html div 的高度
当 div 中只有背景图片的时候, 不足以撑起它的高度, 所以设了也没用
所以, 我们要设随 div 大小而改变的 div 时
应该
利用::after 或::before 伪元素, 为背景添加一个 content 为 null 的元素
如
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title > 无标题文档 </title>
- <style type="text/CSS">
- .bg::after{
- content:"";
- display: block;
- padding-bottom: 48%;
- }
- </style>
- </head>
- <body>
- <div class="bg" style="background:url(img/bj.jpg) no-repeat ;background-size:100% 100%;"></div>
- </body>
- </html>
来源: http://www.bubuko.com/infodetail-2656701.html