Home > Web Front-end > HTML Tutorial > The external div adapts to the height of the internal tag, setting the minimum height and maximum height_html/css_WEB-ITnose

The external div adapts to the height of the internal tag, setting the minimum height and maximum height_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:39:54
Original
1728 people have browsed it

1. div adaptive height: In front-end development, it is often necessary to make the outer div automatically adapt to the height of the internal tags and content. The internal tags may be

,
    ,

    1. Clear the float attribute with a pseudo object

     1 <!doctype html> 2 <html lang="en"> 3  <head> 4   <meta charset="UTF-8"> 5   <title>Document</title> 6   <!-- CSS --> 7   <style type="text/css"> 8     #wrap2{     9         width: auto;10         height: auto;11         min-height: 250px;/*设置最小高度*/12         max-height: 500px;/*设置最大高度*/13         overflow: hidden;/*内容超出后隐藏*/14         border: 2px solid yellow;15     }16     #wrap2:after{    17         content: "";18         visibility: hidden;19         display: block;20         clear: both;21     }22     #inner2{    23         width: 200px;24         height: 200px;25         border: 1px solid black;26         float: right;27     }28   </style>29  </head>30  <body>31   <div id="wrap2" class="">32     <div id="inner2" class=""></div>33   </div>34  </body>35 </html>36     
    Copy after login

    2. Use Empty div to clear the float attribute

     1 <!doctype html> 2 <html lang="en"> 3  <head> 4   <meta charset="UTF-8"> 5   <title>Document</title> 6   <!-- CSS --> 7   <style type="text/css"> 8     #wrap1{     9         width: auto;10         height: auto;11         border: 2px solid yellow;12     }13     #inner1{    14         width: 200px;15         height: 200px;16         border: 1px solid black;17         float: right;18     }19   </style>20  </head>21  <body>22   <div id="wrap1">23     <div id="inner1"></div>24     <div style="clear:both;"></div> <!-- 在外层div的底部加一个空的div标签,并设置样式为clear:both; -->25   </div>26  </body>27 </html>
    Copy after login

    2. Set the minimum and maximum height for the div:

    1 #wrap1{    2         width: auto;3         min-height: 100px;4         max-height: 500px;5         overflow: hidden;6         border: 2px solid yellow;7     }
    Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template