Having trouble with just some basic responsive design. I've checked my math a number of times but I can't figure out why the left and right sections aren't lining up. It seems to be an issue with the padding:
http://jsfiddle.net/J3Rx3/
* {
margin: 0;
padding: 0;
text-decoration: none;
list-style-type: none;
border: none;
}
body {
background-color: #ffffff;
color: #2C2C2C;
font: normal 100% Cambria, Georgia, serif;
}
#container {
background-color: gray;
margin: 0 auto;
width: 90%; /* 960px */
}
#left {
background-color: #cccccc;
float: left;
padding: 0 5.5555556%; /* 10 / 180 */
width: 18.75%; /* 180 / 960 */
}
#right {
background-color: #999999;
float: right;
padding: 0 01.3157895%; /* 10 / 760 */
width: 79.166667%; /* 760 / 960 */
}
h1 {
font-size: 1.5em; /* 24px / 16px */
font-style: italic;
font-weight: normal;
}
h1 a {
color: #747474;
font: bold 0.458333333333333em Calibri, Optima, Arial, sans-serif;
letter-spacing: 0.15em;
text-transform: uppercase;
text-decoration: none;
}
<div id="left">
<ul>
<li>Nav Item 1</li>
<li>Nav Item 2</li>
<li>Nav Item 3</li>
</ul>
</div>
<div id="right">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</div>
If you add box-sizing: border-box; (a savior when it comes to responsive design) to your * declaration, you can just use width: 20%; and width: 80% for your divs, then the padding will be included in, and won't add to, the width calculation.
I should also add that you can mix different units of measure. If you use percentages for width, you can use px or em for padding.
DEMO
The padding as described in:
#left {
background-color: #cccccc;
float: left;
padding: 0 5.5555556%; /* 10 / 180 */
width: 18.75%; /* 180 / 960 */
}
Is incorrect. It's not 10/180 but 10/960, or just plain 0. The padding in percentages is relative to the parent and not the object itself. Use:
#left {
background-color: #cccccc;
float: left;
padding: 0 0.0104%; /* 10 / 960 or just leave it out.*/
width: 18.75%; /* 180 / 960 */
}
Update:
Also the padding on the right box is incorrect. padding: 0 01.3157895%; should be padding: 0 0.013157895%; the decimal seperator is two places too far to the right. But it makes the same mistake as the previous and should actually be 10/960 instead of 760. or 0.0104%. But at those small numbers it doesn't really matter.
I am pretty sure you can use calc() to avoid those calculations. Here is PEN which simulates a similar example to what you are trying to achieve.
calc() automatically takes care of the calculations for you.
#left{
float:left;
width:calc(20% - 10px); /*20% minus the margin on both sides*/
margin:5px;
display:block;
}
#right{
float:left;
display:block;
width:calc(80% - 10px); /*80% minus the margin on both sides*/
margin:5px;
}
NOTE: operator in calc() needs to be surrounded by whitespace.
Related
I want to create a fixed height card with a title, body, and footer. The title and footer can be one or more lines, and the body text should expand to fill the remaining space.
.card {
display: flex;
flex-direction: column;
height: 192px;
width: 300px;
border: 1px solid;
padding: 12px;
}
.title {
font-size: 18px;
font-weight: bold;
margin-bottom: 8px;
}
.body {
flex: 1 1 auto;
overflow: hidden;
overflow-wrap: break-word;
word-wrap: break-word;
margin-bottom: 8px;
}
<div class="card">
<div class="title">
This is a title
</div>
<div class="body">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<div>
footer text
</div>
</div>
How can I prevent the body text from being cut off? overflow-wrap/word-wrap seem to have no effect.
You have to make the height a mutliple of the height of one line. Here is an example using CSS grid.
Resize the main container to see the magic:
.card {
display: flex;
flex-direction: column;
height: 192px;
width: 300px;
border: 1px solid;
padding: 12px;
overflow: hidden;
resize: both;
}
.title {
font-size: 18px;
font-weight: bold;
margin-bottom: 8px;
}
.body {
flex: 1 1 auto;
margin-bottom: 8px;
line-height: 1.2em; /* height of one line */
display: grid;
grid-template-rows: repeat(auto-fit, 1.2em); /* same as line-height here */
grid-auto-rows: 0;
}
.body>div {
grid-row: 1/-1;
overflow: hidden;
}
<div class="card">
<div class="title">
This is a title
</div>
<div class="body">
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</div>
<div>
footer text
</div>
</div>
I'm having trouble getting the following three-column layout to work:
A B C
+-------+-----------+-------------------------+
| | | |
| Fixed | Fixed | Expands to fill width |
| | | |
+-------+-----------+-------------------------+
Where:
A is fixed width.
B is a fixed width.
C contains content which I'd like to fill up the remaining space on the page. The page itself which has a resizable width
I've found numerous solutions where the center column is fluid, but I'm having trouble getting the right column to be the fluid width with the left and middle column having fixed width without having the right column line break when it expands larger. The content in the right column is mostly text while the left and middle columns are images.
Here's a fiddle I've been using for testing which has everything setup: http://jsfiddle.net/7y7Lmvr9/2/
You can ditch the floats and use display:table-cell instead:
$('#div_right').click(function () {
$(this).append('-------');
});
#div_left {
display:table-cell;
border:1px solid #F00;
width: 100px;
}
#div_middle {
display:table-cell;
border:1px solid #0F0;
width: 100px;
}
#div_right {
display:table-cell;
border:1px solid #00F;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id='div_left'>Fixed width</div>
<div id='div_middle'>Fixed Width</div>
<div id='div_right'>Variable-width (click to widen). Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
display:table has been said, so i ll only say flex:)
body {
display:flex;
}
body>div {
border:solid;
width:100px;
}
#div_right {
flex:1;
width:auto;
}
<div id='div_left'>
Fixed width
</div>
<div id='div_middle'>
Fixed Width
</div>
<div id='div_right'>
Variable-width (click to widen). Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
CSS calc() could be one of the solutions.
Demo - http://jsfiddle.net/7y7Lmvr9/3/
#div_left, #div_middle, #div_right {
border: 1px solid red;
box-sizing: border-box;
float:left;
}
#div_left, #div_middle {
width: 100px;
}
#div_right {
width: calc(100% - 200px);
}
Bowser compatibility - http://caniuse.com/#feat=calc
I recommend wrapping the three divs in another div, and setting the wrapper display to "flex." That way you can set the first two divs' width, and set the third to fill the remaining space.
http://jsfiddle.net/6LgkjpwL/
fiddle with flex implemented on wrapper.
A great resource on flex--
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
body{
font-weight:bold;
}
#wrapper{
display:flex;
flex-direction: row;
}
#div_left{
order: 1;
overflow: hidden;
border:1px solid #F00;
width: 100px
}
#div_middle {
order: 2;
overflow: hidden;
border:1px solid #0F0;
width: 100px
}
#div_right {
order:3;
flex:1;
border:1px solid #00F;
}
<div style="width:100%; overflow:hidden">
<div id='div_left'>
Fixed width
</div>
<div id='div_middle'>
Fixed Width
</div>
<div id='div_right'>
Variable-width (click to widen). Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</div>
body{
font-weight:bold;
}
#div_left{
float:left;
overflow: hidden;
border:1px solid #F00;
width: 9%
}
#div_middle {
float:left;
overflow: hidden;
border:1px solid #0F0;
width: 9%
}
#div_right {
float:left;
border:1px solid #00F;
width: 79%
}
I am just learning CSS, ive a project for a car sales website, but im trying to position text within a div, the paragraph code goes in fine, but when i put in the H1 tag, it moves the entire div down? (See below).
https://www.dropbox.com/s/px0zv5xw8vqpvpd/Screenshot%202014-03-12%2001.38.02.png
<div id="bottom">
<h1> Welcome to JJMurray Car Sales </h1>
<p class="hometext">
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p></div>
and the CSS:
#bottom{background-color:#d6d6d6;width:100%;height: 450px;
h1
{
text-align: left;
margin-left: 20px;
margin-right: 20px;
}
p.hometext
{
font-size: 14px;
font-family: calibri;
text-align:left;
width: 600px;
float: left;
margin-left: 20px;
margin-right: 20px;
The heading tag in default occupies some margin.
And that default margin is making it appear with spaces around.
So, first try give h1 tag margin:0; then, you can see how much space it is actually taking in default.
And as it is a block element you can specify maring: top left bottom right;
My margins when using flexbox (current version or display: flex;) seem to be doubled and I can't figure out why. All the other margins between sections on the page show up as 10px as they have been set, but the ones for the flexbox content show up with around double that. I have already tried setting the wrapper div (#output) to margin: 0px; and padding: 0px; but that doesn't have any effect. Is this a flexbox 'feature'? Or is there something wrong with the margin/padding settings for my CSS?
The HTML:
<div id="all_content">
<section id='search_box'>
<h1>Auto Primer</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</section>
<div id="output">
<nav id='user_input'>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</nav>
<section id='gene_selected'>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</section>
</div>
<section id='primers'>
<h2>Primers</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</section>
<section id='how_to'>
<h2>How To Use Auto Primer</h2>
<p><span id="form_out"></span></p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</section>
</div>
The CSS:
div#all_content {
width: 1200px;
margin: 0 auto;
padding: 0px;
}
section#search_box {
padding: 10px;
margin: 10px;
background: #ebf4fb;
border:2px solid #b7ddf2;
border-radius: 15px;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
}
div#output {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
width: 100%;
}
nav#user_input {
background: #ebf4fb;
border: 2px solid #b7ddf2;
width: 275px;
padding: 10px;
margin: 10px;
border-radius: 15px;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
}
section#gene_selected {
-webkit-box-flex: 1;
-moz-box-flex: 1;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
padding: 10px;
margin: 10px;
background: #ebf4fb;
border: 2px solid #b7ddf2;
border-radius: 15px;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
}
section#primers {
padding: 10px;
margin: 10px;
background: #ebf4fb;
border: 2px solid #b7ddf2;
border-radius: 15px;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
}
section#how_to {
padding: 10px;
margin: 10px;
background: #ebf4fb;
border: 2px solid #b7ddf2;
border-radius: 15px;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
}
EDIT:
I managed to get the margins to look the same by giving the left flex element:
margin: 0px 5px 0px 10px;
and the right flex element:
margin: 0px 10px 0px 5px;
instead of margin: 10px; as all the other elements on the page use. While this works I'm still a little at a loss as to why flexbox does this.
EDIT:
Here's a jsfiddle demonstrating the problem: fiddle. Updated and simplified further.
The issue is that margins are applied twice on your side by side flex sections. You can fix this by simply distributing the margins properly between the side by side elements.
Based on CSS3 Definition:
http://www.w3.org/TR/css3-flexbox/#item-margins
The margins of adjacent flex items do not collapse. Auto margins absorb extra space in the corresponding dimension and can be used for alignment and to push adjacent flex items apart; see Aligning with ‘auto’ margins.
This is what happens in your case, that the margins on your side by side flex items do not collapse, but on your other flex items, they do collapse so the margins are not applied twice on those flex items.
The image demonstrates the problem. I want the bullet list to be aligned with the text, not indented.
This must be modified in css i guess, because source is:
<p>This is a test :)</p>
<ul>
<li>Test1</li>
<li>Test2</li>
<li>Test3</li>
<li>Test4</li>
</ul>
<p><strong>Bla bla</strong></p>
<p><strong>Dette er en test</strong></p>
<p><strong><span class="Apple-style-span" style="font-weight: normal;"><strong>Dette er en test</strong></span></strong></p>
<p><strong>Dette er en test</strong></p>
<p><strong><span class="Apple-style-span" style="font-weight: normal;"><strong>Dette er en test</strong></span></strong></p>
</div>
So how can I remove the padding/margin from left in this bull list? I tried margin: 0; padding: 0; did not work out
Apply padding-left: 0 and change the list style position to inside:
ul {
padding-left: 0;
}
ul li {
list-style-position: inside;
}
Example link http://jsfiddle.net/vF5HF/
ul {
margin-left: 0;
padding-left: 0;
}
li {
margin-left: 1em;
}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Bullet alignment</title>
<style type="text/css">
body { font-size: 14pt; margin: 100px; background-color: #f2f2f2; }
ul { margin-left: 0; padding-left: 2em; list-style-type: none; }
li:before {
content: "\2713";
text-align: left;
display: inline-block;
padding: 0;
margin: 0 0 0 -2em;
width: 2em;
}
</style>
</head>
<body>
<p>Bullet alignment 😈</p>
<ul>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</li>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</li>
</ul>
<p>That’s all Folks</p>
</body>
As #NicolaPasqui mentioned, for your problem you should use:
ul {
padding-left: 0
}
ul li {
list-style-position: inside;
}
When setting list-style-position to inside, the bullet will be inside the list item.
Unlike setting it to outside, where the bullet will be outside the list item.
There is a great article about bullet style I think you could benefit from here.