为了账号安全,请及时绑定邮箱和手机立即绑定

关于页面和div

关于页面和div

木柘 2016-07-08 20:04:50
<!DOCTYPE html> <html> <head> <title></title> <style type="text/css"> .div1{ height: 50px; background-color: red; } .div2{ background-color: blue; } .div3{ height: 50px; background-color: green; } </style> </head> <body> <div class="div1"></div> <div class="div2"></div> <div class="div3"></div> </body> </html>对于div2,如何写其样式使得div1 div2 div3的height和至少能够撑起整个页面。(不要那种写死的)写法应该很多吧?求指导,谢谢。
查看完整描述

1 回答

已采纳
?
刚毅87

TA贡献345条经验 获得超309个赞

那 div 的高度也不要写固定值,改为百分比,代码如下

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <style type="text/css">
    		*{
    			margin: 0;
    			padding: 0;
    		}
    		body,html{
    			height: 100%;
    		}
        .div1{
            height: 50%;
            background-color: red;
        }
        .div2{
            background-color: blue;
        }
        .div3{
            height: 50%;
            background-color: green;
        }
    </style>
</head>
<body>
    <div class="div1"></div>
    <div class="div2"></div>
    <div class="div3"></div>
</body>
</html>

望采纳!

查看完整回答
反对 回复 2016-07-08
  • 木柘
    木柘
    div块随内容撑开,不知道它具体的大小,如何确定百分比呢?
  • 刚毅87
    刚毅87
    你既要让 div 撑开页面高度,又让 div 随页面撑开,那只有你的内容够多,足够撑开整个页面
  • 木柘
    木柘
    百分比如何计算?不能凭感觉吧。
点击展开后面2
  • 1 回答
  • 0 关注
  • 1398 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信