How can I get the nav div to have expand down or have the height the same as its parent div?
* { border:0; padding:0; margin:0; } #container { margin-left: auto; margin-right: auto; border: 1px solid black; overflow: auto; width: 800px; } #nav { width: 19%; border: 1px solid green; float:left; } #content { width: 79%; border: 1px solid red; float:right; }
<div id="container"> <div id="nav"> <ul> <li>Menu</li> <li>Menu</li> <li>Menu</li> <li>Menu</li> <li>Menu</li> </ul> </div> <div id="content"> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam fermentum consequat ligula vitae posuere. Mauris dolor quam, consequat vel condimentum eget, aliquet sit amet sem. Nulla in lectus ac felis ultrices dignissim quis ac orci. Nam non tellus eget metus sollicitudin venenatis sit amet at dui. Quisque malesuada feugiat tellus, at semper eros mollis sed. In luctus tellus in magna condimentum sollicitudin. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur vel dui est. Aliquam vitae condimentum dui. Praesent vel mi at odio blandit pellentesque. Proin felis massa, vestibulum a hendrerit ut, imperdiet in nulla. Sed aliquam, dolor id congue porttitor, mauris turpis congue felis, vel luctus ligula libero in arcu. Pellentesque egestas blandit turpis ac aliquet. Sed sit amet orci non turpis feugiat euismod. In elementum tristique tortor ac semper.</p> </div> </div>
Method 2: We can make the display attribute of the child container to table-row and display attribute of parent container to table, that will take all the height available from the parent div element. To cover all the width, we can make the width of parent div to 100%.
To auto-resize an image or a video to fit in a div container use object-fit property. It is used to specify how an image or video fits in the container. object-fit property: This property is used to specify how an image or video resize and fit the container.
For width it's easy, simply remove the width: 100% rule. By default, the div will stretch to fit the parent container.
You can achieve this with setting both the top
and bottom
attributes of the nav to 0
and the position: absolute
. Set the container to position: relative
.
See how this is done
IE11+ and all modern browsers support flexbox.
.container { display: flex; flex-direction: column; } .child { flex-grow: 1; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With