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
Juan Pablo Mejia Duque
6,255 Pointsproblem size of div elements.
Im trying to create a 2 horizontal div. the left one must be a 300px width and the other one must adjust to the left size. How can I do this because I use percentage and it doesnt work, one of the divs overflows the other. This is my code.
<!DOCTYPE html> <html> <head> <link rel="stylesheet" href="main.css"> </head>
<body>
<div class="main-nav"></div>
<div class="extra-nav"></div>
</body>
</html>
html, body { height: 100%; padding: 0; margin: 0; }
.main-nav { position: absolute; top: 0; left: 0; background: black; width: 300px; height: 100%; z-index: 10; }
.extra-nav { width: 80%; height: 100%; background: red; position: absolute; right: 0; top: 0; z-index: 0; }
1 Answer
Christian Lawrence
3,941 PointsHello Juan,
Try this code, I don't think you need to position the elements absolute, a float will do the job. Also note it is difficult to mix different types of width (px & %) in this case both have been set to a width of %, with one element having a max-width of 300px.
http://codepen.io/anon/pen/ByLYVO
html, body {
height: 100%;
padding: 0;
margin: 0;
}
.main-nav {
float: left;
background: yellow;
width: 20%;
max-width: 300px;
height: 100%;
z-index: 10;
}
.extra-nav {
width: 80%;
height: 100%;
background: red;
float: right;
z-index: 0;
}
Juan Pablo Mejia Duque
6,255 PointsJuan Pablo Mejia Duque
6,255 Pointsyes it works perfect, thank you Christian
Christian Lawrence
3,941 PointsChristian Lawrence
3,941 Pointsoh and you can remove the height:100% too as that won't be doing much now it's not position:absolute