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 Review: Styling Web Pages and Navigation

page styling difference between ul, li and a

I'm playing around with styling in these three selector in nav, and got a little confused about what the content areas of these three selectors: "ul, li and a".

For example, 3 situations when na li {display: inline-block},

  1. na ul {margin: 10px} 2 na li { margin: 10px}
  2. na a { margin: 10px}

when I set margin: 10px for ul, nothing changed; same to li and it applied margin in four directions; whereas same to a and it applied only on left-right directions (inline-block applied to li).

Can anyone draw me a picture (box and lines) to show how exactly are these three selectors' content areas? Thanks.

3 Answers

Tell me if this helps:

http://www.nickmejia.com/img/example.jpg

Here is the code that corresponds so you can see what color and border refers to the element being styled:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<style>
    ul{
        border: 1px red solid;
        margin: 2px;
}
    li{
        border: 2px blue dotted;
        margin: 2px;
}
    a{
        border: 3px green dashed;
        margin: 2px;
}
</style>
</head>

<body>

<nav>
    <ul>
        <li><a href="#">Item 1</a></li>
        <li><a href="#">Item 2</a></li>
        <li><a href="#">Item 3</a></li>
        <li><a href="#">Item 4</a></li>
        <li><a href="#">Item 5</a></li>
    </ul>
</nav>

</body>

</html>

Can you post your code so anyone who wants to help can get a better idea of what your doing?

Edited, I'm a beginner by the way.

I also just noticed that you wanted them set to inline style too, so here it is styled as such:

http://www.nickmejia.com/img/example2.jpg

This is exactly what I asked for. Great example! Thanks a lot Nick!