1. Use floating methodEffect picture: The code is as follows: (Note that the height of .content is 500px, which is the height of the parent element, but the floating element is above .content and covers .content. Change the .nav background style to background-color: rgba(0,0,0,0.1); to observe the effect) <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Height fills the parent container</title> </head> <style> .parent { height: 500px; width: 300px; border: 1px solid red;/***/ padding: 2px 2px;/***/ } .nav { height: 100px; width: 100%;/*Required, full width to prevent floating*/ float: left;/*Required*/ background-color: red; } .content { height:100%;/*Required*/ background-color: green; } </style> <body> <div class="parent"> <div class="nav"> Fixed height </div> <div class="content"> Adaptive parent container, fill the remaining space </div> </div> </body> </html> 2. Use positioningThe code is as follows: (This method is recommended because it does not have the disadvantages of the above method) <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Height fills the parent container</title> </head> <style> .parent { position: relative; height: 500px; width: 300px; border: 1px solid red;/***/ padding: 2px 2px;/***/ } .nav { height: 100px; width: 100%; background-color: red; } .content { position:absolute; top: 100px; bottom: 0px; background-color: green; width: 100%; } </style> <body> <div class="parent"> <div class="nav"> Fixed height </div> <div class="content"> Adaptive parent container, fill the remaining space </div> </div> </body> </html> This concludes this article on how to use CSS to make the height of a child div fill the remaining space of its parent container. For more information on how to use CSS to make the height of a child div fill the remaining space, please search previous articles on 123WORDPRESS.COM or continue browsing the related articles below. We hope that you will support 123WORDPRESS.COM in the future! |
<<: JavaScript implements three common web effects (offset, client, scroll series)
>>: HTML page common style (recommended)
This article mainly introduces the method of conf...
The effect of this function is similar to vue的pro...
Table of contents 1. Core commands 2. Common comm...
Unicode Signature BOM - What is the BOM? BOM is th...
Effect There are currently 2 projects (project1, ...
Win2008 R2 zip format mysql installation and conf...
answer from stackflow: Simply <br> is suffic...
Preface This article mainly shares with you an ex...
What is Let’s first look at the concept of Docker...
The default number of remote desktop connections ...
The following error is reported when MySQL joins ...
Preface I have seen many articles about the leftm...
Preface As a basic data structure, arrays and obj...
Phenomenon: After MySQL version 5.7, the default ...
MySQL database reports ERROR 1045 (28000): Access...