CSS organisation with ids and classes - css

What do you think is the best way to organise the CSS of a site?
I wanted to have ids followed by classes. However they are not exclusive.
Example:
h4 {
padding: 5px 5px 5px 10px;
font-size: 110%;
font-weight: bold;
color: #000000;
font-family: Arial, Helvetica, sans-serif;
margin: 0px 0px 5px 0px;
background:transparent url(/images/example2.jpg) no-repeat scroll left top;
text-transform: uppercase;
}
#rightcol {
padding: 0px;
width: 306px;
overflow: hidden;
float: left;
margin: 0;
border: 0;
}
#rightcol .container {
margin: 5px 6px 0 0;
padding: 5px 5px 0 5px;
background: #FFFFFF;
}
#box_info {
border: 1px solid #AAAAAA;
background: #4F4F4F;
line-height: normal;
background: #4F4F4F url("../images/example.gif") repeat-x top left;
}
#box_info.container {
margin: 10px 5px 10px 10px;
background: transparent;
padding: 0;
}
If there is a id infobox inside of a id right nav, the infobox's container will have the right nav's instead!
<div id="rightnav">
<div class="advert">
This needs to be here as sometimes I need it without borders margins etc.
</div>
<div class="container">
<div id="otherbox">
<div class="container">
</div>
</div>
<div id="info_box">
<h4>Related Info</h4>
<div class="container">
<span>Info in here</span>
</div>
</div>
<div id="yetanotherbox">
<div class="container">
</div>
</div>
</div>
</div>
So my question is: Is there a way to make them exclusive (or private if that is a better term) or a better way of organising CSS.
Cheers in advance.
edit: Just to let you know, I like putting containers in for the simple reason of width. I want 100% width but I also want to indent my containers. I find adding padding to the box then adding margin to the containers I get what I desire. If you can tell me how to do this with just one div, then go ahead although I just want a way of organising CSS better, not html (as I believe I am doing it the best it can be, but take a shot at proving me wrong :) ). Thank you :)

I think Natalie Downe has the right approach to CSS organization, which she details in her CSS Systems presentation here:
http://natbat.net/2008/Sep/28/css-systems/
The idea is that you move from the more general to the more specific in several chunks:
general styles
List item
body styles
reset
links
headings
other elements, tags
helper styles
forms
notiļ¬cations and errors
consistant items with normally just one class
page structure
skeleton including page furniture
page components
most of your styles will be in here
overrides
as little as possible goes here

In your case when you want apply the #infobox .container styles you have to override the #rightnav .container with the "!important" rule.
If you don't want any conflict between names, simply change, for example, the #rightnav .container in #rightnav .mainContainer.
I hope I've written something not so obvious.

I think trying to organize your cascade rules by class and id might be miss guided. You really should just be thinking of the actual cascade of things rather than trying to make them private.
For example the following:
#container
{
width: 600px;
margin: auto;
}
#left
{
width: 250px;
float: left;
}
#left p
{
color: Blue;
}
#left .information p
{
font: normal .83em sans-serif;
color: #000000;
}
#right
{
width: 250px;
float: right;
}
#right ul
{
font: normal .83em sans-serif;
list-style: none;
}
Will show the this:
alt text http://img188.imageshack.us/img188/1576/croppercapture5e.jpg
As you can see, there is no font face for the page itself. But as you dive deeper in the levels of the style cascade you will find that paragaphs have style defined and with the .information class you have a color blue defined on a paragraph. By thinking of what styles are needed as you dive deeper into your HTML you will see that you actually end up with less HTML and better organized style sheets.
Good luck and hope this helps.

One of the properties of cascading style sheets is that they cascade. Styles applied to parent elements also apply to their children. To change that, you will have to override the styles inherited from the parent by setting them again explicitly.

To target sub containers you could do #rightnav .container .container I think.

Related

Why do CSS Frameworks use !important tags unnecessarily?

