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
Ji Jiang
2,505 Pointsoverflow: hidden
Hi, Please see the html code below:
<div class="wrap">`
` <header class="main-header">`
`<a class="logo" href="#">Logo</a>`
`<nav class="nav">`
` <a href="#">Link 1</a>`
`<a href="#">Link 2</a>`
`<a href="#">Link 3</a>`
` <a href="#">Link 4</a>`
` <a href="#">Link 5</a>`
`</nav>`
` </header>`
<div class="content">
<div class="main col">main</div>
<div class="secondary col">Secondary</div>
<div class="extra col">Extra</div>
</div>
<footer class="footer">
Footer
</footer>
</div>
` In my css, I have to specify the overflow property of .main-header and .content to hidden, like this:
.wrap{
margin: auto;
width: 90%;
}
.logo, .nav a{
display:inline-block;
text-decoration:none;
color: inherit;
}
.main-header, .content{
overflow: hidden;
}
.col{
height: 200px;
}
.main-header, .col, .footer{
padding: 2.15%;
border-radius: 5px;
margin-bottom: 15px;
}
@media only screen and (min-width: 769px) {
.logo {
float: left;
}
.nav{
float: right;}
.main {
width: 40.425531914894%;
}
.extra {
display: block;
width: 23.404255319149%;}}
Otherwise the main-header will collapse if I float log and nav and the content will behave very wield. Can you please let me know why?
Thank you!
2 Answers
Andrew Stelmach
12,583 PointsCould you post the rest of your CSS, please?
Jason Anello
Courses Plus Student 94,610 PointsHi Ji Jiang ,
Normally a parent element will not contain it's floated children. It will collapse to zero height if all it contains is floated children. You don't necessarily have to fix this but in some cases you may have a background or a border applied to the parent which won't show up if it collapses to zero height.
Setting overflow: hidden is one trick to make a parent contain the floated children. The micro-clearfix hack is another one. You can also float the parent too, although I'm not sure if this works in all situations. Floating the parent is done in the "How to Make a Website" course here on treehouse. The header is floated because it contains floated children and this keeps it from collapsing.
Ji Jiang
2,505 PointsJi Jiang
2,505 PointsThank you! I have just added the rest of the CSS.