打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Div高度的百分比问题

Div高度的百分比问题  

2013-10-10 13:28:43|  分类: CSS |举报 |字号 订阅

总结:Div设置高度为百分比的时候  则外层的元素必须指定height属性
1.简单 外层div
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<style type="text/css">
html, body {
width:100%;
height:100%;
margin:0px;
padding:0px;
}
#one {
width:50%;
height:50%;
background-color:silver;
margin:auto;
}
</style>
</head>
<body>
<div id="one"></div>
</body>
</html>
显示结果:
 
2.简单外层div
  <style type="text/css">
html,body {
width:100%;
height:100%;
margin:0px;
padding:0px;
}
.center {
width:80%;
margin:auto;
}
#top {
height:20%;
background-color:yellow;
}
#module {
height:60%;
background-color:gray;
}
#bottom {
height:20%;
background-color:blue;
}
</style>
<body>
<div id="top" class="center"></div>
<div id="module" class="center"></div>
<div id="bottom" class="center"></div>
</body>
显示结果:
 
3.简单内层div
    <style type="text/css">
#outOne {
width:500px;
height:500px;
margin:auto;
background-color:gray;
}
#innerOne {
width:50%;
height:50%;
margin:auto;
background-color:blue;
}
</style>
显示结果:
 
4.简单内层div2

<style type="text/css">
html,body {
width:100%;
height:100%;
padding:0px;
margin:0px;
}
#outOne {
width:50%;
height:50%;
margin:auto;
background-color:gray;
}
#innerOne {
width:50%;
height:50%;
margin:auto;
background-color:blue;
}
</style>

<body>
       <div id="outOne">
        <div id="innerOne"></div>
    </div>
</body>

显示结果:
 
5.简单内层div3:
     <style type="text/css">
html,body {
width:100%;
height:100%;
padding:0px;
margin:0px;
}
#outOne {
width:50%;
height:50%;
margin:auto;
background-color:gray;
}
#innerOne {
width:50%;
height:50%;
margin:auto;
background-color:blue;
}
#innerTwo {
width:60%;
height:30%;
margin:auto;
background-color:red;
}
</style>
<body>
<div id="outOne">
<div id="innerOne"></div>
<div id="innerTwo"></div>
</div>
</body>
显示结果:
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
盒子模型的实例
DIV+CSS左右布局(左固定右自适应)
关于使用CSS居中(包括水平/垂直) 统一教学网
网页的基本布局
请教CSS中的position:relative;的作用。
超详细常用css布局
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服