This is more of a debate than a question but I feel that there isn't a lot on the internet that covers this topic.
For example foundation comes with hundreds of !important tags for things that in my eyes do not need them:
.text-center { text-align: center !important; }
There is loads of css that is simular to this which in my point of view is bad practise and the question I'd like to answer is why do css frameworks use them at all? Bootstrap and Foundation are two main css frameworks that both use them.
I've always been told that using important tags in css is very bad practise and should only be used for IE.
If you write your own CSS you have the freedom to add more specific rules whenever needed:
.center { text-align: center; }
.foobar { text-align: left; }
.foobar.center { text-align: center; }
However, the CSS framework cannot predict how you will arrange your HTML. So it is easier to do !important instead of generating thousands of combinations of more specific rules. Example:
.center { text-align: center; }
.foobar { text-align: left; }
.barbaz { text-align: right; }
/*
* assuming .center must be centered regardless of other rules and
* !important must be avoided at the same time, we need to do this
*/
.foobar.center { text-align: center; }
.barbaz.center { text-align: center; }
.foobar.barbaz.center { text-align: center; }
Is because you can have in your code st. like this:
<style>
#aside p {text-align: right;}
.text-center {text-align: center} /* without important text will be aligned to right */
</style>
<div id="aside">
<p>right-aligned text</p>
<p class="text-center">centered text</p>
</div>
http://jsfiddle.net/v1v4jaas/
In this case without inportant the text will be aligned to right. With important, the second paragraph will be centered.
Class has only a low priority against id, etc.
Using !important in your CSS usually means, the classes you have written do
not have a proper hierarchy.
The !important rule overrides a particular property. But should be used only when one is helpless and it has to be overridden.
Best practice would be to use !important only in utility classes alone.
eg. Say you have a button which u want to look similar throughout your application
.btn {
margin-bottom: 0;
text-align: center;
vertical-align: middle;
touch-action: manipulation;
cursor: pointer;
border: 1px solid transparent;
padding: 6px 12px;
font-size: 11px;
border-radius: 4px;
}
The above definition for .btn holds true unless it is not wrapped by any other class which could override the .btn formatting which we expect to be same throughout the application. But once it is wrapped by other class like below, the final style would be totally different from your expectations.
<p class="format-paragraph">
<button type="submit" name="save" class="btn"> Submit</button>
</p>
Now, to make your .btn class super strong and to be treated with respect by the ones wrapping it, change the .btn definition to:
.btn {
margin-bottom: 0 !important;
text-align: center !important;
vertical-align: middle !important;
touch-action: manipulation !important;
cursor: pointer !important;
border: 1px solid transparent !important;
padding: 6px 12px !important;
font-size: 11px !important;
border-radius: 4px !important;
}
This definition would be sufficient to make your button look similar throughout the application.
The .text-center { text-align: center !important; } class mentioned in question is nothing but a utility here.
Know more on !important precedence here.

spacing between thumbnails disappeared after using another lightbox

