解决方案主要有五种

首先写入全局样式

<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. 简单几步,教你学会PHP,新手必看!

    学习php的方法,学东西,永远不要妄想有速成这一说,告诉你了一个方式,但是缺少努力这一环节,那也是白搭.掌握好的学习方法非常必要,看看这篇如何学习PHP培训的方法,在此提醒一下大家,PHP不像别的科目 ...

  2. Struts功能详解——ActionMapping对象

    Struts功能详解——ActionMapping对象 ActionMapping描述了struts中用户请求路径和Action的映射关系,在struts中每个ActionMapping都是通过pat ...

  3. 初用jdbc来运行事务

    dao层 public Connection getConnection() throws Exception { Class.forName(driver); if (con == null || ...

  4. webpack基本配置

    module: { rules: [ { test: /\.css$/, use: ['style-loader','css-loader?minimize'] } ] } 一.入门 loader可以 ...

  5. Web测试常见问题点汇总

    UI测试 [目标] 确保用户可以访问产品所提供的浏览功能.符合企业或行业标准,包含用户易用性,友好性.可操作性等 [关注点] 菜单.对话框以及上边的文字.按钮.错误提示.帮助信息.图标.位置等. [常 ...

  6. 准备学习wrf

    namelist.wps 中的 geog_data_path=后面的文件夹的文件即土地覆被资料:(看下图) 推荐中科院地理所承担的地球系统科学数据共享平台上共享的100m分辨率资料,官网  http: ...

  7. React Lifecycle

    React Lifecycle 分为三种: 初始化阶段 状态的更新 销毁 实例化: ReactDom.render 用于将模板转换成HTML语言,并插入DOM节点. 1.getDefaultProps ...

  8. 如何使用 Pylint 来规范 Python 代码风格

    如何使用 Pylint 来规范 Python 代码风格 转载自https://www.ibm.com/developerworks/cn/linux/l-cn-pylint/   Pylint 是什么 ...

  9. Qt学习--信号与槽(多窗口的实现)

    按照helloword的创建过程 创建一个新的项目(项目名:window) 之后进行多窗口的实现过程: (参考:http://www.qter.org/portal.php?mod=view& ...

  10. 我的代码-random forest

    # coding: utf-8 # In[1]: import pandas as pdimport numpy as npfrom sklearn import treefrom sklearn.s ...