Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

HTML

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?

<header>
            <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>
                  </div>
            </nav>
       </header>
* {
    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);
}

.logo{
    color: #3db5da;
}

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



/*flexbox*/
.container{
    display: flex;
    flex-direction: column;
    text-align: center;
    // height: 100vh;

    .menu{
        display: flex;
        flex-direction: column;
    }
}

2 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 90,705 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
215,972 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.