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!

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


Why does a div change the way my content is displayed?

When I change nav to a div the user agent styles get applied to the h1. Why is that?

            <nav class="container">
                <h1 class="logo">LOGO</h1>
                  <div class="menu">
                        <div class="item-1 item">Item 1</div>
                        <div class="item-2 item">Item 2</div>
                        <div class="item-3 item">Item 3</div>
                        <div class="item-4 item">Item 4</div>
                        <div class="item-5 item">Item 5</div>
                        <div class="item-6 item">Item 6</div>
* {
    box-sizing: border-box;
body {
    font-size: 1.35em;
    font-family: 'Varela Round', sans-serif;
    color: #fff;
    background: #e8e9e9;
    padding-left: 5%;
    padding-right: 5%;
.container {
    padding: 10px;
    background: #fff;
  border-radius: 5px;
    margin: 45px auto;
  box-shadow: 0 1.5px 0 0 rgba(0,0,0,0.1);

    color: #3db5da;

.item {
    color: #fff;
    padding: 15px;
    margin: 5px;    
    background: #3db5da;
    border-radius: 3px;

    display: flex;
    flex-direction: column;
    text-align: center;
    // height: 100vh;

        display: flex;
        flex-direction: column;

2 Answers

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,247 Points

The only reason I can think of is that changing nav to div changes the display property of the containing element. Nav is block level but a div is an inline element.

Steven Parker
Steven Parker
227,141 Points

Both "div" and "nav" are block elements by default, and neither has any other default attributes of itself. But if you are using any kind of "normalize" or "reset" script, or any framework, there could be some attributes established for one and not the other.

The best way to determine the cause of the difference is to use the inspector facility of the browser tools, and drill down into the computed values shown for the element when set each way.