两列布局:左边固定,右边自适应

第一种方法:左边的div左浮动或者是绝对定位,右边的div加margin-left:左边div的宽度

html部分

 <div class="left"></div>
<div class="right"></div>

css部分

.left {
position: absolute; /*这可以换成float:left,都可以使其脱离文档流*/
height: 100px;
width: 300px;
background-color: blue;
}
.right {
height: 200px;
margin-left: 300px;
background-color: red;
}

第二种方法:BFC(块级格式化上下文)

对于BFC的理解可以看 http://www.cnblogs.com/vitruvi/p/4303891.html

html部分和上面是一样的,下面只写css部分

.left {
float: left;
height: 200px;
width: 300px;
background-color: blue;
}
.right {
overflow: auto;
height: 200px;
      background-color:red;
}

 第三种方法:这种方法其实是第一种方法的延伸

<div style="float:left;width:100%">
<p style="margin-right:170px;">文字</p>
</div>
<img width='' style='float:left;margin-left:-150px;'>

这种方法与第一种方法的比较的好处就是dom的顺序和显示的顺序是一致的

第四种方法:flex

css:

 .containter{
display: flex;
}
.left {
width: 200px;
background-color: blue;
}
.right {
background-color: red;
flex:1;
}

html:

<div class="containter">
<div class="left">left</div>
<div class="right">right</div>
</div>

第五种方法:table

       html *{
margin:0;
padding: 0;
}
.containter{
display: table;
width: 100%;
height: 100%;

}
.left {
width: 200px;
background-color: blue;
display: table-cell;
}
.right {
background-color: red;
display: table-cell;
}
<body>
<div class="containter">
<div class="left">left</div>
<div class="right">right</div>
</div>
</body>

第六种:grid

.containter{
display: grid;
width: 100%;
height: 100%;
grid-template-rows:100px;
grid-template-columns:200px auto;
}
.left {
width: 200px;
background-color: blue;
}
.right {
background-color: red;
}

两列布局:右边固定,左边自适应

第一种:float或position,其实和上面差不多

    .containter{
width:400px;
height: auto;
}
.right{
width:100px;
background: red;
float: right;
}
.left{
margin-right: 100px;
background: blue;
}

html

<div class="containter">
<div class="right">right</div>
<div class="left">left</div>
</div>

第二种方法:BFC

  .left {
height: 200px;
overflow: auto;
background-color: blue;
}
.right {
float: right;
background-color: red;
height: 200px;
width: 300px;
}

html同上

css之页面两列布局的更多相关文章

  1. css实现div两列布局——左侧宽度固定,右侧宽度自适应(两种方法)

    原文:css实现div两列布局--左侧宽度固定,右侧宽度自适应(两种方法) 1.应用场景 左侧一个导航栏宽度固定,右侧内容根据用户浏览器窗口宽度进行自适应 2.思路 首先把这个问题分步解决,需要攻克以 ...

  2. div+css经典三行两列布局

    写在前面 在面试的时候遇到这样一个笔试题,使用div+css布局一个三行两列的页面.这里主要考察的是css中postion的具体用法.详细信息可参考我这篇文章: [HTML/CSS]说说positio ...

  3. css之页面三列布局

    左右两边宽度固定,中间自适应 第一种方法:左右两边绝对定位 html代码 <div class="left"></div> <div class=&q ...

  4. css之页面三列布局之左右两边宽度固定,中间自适应

    左右两边宽度固定,中间自适应 左右两边绝对定位 可以利用浮动,左边的左浮动,右边的右浮动 css3 flex布局(html http://www.cnblogs.com/myzy/p/5919814. ...

  5. css之页面三列布局之左右上下高度固定,中间自适应

    第一种,绝对定位 !DOCTYPE HTML> <html> <head> <meta charset="gb2312"> <tit ...

  6. 3种常见的CSS页面布局--双飞翼布局、粘连布局、左右两列布局

    一.左右两列布局 1.代码如下,可先粘贴复制,自行运行 <!DOCTYPE html><html> <head> <meta charset="UT ...

  7. 两列布局,读《css那些事儿》

    两列布局: 1.两列定宽: 要点:float.width固定. :after清除浮动. 前提:两列的盒模型宽度相加不能大于父元素的宽度,否则会出现错位现象. <!DOCTYPE html> ...

  8. CSS读书笔记(1)---选择器和两列布局

    (1)CSS选择器优先权选择. 优先权从大到小的选择如下: 标有!important关键字声明的属性 HTML中的CSS样式属性 <div style="color:red" ...

  9. CSS两列布局——左侧宽度固定,右侧宽度自适应的3种方法

    1.左侧绝对定位法 直接看代码: <!DOCTYPE html> <html lang="en"> <head> <meta charse ...

随机推荐

  1. Python set集合类型操作总结

    Python中除了字典,列表,元组还有一个非常好用的数据结构,那就是set了,灵活的运用set可以减去不少的操作(虽然set可以用列表代替) 小例子 1.如果我要在许多列表中找出相同的项,那么用集合是 ...

  2. SSIS自定义数据流组件开发(血路)

    由于特殊的原因(怎么特殊不解释),需要开发自定义数据流组件处理. 查了很多资料,用了不同的版本,发现各种各样的问题没有找到最终的解决方案. 遇到的问题如下: 用VS2015编译出来的插件,在SSDTB ...

  3. Process的Waitfor() 引起代码死锁

    Java用process调用c#的exe后,process.waitfor(). exe执行会停在某处.据说是waitfor引起的exe子线程死锁. 先存一个链接 http://yearsaaaa12 ...

  4. AngularJS之directive

    AngularJS之directive AngularJS是什么就不多舌了,这里简单介绍下directive.内容基本上是读书笔记,所以如果你看过<AngularJS up and runnin ...

  5. Uva11292--------------(The Dragon of Loowater)勇者斗恶龙 (排序后贪心)

    ---恢复内容开始--- 题目: Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major ...

  6. 重装系统后,delphi7打开报错

    delphi7运行不正常的提示unable to rename'c:\program files\Borland\delphi7\Bin\delphi32.$$$'to'c:\program file ...

  7. Rails : 产品环境(生产环境)的部署

    bundle install rails server (默认为开发环境) rails server -p80 -e production (指定为生产环境 ,并自定义指定站点端口) rake RAI ...

  8. [git]问题list

    1. fast-forward和non fast-forward分别代表什么概念? 2. 在git中文件index是个什么概念? 3. stage/index/cache三者有什么关系? 4. git ...

  9. 数据库整合数据报表SQL实战

    协助同事整理sql统计报表. ---建立由avalue的视图,要过滤重复数据 CREATE VIEW vLectAnswerRecord as SELECT t2.OpenID,t2.Qguid,t1 ...

  10. 重载Python FTP_TLS 实现Implicit FTP Over TLS方式下载文件

    对于Python2.7来说,内置的FTP_TLS类并不支持Implicit FTP Over TLS加密方式的FTP Server操作,为支持Implicit FTP Over TLS加密方式,必须重 ...