解决方案主要有五种

首先写入全局样式

<style type="text/css">
html * {
margin: ;
padding: ;
}
.layout {
margin-top: 20px;
}
.layout article div {
min-height: 100px;
}
</style>

1、用浮动解决方案

缺点:清除浮动,脱离文档流

优点:兼容性好

 <section class="layout float">
<style media="screen">
.layout.float .left {
float: left;
width: 300px;
background: red;
}
.layout.float .right {
float: right;
width: 300px;
background: blue;
}
.layout.float .center {
background: yellow;
text-align: center;
}
</style>
<article class="left-right-center">
<div class="left"></div>
<div class="right"></div>
<div class="center">
<h1>浮动解决方案</h1>
1、这是三栏布局中间部分 2、这是三栏布局中间部分
</div>
</article>
</section>

2、绝对定位解决方案

缺点:布局脱离文档流

优点:快捷

<section class="layout absolute">
<style media="screen">
.layout.absolute .left-center-right > div {
position: absolute;
}
.layout.absolute .left {
background: red;
width: 300px;
left: 0;
}
.layout.absolute .right {
background: blue;
width: 300px;
right: 0;
}
.layout.absolute .center {
background: yellow;
left: 300px;
right: 300px;
text-align: center;
}
</style>
<article class="left-center-right">
<div class="left"></div>
<div class="center">
<h2>绝对定位解决方案</h2>
1、这是三栏布局绝对定位中间部分 2、这是三栏布局绝对定位中间部分
</div>
<div class="right"></div>
</article>
</section>

3、flexbox布局解决方案

优点:为了解决绝对定位和浮动不足,基本比较完美,移动端基本是flexbox

<section class="layout flexbox">
<style>
.layout.flexbox {
margin-top: 150px;
}
.layout.flexbox .left-center-right {
display: flex;
}
.layout.flexbox .left {
width: 300px;
background: red;
}
.layout.flexbox .right {
width: 300px;
background: blue;
}
.layout.flexbox .center {
flex: 1;
background: yellow;
text-align: center;
}
</style>
<article class="left-center-right">
<div class="left"></div>
<div class="center">
<h2>flexbox解决方案</h2>
1、这是三栏布局flexbox中间部分 2、这是三栏布局flexbox中间部分
</div>
<div class="right"></div>
</article>
</section>

4、表格布局解决方案

缺点:当某个单元格高度超过表格时,其他单元格也会调整高度

优点:表格在很多场景中还是很适用的,兼容性很好,当需要兼容ie8时

 <section class="layout table">
<style>
.layout.table .left-center-right {
width: 100%;
display: table;
height: 100px;
}
.layout.table .left-center-right > div {
display: table-cell;
}
.layout.table .left {
width: 300px;
background: red;
}
.layout.table .center {
background: yellow;
text-align: center;
}
.layout.table .right {
width: 300px;
background: blue;
}
</style>
<article class="left-center-right">
<div class="left"></div>
<div class="center">
<h2>表格布局解决方案</h2>
1、这是三栏布表格布局中间部分 2、这是三栏布表格布局中间部分
</div>
<div class="right"></div>
</article>
</section>

5、grid布局解决方案

缺点:

优点:代码简化

 <section class="layout grid">
<style media="screen">
.layout.grid .left-center-right {
display: grid;
width: 100%;
grid-template-rows: 100px;
grid-template-columns: 300px auto 300px;
}
.layout.grid .left {
background: red;
}
.layout.grid .center {
background: yellow;
text-align: center;
}
.layout.grid .right {
background: blue;
}
</style>
<article class="left-center-right">
<div class="left"></div>
<div class="center">
<h2>网格布局解决方案</h2>
1、这是三栏布表网格布局中间部分 2、这是三栏布网格布局中间部分
</div>
<div class="right"></div>
</article>
</section>

