I’m building a page based on the tutorial code that goes along with the book "CSS Mastery" by Andy Budd from friendsofed.
It is based on the Three-column floated layout on page 140. The CSS code has this bit;
I don’t understand what this is doing, and the book contains no explanation of it that I can find. If I remove it I can’t make the page look right. I know right now you’re thinking — well leave it in you idiot — and I certainly don’t mind doing that, but I would like to understand what its function is.
I tried going to the source and posted this question on the forum at friendsofed but got no response. CSS-Tricks is one of my top 5 places for learning web design so I hope someone here can help me out.
Padding adds space or "padding" to the inside of an element. Think of it this way. You have a <div> and inside the div you have text. Think of the div as a box. the text inside the box is the contents of the box. The padding adds space between the contents of the box and the inner wall of that box. So that the contents don’t touch the walls. Margin add space ouside the box so that the box doesn’t touch any other box. So padding-top and padding bottom adds space to what is above the contents and what is below the content padding left and right do the same things. So this code
Create a page using this CSS code – then use firefox with the firebug addon and view your page. With firebug you can then ‘virtually’ deactivate elements of the code so you can see in real time what changes take affect. This is one of the best ways to learn exactly what a particular piece of code is doing.
I understand the concept of the box model, and thus, the first segment of code. What I don’t understand is the following two sections, making use of the universal selector. If someone could explain that I would appreciate it.
Well, the * is just a wildcard selector to select any element. So, the second declaration (#mainNav *) adds 20px of left and right padding to any element at all inside #mainNav. The third declaration (#mainNav * *) then removes that padding from any element nested two levels down from the top, because it’s more specific than #mainNav *.
It is kind of confusing…without seeing the page itself I’m not sure what the advantage is.