I used to have no problem with the css code i have been using. But, after I have changed from using "Lightbox2" to "fancybox", the spacing between the thumbnails and the thumbnail border (when mouse hovering above) disappeared. What has gone wrong?
Compare the problem page after switching to using fancybox (www.lixiao-art.com/test.html ) with the page using Lightbox2 ( www.lixiao-art.com/latest.html )
This is the code I use:
body { font-family: Verdana, Arial, Helvetica, sans-serif;
color: black;
margin: 0px;
background-color: RGB(181,170,128);}
*{
font-family: Verdana, Arial, Helvetica, sans-serif; font-weight:normal
}
#nav {float: left;
position: fixed;
background-color: RGB(233,231,197);
text-align: left;
font-size: 11px;
color: #645630;
width: 90px;
font-weight: bold;
padding: 100px 20px 100px 30px;
border: none;
min-height: 100%;
}
#content {float: left;
margin-left: 150px;
padding: 15px 20px 10px 80px;
width: 900px;
margin-top: 0px;
border: none;
font: black;
font-size: 11px;
}
#content a {text-decoration:underline}
h2 {height: 2em;}
.footer {
text-align:center;
padding-top: 50px;
padding-bottom: 1em;
font-size: 11px;
}
a{text-decoration: none;
color: #645630;}
a:hover {color: red;}
* {margin: 0;}
html, body, wrapper {height: 100%;}
.ImgBorder img { border:2px solid transparent;
height:100px;
}
.ImgBorder:hover img{ border-color: white}
.ImgBorder {display: block;
float: left;
margin: 30px 20px; }
h5{
clear:both
}
img { border: none; }
Thank you!
In your previous Lightbox2, each image is wrapped in an anchor
<a class="ImgBorder">
and the class ImgBorder has the value margin: 30px 20px
In your current Fancybox, you can just add this missing margin margin: 30px 20px to the class fancybox as each image is now wrapped in an anchor
<a class="fancybox"/>
As I just noticed that there doesn't seem to be any class fancybox already defined, you just have to add
.fancybox
{
margin: 30px 20px;
}
e.g. in your global.css
Update: In case you also want to display the border for the fancybox-images, there are two ways of achieving this: Currently you have both lightbox versions on your test page. For the first image the border is still displayed for hover. Following CSS is taking care about that:
.ImgBorder img {
border: 2px solid transparent;
height: 100px;
}
.ImgBorder:hover img {
border-color:white;
}
for an image markup as follows for your first image:
<a class="ImgBorder" rel="lightbox[gaze]"
href="http://www.lixiao-art.com/work/2014/52.jpg">
<img src="work/2014/52_t.jpg">
</a>
Your current fancybox-markup is like this for your second image:
<a href="work/2014/52.jpg" rel="group" class="fancybox">
<img src="work/2014/52_t.jpg">
</a>
So all you have to add is the border and hover for the fancybox-class:
.fancybox img {
border: 2px solid transparent;
height: 100px;
}
.fancybox:hover img {
border-color:white;
}
It's possible that there are some additional adjustments because of the CSS that fancybox uses, but it's easier if you just check this on your site as I just noticed that you're currently working on it.
At the moment your fancybox images "jump" because you added the CSS
.fancybox:hover
{
border-color:white;
margin:30px 20px;
}
which results in setting this margin on hover (therefore jumping then). I suggest you just try the CSS I posted above, that should work.
Update 2 for the comments follow-up questions:
The attributes class and rel stands for the following:
rel (='related') is an attribute containing information for you previous lightbox. The lightbox script will just fetch the information for e.g. a big image or a link from there.
class: as you noticed, almost all in your css-file starts with a dot (.) followed by a name. This name is the name of the class to which the style information will apply. So .test {color:red;} results in displaying a text red in case it's wrapped in an element with the class test, e.g. a <div>: <div class="test">This is red text</div>.
Update for the margins:
To keep the margins to your images when you remove it for the :hover - the correct way to have the margins is just like that:
.fancybox img
{
margin:30px 20px;
}
As you already have one .fancybox img in your CSS, just add this margin to it, though you can also have these selectors multiple times in a CSS file, it's better to keep the styles applying to an element together.
Thank you very much! You've pointed out the problem with my multiple classes, and I've fixed it accordingly like this:
<a class="fancybox ImgBorder" rel="group" href="work/2014/52.jpg"">
<img src="work/2014/52_t.jpg">
</a>
(instead of making new definitions in my global.css)
But, a small problem shows up: this line shows in red colour in the editor at the backoffice. Is there a problem with this line? but I guess I will open a new thread for this.
Thanks again!

Element with CSS display: none; breaking layout - causing misalignment

I have a basic menu, made from a horizontally aligned list (<li>), each containing an icon image and some text:
One of the <li> contains an extra image with display: none; so that the icon can be toggled (from a green to a red pepper, in this example.
The problem is that it doesn't align correctly on some browsers, as shown in the above image. My understanding was that in contrast to visibilty: hidden;, an element with display: none; should not affect the position of any other element and should render as if it's not there?
The browsers where it doesn't render correctly are Google Chrome and Safari - but only on MacOS(!?) and IE7 (I know, I know...) on Windows. Every other browser / OS combination I've tested works fine.
Here's the HTML:
<ul class="menu">
<li><img alt="Green Pepper" src="/green.png">li</li>
<li><img alt="Green Pepper" src="/green.png">li</li>
<li><img alt="Green Pepper" src="/green.png">li</li>
<li id="change">
<img alt="Red Pepper" src="/red.png" style="display: none;">
<img alt="Green Pepper" src="/green.png">
li
</li>
<li><img alt="Green Pepper" src="/green.png">li</li>
</ul>
Here's the CSS:
.menu li {
cursor: default;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10pt;
list-style-type: none;
position: relative;
text-align:center;
margin: 0 0 0 -25px;
padding: 8px 0 0 0;
width: 144px;
height: 35px;
display: inline-block;
background-image: url(../bct-white.png);
background-repeat: no-repeat;
color: #0091c1;
}
And for the icon images:
.menu img {
display: inline;
vertical-align: -25%;
padding-right: 6px;
}
I've also had to include a browser hack for IE7 because it doesn't recognise inline-block, coming from a separate stylesheet based on a conditional import (<!--[if lte IE 7]>):
.menu li {
zoom: 1;
display: inline;
}
Although, obviously that style isn't loaded on Chrome and Safari regardless of OS, so can't be causing my issue on Macs.
I know the quickest solution would be to refactor the HTML and the JavaScript manipulation of the show / hide of the icons, but I'd really like to know what causes this issue and how to resolve it.
Update
I've tracked the cause down. Basically, the element style of display: none; on the <img> element overrides the inline from the .menu img rule. Removing that, then toggling between block and inline allows you to reproduce the issue. This is obviously a browser bug, and while the element is not displayed being an in-line or block element should have no effect on the layout.
jsFiddles
Issue with Chrome and Safari on Macs only
Issue with extra CSS for IE7 only
Note! For me, the Fiddle page didn't load properly using IE7, but the direct link for the result iFrame is http://fiddle.jshell.net/z4dU7/3/show/
Bounty update!!!
I've posted one fix below, but it actually introduces the same layout problem in IE9! Please feel free to evolve or improve on my answer - or come to the table with something completely different! :)
Scrap Approach and Use Background Images
http://jsfiddle.net/P5CKC/2/
<ul class="menu">
<li><span>Li</span></li>
<li><span>Li</span></li>
<li><span>Li</span></li>
<li class="change"><span>Li</span></li>
<li><span>Li</span></li>
</ul>
CSS
ul.menu {
overlflow: hidden;
}
ul.menu li {
float: left;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10pt;
text-align:center;
margin: 0 0 0 -25px;
width: 152px;
line-height: 35px;
height: 35px;
background: url(../bct-white.png) no-repeat;
color: #0091c1;
}
ul.menu li span {
background: url(/green.png) no-repeat 5px 6px;
display: block;
}
ul.menu li.change span {
background-image: url(/red.png);
}
CSS2.0 and browser compatibility
The code application I have provided is Css2.0 and should easily work in IE7 and above.
Removed img tags and implemmented aesthetics (images) as backgrounds
Extra span had to be added because CSS2 allows only 1 background image per element
Li tag holds the arrow background; span tag holds the pepper background
Updated id="change" to class="change". UNLESS you are 100% certain that you will only have one #change element, use a class. This is purely styling and it prevents you from having two menu lists on the same page.
Tweaked your CSS styling a bit as follows:
Removed top padding and increased the height. So your li elements are the same height BUT then added line-height: 35px -> this is the best way to vertically center text. Utlizing top padding works but it is prone to poor browser inconsistency.
Change li elements to floats. Floated elements are the most IE7 friendly method! Even IE6 will not bug out but I don't have that old version to test your webpage in. FYI - ul.menu has to have overflow: hidden to clear the floats.
position: relative;
cursor: default;
Unless you changed the defaults, you can keep these two properties out. cursor should be default. Position: relative is unnecessary - you aren't using absolute positioning or anything that warrants its need. Now, you can keep these in your declaration. I just like code to be as "slim" as possible.
final words:
Take a look at my CSS. Notice how I used ul.menu in all my declaration. You may want to get in the habit of doign the same; this provides the developer some insight on what the HTML looks like and more importantly - your css will not get overrided if you decide to add <div class=menu> later on. Specfically .menu img would apply to any image tag within the menu div.
Okay - that's it. Let me know if there are any clarfications.
FYI - seeing as this question has a bounty, if you provide me with the background images I can polish my code to suit your needs 100% - perhaps upload them in an edit of your answer.
There is whitespace between your elements. None of your other list items have that whitespace. Try removing all whitespace between those elements and see if that fixes your problem.
If it does, it just means that your HTML is parsing the content of your <li> as having a line break - which would be why you are seeing an issue. To solve this, wrap the text in your <li> with a <span>. When your browser parses HTML it will automatically trim whitespace between HTML tags and automatically fix the issue (without losing your formatting)
This is an odd one but I could recreate the issue in Firefox v22. The really odd part was that in the jsFiddle if I just hit "Tidy Up" and then hit "Run" and the problem was solved. As Matthew R mentioned this is likely due to the additional white space being removed.
Broken:
Tidy Up, Run, and Fixed
Here's an alternate method using background images:
Working Example
.menu li {
cursor: default;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10pt;
list-style-type: none;
position: relative;
text-align: center;
margin: 0 0 0 -25px;
padding: 8px 0 0 10px;
width: 118px;
height: 20px;
display: inline-block;
background-image: url(http://modmyi.com/attachments/forums/iphone-4-4s-new-skins-themes-launches/465481d1282224308-classified-hd-cydia-released-goldborder.png), url(http://i.stack.imgur.com/dmHl0.png);
background-position: 0% 0%, 44% 75%;
background-size: 128px, 18px;
background-repeat: no-repeat;
color: #0091c1;
}
.menu img {
display: inline;
vertical-align: -25%;
padding-right: 6px;
}
#change:hover {
background-image: url(http://modmyi.com/attachments/forums/iphone-4-4s-new-skins-themes-launches/465481d1282224308-classified-hd-cydia-released-goldborder.png), url(http://www.chiletownhotsauce.com/images/stories/Red%20bell%20pepper.jpg);
background-repeat: no-repeat;
background-position: 0% 0%, 44% 75%;
background-size: 128px, 18px;
}
<ul class="menu">
<li>li</li>
<li>li</li>
<li>li</li>
<li id="change">li</li>
<li>li</li>
</ul>
I think your issue is with the box model and display:inline-block. When I use display:inline-block in horizontal menus, I also use a clear fix for the parent and float:left; with the children.
In this example of the css, I put some values in the .menu that can be inherited and I used overflow:hidden; to address the clear fix. Then I used float:left; in the li to force them tight and avoid any weird spacing caused by the browsers defaults. And then I changed the vertical-align value to middle for the image. When toggled display:none; with inline, it all looked correct to me. I did not test in all the browsers listed. I also used the first piece of CSS there for the css reset, which may be redundant but I always find it useful on JSFiddle.
* {
margin:0;
padding:0;
}
.menu {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10pt;
list-style-type: none;
color: #0091c1;
overflow:hidden;
}
.menu li {
cursor: default;
position: relative;
text-align:center;
/* margin: 0 0 0 -25px; */
padding: 8px 0 0 0;
width: 118px;
height: 20px;
display: inline-block;
float:left;
background-image: url(http://modmyi.com/attachments/forums/iphone-4-4s-new-skins-themes-launches/465481d1282224308-classified-hd-cydia-released-goldborder.png);
background-repeat: no-repeat;
}
.menu img {
display: inline;
/* vertical-align: -25%; */
padding-right: 6px;
vertical-align:middle;
}
To resolve the (appearance of) the issue, change the vertical alignment of the icon images contained in the menu:
.menu img {
display: inline;
vertical-align: top;
margin-top: 2px;
padding-right: 6px;
}
On the affected browsers, the additional image (with display: none;) was altering the height of the containing element. Setting the <img> to display: none; meant that the display: inline; setting no longer applied and was positioned underneath the first image.
Just having the extra <img> displaying in-line fixes the vertical alignment, but obviously doesn't fix the issue as the image needs to be hidden without changing the position of the text.
This fix changes the vertical alignment from a percentage (-25%) to a fixed position, avoiding any (spurious) differences in the height of the containing element. I've then set the top margin of the image to get the desired spacing from the top edge of the element.
Update
This fix breaks the display in IE9 - same appearance as IE7 without this fix.
You made a mistake with the line-height
instead of 35px give 23px
<ul class="menu">
<li><span>Li</span></li>
<li><span>Li</span></li>
<li><span>Li</span></li>
<li class="change"><span>Li</span></li>
<li><span>Li</span></li>
</ul>
ul.menu {
overlflow: hidden;
}
ul.menu li {
float: left;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10pt;
text-align: center;
margin: 0 0 0 -25px;
width: 152px;
line-height: 23px;
list-style: none;
height: 35px;
background: #ccc;
color: #0091c1;
}
ul.menu li span {
background: url(http://i.stack.imgur.com/dmHl0.png) no-repeat 5px 6px;
display: block;
}
ul.menu li.change span {
background-image: url(/red.png);
}
check the output
jsfiddle-link
I had the same issue with display:none; breaking my layout. I ended up just removing the style and using jQuery's:
$(".element").show();
$(".element").hide();

solve this style problem for IE6 and IE7

First i will show you the problem, wich only happens on IE6/IE7
As you can see, when the length of the innerHtml it's not long, no problem; but when it's 'longer' the sprite set as bg image gets repeated and the text jumps to the next line...
now, the CSS
.contButton {
list-style: none;
float: right;
}
.contButton p {
float: left;
display: inline; /*For ignore double margin in IE6*/
margin: 0 0 0 10px !important;
}
.contButton a {
text-decoration: none !important;
float: left;
color: #FFF;
cursor: pointer;
font-size: 14px !important;
line-height: 21px;
font-weight: bold !important;
}
.contButton span {
margin: 0px 10px 0 -10px;
padding: 3px 8px 5px 18px;
position: relative; /*To fix IE6 problem (not displaying)*/
float:left;
}
/*ESTADO NORMAL AZUL*/
.contButton p a {
background: url(../nImg/spriteBotones.png) no-repeat right -214px;
_background: url(../nImg/spriteBotones.gif) no-repeat right -214px;
color: #FFF;
}
.contButton p a span {
background: url(../nImg/spriteBotones.png) no-repeat left -214px;
_background: url(../nImg/spriteBotones.gif) no-repeat left -214px;
}
And the Html:
<div class="">
....
<div class="contButton mt10">
<p><a tabindex="" title="acceder" href="#"><span>ver disponibilidad</span></a></p>
</div>
...
</div>
This is the bg Image.
![the sprite][2]
Tried with:
<!--[if IE lte 7]>
<style type="text/css">
/*
.contNombrePrecioHtl .contButton p a{ height:20px; }
.contNombrePrecioHtl .contButton p a span{ height:20px; width:auto; } */
</style>
<![endif]-->
But that didn't solve the problem...
PS: class="mt10" it's only a margin-top:10px;
Any idea how to solve this for the glorious IE6/7?
Try adding white-space: nowrap to .contButton.
change this:
.contButton span {
margin: 0px 10px 0 -10px;
padding: 3px 8px 5px 18px;
position: relative; /*To fix IE6 problem (not displaying)*/
float:left;
white-space: nowrap;
}
I don't think it is a problem with either IE versions, it's probably just the newer browsers being less strict about this particular thing. I haven't tested anything, but "display:inline-block" has helped me sometimes. Still it doesn't seem like the most effective solution. The width seems to be limiting here, you shouldn't give the thing a fixed width if you don't want the text to "jump" into a second line...
can you try to add overflow: hidden to each parent of element with float: left? in this case you will have to add it to each div, p and a. I am not sure whether your actual code is optimal.
Moreover, float: left; and display: inline together make no sense. This might be the reason of the strange behaviour. Delete display: inline (remember about adding overflow: hidden to its parent) and it should work.
Haven't tested though.
UPDATE:
apparently as the author of the question mentions float:left + display: inline fixes IE6 double margin bug for floating elements.
defining dimensions for elements like p oder span is always somewhere between tricky and impossible, because they are inline elements. I'd recommend modifying the surrounding block element div.contButton.
In addition to height you should set overflow to hidden:
.contButton {
height:20px;
width:219px;
overflow: hidden;
}

css: mystery "margin"

Whenever I have two elements side by side horizontally with right and/or left padding and/or margin specified, there is often space between the elements over and above what I've specified. I'm hoping someone can tell me how to eliminate that space (without something crufty like a negative margin).
Please note: I am not looking for alternative multi-column CSS layout techniques. I know there are loads of them out there and this issue is bigger than just a column layout issue.
Below is the markup and styles for a working example page. Here's a partial screenshot of that page that shows left elements selected with Firebug. The mysterious space in question is to the right and is marked with a red asterisk. There are no reset styles included but I've plugged in Eric Meyers' reset and it didn't solve the problem.
<div id="side-a">
<p>
Lorem ipsum ....
</p>
</div>
<div id="side-b">
<p>
Nunc dapibus....
</p>
</div>
<div id="website-footer">
<ul id="legal-information">
<li>Copyright 2011</li>
<li>Privacy Policy</li>
</ul>
</div>
div#side-a,
div#side-b {
display: inline-block;
width: 200px;
padding: 17px 17px 0;
}
div#side-a {
vertical-align: top;
}
div#side-b {
background: #999;
}
ul {
padding-bottom: 17px;
list-style: none outside none;
}
ul li {
line-height: 17px;
margin-left: 17px;
}
div#website-footer ul#legal-information {
float: left;
}
div#website-footer ul#legal-information li {
border-left: 1px solid #29443C;
display: inline;
margin: 17px 0;
padding-left: 8px;
}
div#website-footer ul#legal-information li:first-child {
border-left: medium none;
padding: 0 8px 0 0;
}
It's natural because of inline-block. Simple solution is to kill whitespace.
http://work.arounds.org/issue/6/unwanted-white-space-between-inline-block-elements/
There are other css based workarounds such as setting a font size of 0 on the body, but AFAIK they aren't as consistent/reliable. I could be wrong though.
I changed this Css:
div#side-a,
div#side-b {
float: left
width: 200px;
padding: 17px 17px 0;
}
And added in Css for the footer:
#website-footer {
clear: both;
}
And this fixed the issue.
I usually float the elements when I want them next to each other.

Resources