页面布局:假设高度已知,请写出三栏布局,其中左栏、由栏宽度各自为300px,中间自适应

学习整理

方法一:浮动

<style>
* {
    padding:0;
    margin:0;
}
.layout article div {
    min-height: 100px;
}
.left{
    float: left;
    width:300px;
    background: blue;
}
.right{
    float: right;
    width:300px;
    background: red;
}
.center {
    background: yellow;
}
</style>
<section class="layout float">
    <article class="left-right-center">
        <div class="left"></div>
        <div class="right"></div>
        <div class="center"></div>
    </article >
</section>

方法二:绝对定位

<style>
.left-right-center>div {
    position: absolute;
}
.layout article div {
    min-height: 100px;
}
.left{
    left: 0;
    width:300px;
    background: blue;
}
.center {
    left: 300px;
    right: 300px;
    background: yellow;
}
.right{
    right: 0;
    background: red;
}
</style>
<section class="layout absolute">
    <article class="left-right-center">
        <div class="left"></div>
        <div class="center"></div>
        <div class="right"></div>
    </article >
</section>

方法三:flexbox

<style>
.flexbox {
    margin-top: 140px;
}
.left-right-center {
    display: flex;
}
.layout article div {
    min-height: 100px;
}
.left{
    width:300px;
    background: blue;
}
.center {
    flex: 1;
    background: yellow;
}
.right{
    width: 300px;
    background: red;
}
</style>
<section class="layout flexbox">
    <article class="left-right-center">
        <div class="left"></div>
        <div class="center"></div>
        <div class="right"></div>
    </article >
</section>

方法四:表格布局

<style>
.left-right-center {
    width: 100%;
    display: table;
    height: 100px;
}
.layout article div {
    display: table-cell;
}
.left{
    width:300px;
    background: blue;
}
.center {
    background: yellow;
}
.right{
    width: 300px;
    background: red;
}
</style>
<section class="layout table">
    <article class="left-right-center">
        <div class="left"></div>
        <div class="center"></div>
        <div class="right"></div>
    </article >
</section>

方法五:网格布局

<style>
.left-right-center {
    width: 100%;
    display: grid;
    grid-template-rows: 100px;
    grid-template-columns: 200px auto 300px;
}
.left{
    background: blue;
}
.center {
    background: yellow;
}
.right{
    background: red;
}
</style>
<section class="layout grid">
    <article class="left-right-center">
        <div class="left"></div>
        <div class="center"></div>
        <div class="right"></div>
    </article >
</section>

优缺点:

(1)浮动:

缺点:脱离文档流

优点:兼容性好

(2)绝对定位:

缺点:布局脱离文档流,子元素脱离文档流,可使用性差

优点:快捷

(3)flexbox:

缺点:有的ie版本不兼容

优点:完美

(4)表格布局:

缺点:麻烦,操作繁琐,不利于搜索引擎抓取信息

优点:兼容性好

(5)网格布局:

优点:代码少

高度已知去掉哪个不再适用:

浮动,定位,网格布局

兼容性如何:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值