用两种不同的方法来实现一个两列布局,其中左侧部分宽度固定、右侧部分宽度随浏览器宽度的变化而自适应变化
2016-09-21 11:53
1171 查看
[html] view
plain copy
<pre name="code" class="html"><div id="one" class="box">
<div id="box1" >box1</div>
<div id="box2" >box2</div>
</div>
<div class="box">
<div id="box3" >box3</div>
<div id="box4" >box4</div>
</div>
方法一的css部分:
[css] view
plain copy
#one{
padding-left: 300px;
}
#box1{
float: left;
margin-top: 50px;
background-color: #34ED16;
width: 100%;
height: 50px;
position: relative
df65
;
}
#box2{
float: left;
margin-top: 50px;
background-color: greenyellow;
width: 300px;
height: 50px;
margin-left: -100%;
position: relative;
left: -300px;
}
注意:父节点设置padding-left:300px,相当于设置左边部分宽度为300px,而右边宽度为:100%-300px。
用relative来固定左边和右边的位置。
方法二的css部分:
[css] view
plain copy
#box3{
margin-top: 180px;
background-color: bisque;
width: 300px;
height: 50px;
}
#box4{
margin-top: -50px;
margin-left: 300px;
background-color: #ff0000;
height: 50px;
}
注意:box4设置成margin-top:-50px,是为了让box3和box4在同一水平位置上
plain copy
<pre name="code" class="html"><div id="one" class="box">
<div id="box1" >box1</div>
<div id="box2" >box2</div>
</div>
<div class="box">
<div id="box3" >box3</div>
<div id="box4" >box4</div>
</div>
方法一的css部分:
[css] view
plain copy
#one{
padding-left: 300px;
}
#box1{
float: left;
margin-top: 50px;
background-color: #34ED16;
width: 100%;
height: 50px;
position: relative
df65
;
}
#box2{
float: left;
margin-top: 50px;
background-color: greenyellow;
width: 300px;
height: 50px;
margin-left: -100%;
position: relative;
left: -300px;
}
注意:父节点设置padding-left:300px,相当于设置左边部分宽度为300px,而右边宽度为:100%-300px。
用relative来固定左边和右边的位置。
方法二的css部分:
[css] view
plain copy
#box3{
margin-top: 180px;
background-color: bisque;
width: 300px;
height: 50px;
}
#box4{
margin-top: -50px;
margin-left: 300px;
background-color: #ff0000;
height: 50px;
}
注意:box4设置成margin-top:-50px,是为了让box3和box4在同一水平位置上
相关文章推荐
- 用两种不同的方式来实现一个三列布局,其中左侧和右侧的部分宽度固定,中间部分宽度随浏览器宽度的变化而自适应变化
- 用两种不同的方式来实现一个三列布局,其中左侧和右侧的部分宽度固定,中间部分宽度随浏览器宽度的变化而自适应变化
- CSS float的初步理解:用两种不同的方式来实现一个三列布局,其中左侧和右侧的部分宽度固定,中间部分宽度随浏览器宽度的变化而自适应变化
- HTML/CSS学习之 三列布局,其中左侧和右侧的部分宽度固定,中间部分宽度随浏览器宽度的变化而自适应变化
- CSS-左侧固定宽度,右侧自适应宽度的两列布局实现方法总结
- 两列布局——左侧宽度固定,右侧宽度自适应的两种方法
- 两列布局——左侧宽度固定,右侧宽度自适应的两种方法
- 两列布局——左侧宽度固定,右侧宽度自适应的两种方法
- 两列布局——左侧宽度固定,右侧宽度自适应的两种方法
- CSS基础篇--css实现两列布局,一列固定宽度,一列宽度自适应方法
- css布局:左边固定宽度,右边自适应宽度或右侧固定,左侧自适应三种方法
- div 两列布局,左侧固定宽度px,右侧自适应宽度,满屏
- css实现左右布局,左侧div固定不变,右侧div宽度自适应
- CSS实现左右栏宽度固定中间栏宽度变化且各栏高度自适应背景色不同的三栏布局
- DIV+CSS布局两列右列宽度自适应布局的不同实现方法
- android布局时,左侧宽度固定而右侧textview高度变化,怎么9png实现左侧高度与右侧相等?
- 【前端攻城狮之路】CSS两列布局——右侧固定宽度、左侧自适应
- 两种不同的方法来实现一个两列布局
- css实现右侧固定宽度,左侧宽度自适应
- 老生长谈:css实现右侧固定宽度,左侧宽度自适应