Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS How to Make a Website Styling Web Pages and Navigation Polish the Navigation and Footer

Amit Panhale
Amit Panhale
1,436 Points

Why not just apply the style we applied to 'nav a' to 'nav li' as there are no other elements in nav?

NA

2 Answers

Benjamin Lim
Benjamin Lim
17,880 Points

I guess you could but best practice is to allocate the styling you want to the elements itself rather than a top-level 'nav' or 'nav li'. That way you are able to style when more attributes are added.

HTH.

Best practice is your friend and a time saver :D. I concur with your statement Benjamin!

You just apply the necessary rules to the elements that can be standardised to all other elements with the same class or html tag, then trickle down specific rules to children elements. Thats how I understand the word Cascading in CSS. That way you create uniformity across your design, and save time when you want to edit an entire set of rules or adding specific rules to a smaller portion of elements.

When you have thousands of CSS blocks, it really helps to prevent unexpected changes across your website/application.

If you try to put all the rules in one parent element, then it means you have to create counter rules to all potential child elements that don't need them.

If you take the example of

<ul>
   <li>
      <a>
      </a>
   </li>
</ul>

Its just a box (a) within a box (li), within another box(ul). Well it makes more sense to add padding from inside-out than outside-in.

I don't know if that makes any senses...

Benjamin Lim
Benjamin Lim
17,880 Points

Aurelien Schlumberger

The cascading in CSS would be meant not so much for the styling to the elements or attributes, but the effect of the styling based on the arrangement of the CSS being coded, the CSS that are written later would overwrite any CSS that is written above.

That said, the basics of CSS that is covered here is a great start, but in all practicality, I would be using CSS frameworks such as Foundation and scripting languages like Sass for the 'real-world'.

HTH!

Its also about the button of the link.

The link html <a></a> is the button. If you applied padding to html <a></a> it will make the clickable area bigger.

However if you had a structure html <li><a></a></li> and applied the padding to li instead of a, then the clickable area won't be bigger. Go ahead and try it. (Well you can cheat and find workarounds, but why make it troublesome?)

And if you had padding on both then it will make some buttons bigger than others ^^

Benjamin Lim
Benjamin Lim
17,880 Points

You're right. Just tested, applying the styling to <a> instead of just <li> would affect the clickable area, as <a> is the actual link. Nice.

Amit Panhale - if styling is at <li> it would look it, but not be clickable.

Amit Panhale
Amit Panhale
1,436 Points

Thanks Aurelien and Benjamin for your inputs. Will try it out as you suggest.