这篇文章将为大家详细讲解有关css实现两栏布局的方法有哪些,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
1、浮动布局
左侧栏固定宽度向左浮动,右侧主要内容则用margin-left留出左侧栏的宽度,默认宽度为auto,自动填满剩下的宽度。
<div class="one"></div>
<div class="two"></div>
.one{
float: left;
width: 200px;
height: 200px;
background: darkcyan
}
.two{
margin-left: 200px;
height: 200px;
background: salmon
}
右侧固定宽度,左侧自适应则是同理,只要将固定栏右浮动,使用margin-right空出其宽度即可。
<div class="one"></div>
<div class="two"></div>
.one{
float: right;
width: 200px;
height: 200px;
background: darkcyan
}
.two{
margin-right: 200px;
height: 200px;
background: salmon
}
2、浮动布局+负外边距(双飞翼布局的两栏版)
<div class="aside"></div>
<div class="main">
<div class="content"></div>
</div>
.aside{
width: 300px;
height: 100px;
background:darkcyan;
margin-right: -100%;
float: left;
}
.main{
width: 100%;
float: left;
}
.content{
margin-left: 300px;
background: salmon;
}
3、绝对定位
<div class="left"></div>
<div class="right"></div>
.left{
width: 200px;
height: 200px;
position: absolute;
background: darkcyan
}
.right{
height: 200px;
margin-left:200px;
background: salmon;
}
关于css实现两栏布局的方法有哪些就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。