利用css实现两列等高的方法
2016-03-30 11:00
681 查看
1:利用负边距
<style type="text/css">
.container{
width:980px
background: pink;
overflow:hidden;
}
/*清楚浮动*/
.clearfloat{
zoom:1;
}
.clearfloat:after{
display:block;
clear:both;
content:"";
height: 0;
line-height: 0;
visibility: hidden;
}
/*清楚浮动*/
.mainbox{
width:650px;
float:left;
background: red;
margin-bottom:-9999px;
padding-bottom:9999px;
}
.sidebox{
width:280px;
float: right;
background: green;
margin-bottom:-9999px;
padding-bottom:9999px;
}
</style>
2:利用背景图片在Y方向重复
<style type="text/css">
.container{
width:980px
background: url(images/a.png) repeat-y 0 0;
}
/*清楚浮动*/
.clearfloat{
zoom:1;
}
.clearfloat:after{
display:block;
clear:both;
content:"";
height: 0;
line-height: 0;
visibility: hidden;
}
/*清楚浮动*/
.mainbox{
width:650px;
float:left;
}
.sidebox{
width:280px;
float: right;
}
</style>
3:利用边框模拟(定位元素的高度不能大于非定位元素的高度)
<style type="text/css">
.container{
width:980px;
positin:relative;
}
/*清楚浮动*/
.clearfloat{
zoom:1;
}
.clearfloat:after{
display:block;
clear:both;
content:"";
height: 0;
line-height: 0;
visibility: hidden;
}
/*清楚浮动*/
.mainbox{
width:650px;
float:left;
background: red;
border-right:280px solid green;
}
.sidebox{
width:280px;
position:absolute;
top:0;
right:0;
}
</style>
div class="container clearfloat">
<div class="mainbox">主要</div>
<div class="sidebox">侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏</div>
</div>
<style type="text/css">
.container{
width:980px
background: pink;
overflow:hidden;
}
/*清楚浮动*/
.clearfloat{
zoom:1;
}
.clearfloat:after{
display:block;
clear:both;
content:"";
height: 0;
line-height: 0;
visibility: hidden;
}
/*清楚浮动*/
.mainbox{
width:650px;
float:left;
background: red;
margin-bottom:-9999px;
padding-bottom:9999px;
}
.sidebox{
width:280px;
float: right;
background: green;
margin-bottom:-9999px;
padding-bottom:9999px;
}
</style>
2:利用背景图片在Y方向重复
<style type="text/css">
.container{
width:980px
background: url(images/a.png) repeat-y 0 0;
}
/*清楚浮动*/
.clearfloat{
zoom:1;
}
.clearfloat:after{
display:block;
clear:both;
content:"";
height: 0;
line-height: 0;
visibility: hidden;
}
/*清楚浮动*/
.mainbox{
width:650px;
float:left;
}
.sidebox{
width:280px;
float: right;
}
</style>
3:利用边框模拟(定位元素的高度不能大于非定位元素的高度)
<style type="text/css">
.container{
width:980px;
positin:relative;
}
/*清楚浮动*/
.clearfloat{
zoom:1;
}
.clearfloat:after{
display:block;
clear:both;
content:"";
height: 0;
line-height: 0;
visibility: hidden;
}
/*清楚浮动*/
.mainbox{
width:650px;
float:left;
background: red;
border-right:280px solid green;
}
.sidebox{
width:280px;
position:absolute;
top:0;
right:0;
}
</style>
div class="container clearfloat">
<div class="mainbox">主要</div>
<div class="sidebox">侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏</div>
</div>
相关文章推荐
- HTML学习笔记(二)样式
- CSS的各种属性
- CSS制作表格式按钮
- 《Head First HTML与CSS、XHTML》读后记录
- CSS文字单位
- CSS Hack解析
- CSS定位专题
- CSS旧版flex及兼容
- 迷你猫头鹰
- index.css文件查看这些代码
- 简单谈谈自己对htm与css中画圆的理解。
- CSS margin 边界叠加知识点
- <响应式布局>3---设计案例样式文件的另一种引入方式
- css中clip:rect矩形剪裁功能
- CSS---cursor鼠标属性
- js,css 文件延迟加载
- CSS后代选择器可能的错误认识
- css3 transform IE 滤镜转换
- css 伪类冒号前空格
- CSS3魔法堂:CSS3滤镜及Canvas、SVG和IE滤镜替代方案详解[转]