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 trialMechadon blaze
12,604 PointsWhy 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
Treehouse Moderator 91,253 PointsThe 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
231,261 PointsBoth "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.