首页 > 其他分享 >假设高度已知,请写出三栏布局,其中左栏、右栏宽度各为300px,中间自适应.

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

时间:2023-10-02 23:32:24浏览次数:47  
标签:right layout background float 300px width 右栏 三栏

  1. 浮动、绝对定位、flexbox、表格、网格布局.
<style media="screen">
    .layout div{min-height:300px;}
    .layout .float{float:left;width:300px;background:red;}
    .layout .right{float:right;width:300px;background:blue;}
    .layout .center{background:yellow;}
</style>
<section class="layout">
    <div class="float"></div>
    <div class="right"></div>
    <div class="center"></div>
</section>

缺点: 浮动是脱离文档流的,需要清除浮动. 优点: 兼容性好.

<style media="screen">
    .layout>div{position:absolute;min-height:300px;}
    .layout .float{left:0;width:300px;background:red;}
    .layout .right{right:0;width:300px;background:blue;}
    .layout .center{left:300px;right:300px;background:yellow;}    # 这里是自适应的关键
</style>
<section class="layout">
    <div class="float"></div>
    <div class="right"></div>
    <div class="center"></div>
</section>

缺点: 已经脱离文档流了,表示下面所有的子元素全部需要脱离文档流.可使用性比较差. 优点: 快捷

<style media="screen">
    .layout{display:flex;}
    .layout>div{min-height:300px;}
    .layout .float{width:300px;background:red;}
    .layout .right{width:300px;background:blue;}
    .layout .center{flex:1;background:yellow;}
</style>
<section class="layout">
    <div class="float"></div>
    <div class="center"></div>    # 这里一定要在中间,不能跟上面一样写法
    <div class="right"></div>
</section>

优点: 解决上面两个不足,移动端都比较倾向.

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

优点: 表格布局的兼容性非常好 缺点: 当三个单元格有一个超出高度,同时两个都要超过高度.

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

标签:right,layout,background,float,300px,width,右栏,三栏
From: https://blog.51cto.com/u_16251183/7685124

相关文章

  • 前端经典三栏布局
    浮动实现前面放置的两个div进行浮动,后面一个让其marginauto居中<style>/*浮动三栏*/.fatherdiv{width:200px;height:200px;}.left{background-color:red;float:left;......
  • Bing全新改版为三栏显示 加入社交搜索
    微软在Bing官网上宣布,将对这个有着三年历史的搜索引擎进行重大改版,新版的搜索结果将以三栏(如下图)的形式显示,分为CoreSearchResults、Snapshot和Sidebar,让搜索结果更加清晰简洁:从左到右依次是网页为主的搜索结果、地图以及评价和其他信息、社交信息。社交信息应该是此次改版的重头......
  • HTML与CSS手写-4.实现常用布局(三栏、圣杯、双飞翼、吸顶),可是说出多种方式并理解其优缺
    实现常用布局两栏布局三栏、圣杯、双飞翼圣杯布局和双飞翼布局是前端工程师需要日常掌握的重要布局方式。两者的功能相同,都是为了实现一个两侧宽度固定,中间宽度自适应......
  • 如何是心啊两栏布局,右侧自适应?三栏布局中间自适应
    如何是心啊两栏布局,右侧自适应?三栏布局中间自适应?一、在日常布局中,无论是两栏布局还是三栏布局,使用的频率都非常高两栏布局:两栏布局实现效果就是将页面分割成左右宽度不......
  • 三栏布局
    子绝父相+左left:0px右right:0px中间margin:width<style>.container{position:relative;height:600px;}......
  • 三栏布局
    三栏布局就是在网页上以平铺方式展现左中右三列布局,其特点在于,左右两列固定在网页两侧,中间一列永远居中,且当网页宽度大于左右两列宽度之和时,中间一列可随网页整体宽度的变......