css中,在高度已知,写出三栏布局,其中左栏、右栏宽度各位300px,中间自适应的更多相关文章

  1. 前端一面/面试常考题1-页面布局:假设高度已知,请写出三栏布局,其中左栏、右栏宽度各为300px,中间自适应。

    题目:假设高度已知,请写出三栏布局,其中左栏.右栏宽度各为300px,中间自适应. [题外话:日常宣读我的目标===想要成为一名优雅的程序媛] 一.分析 1. 题目真的像我们想得这么简单吗? 其实不然 ...

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

    假设高度已知,请写出三栏布局,其中左栏.右栏各为300px,中间自适应的五种方法 HTML CSS 页面布局 题目:假设高度已知,请写出三栏布局,其中左栏.右栏各为300px,中间自适应 <!D ...

  3. css高度已知,左右定宽,中间自适应三栏布局

    css高度已知,左右定宽,中间自适应三栏布局: <!DOCTYPE html> <html lang="en"> <head> <meta ...

  4. 布局:高度已知,布局一个三栏布局,左栏和右栏宽度为200px,中间自适应

    需求:高度已知为200px,写出三栏布局,左栏和右栏各位200px,中间自适应,如下图所示: 方法一:float浮动布局 原理是:定义三个区块,需要注意的是中间的区块放在右边区块的下面,统一设置高度为 ...

  5. 请求大神,C#如何截取字符串中指定字符之间的部分 按指定字符串分割 一分为二 c# 去除字符串中的某个已知字符

    string stra = "abcdefghijk";string strtempa = "c";string strtempb = "j" ...

  6. 已知圆上三个点坐标,求圆半径 r 和 圆心坐标

    问题: 已知圆上三个点坐标分别为(x1,y1).(x2,y2).(x3,y3) 求圆半径R和圆心坐标(X,Y) X,Y,R为未知数,x1,y1,x2,y2,x3,y3为常数 则由圆公式:(x1-X)² ...

  7. 如何在在页面中清除一个已知的cookie?

    前些天在写一个项目的时候,使用cookie来存储一些用户数据,在用户登出时需要清理以往的数据,对于一个初学者来说,我需要学习如何清除一个已知的cookie. 首先,引入两个js文件: 1.jquery ...

  8. css多种方法实现已知宽度和未知宽度的元素水平垂直居中

    // html <div class="box-wrapper"> <div class="box"> 内部box <p>更 ...

  9. CSS 中的高度百分比

    CSS 中可以使用%来给定指定元素的大小,也就是高度.宽度.margin,padding 等等,但是相信很多人都对百分比表示法的具体含义并不清楚,那么不懂就练,毕竟是检验真理的唯一标准(考研党举个手我 ...

随机推荐

  1. 访问mysql出现Access denied for user 'root'@'的解决方法

    1.关闭mysql的服务 方法一:我的电脑右键-管理-服务和应用程序-服务,找到mysql,右键关闭 方法二:cmd进入命令提示符,service mysqld stop(这个是网上的方法,我试了一下 ...

  2. css-改变input原始样式

    1.改变input的提示字位置 input::-webkit-input-placeholder { /* placeholder颜色 */ color: #aab2bd; /* placeholde ...

  3. python+flask+session写供前端使用的后台接口,实现登录保存session时报错。

    RuntimeError: The session is unavailable because no secret key was set.  Set the secret_key on the a ...

  4. 点击iframe窗口里的超链接,打开新页面的方式

    点击iframe窗口里的超链接打开新页面的方式: a标签中设置按钮点击事件,事件调用的方法使用如下方法跳转链接:  window.open('url链接', '_blank');

  5. iis7 绑定多个ssl证书

    默认情况下iis上只能绑定一个ssl证书,如果多的话 会只认一个. 停止IIS 运行[ CMD]  ,  输入 [iisreset /STOP] 第一步:修改配置文件. 然后打开:C:/Windows ...

  6. ubuntu编译安装opencv

    简易安装opencv2: conda install --channel https://conda.anaconda.org/menpo opencv 或: sudo apt-get install ...

  7. java变量的自动提升与强制转换

    所有的byte型.short型和char的值将被提升到int型 一个字节可以提升为4个字节 4个字节不可以降为一个字节 强制转换4个字节转换为一个字节 [丢失精度] byte b = 3; b = ( ...

  8. php中的内存管理的介绍(转)

    本篇文章给大家带来的内容是关于php中的内存管理的介绍,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 一.php内存管理概述——Zend引擎 由于计算机的内存由操作系统进行管理,所以 ...

  9. 微信小程序之点击列表的item带参数跳转界面

    1.在js文件里写个界面跳转的事件处理函数gotableinfo,var index = parseInt(e.currentTarget.dataset.index); 为获取当前点击列表的下脚标, ...

  10. python自动化框架(一)

    一.jsonpath难点分析 dic = { "error_code": 0, "stu_info": [ { "id": 2057, &q ...