<!DOCTYPE html>
<html> <head>
<meta charset="UTF-8">
<title>实现三个div,固定左右两边的div宽为200,中间的div宽度自适应的四种方法</title>
<style type="text/css">
html,
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
color: #fff;
text-align: center;
line-height: 100px;
} .clear:after {
content: "";
display: block;
height: 0;
clear: both;
}
/*float法*/ .left {
float: left;
width: 200px;
height: 100px;
background: Red;
} .right {
float: right;
width: 200px;
height: 100px;
background: green;
} .center {
margin-left: 200px;
margin-right: 20px;
height: 100px;
background: blue;
}
/*position*/ .position {
position: relative;
margin-bottom: 100px;
} .left2 {
position: absolute;
left: 0;
top: 0;
width: 200px;
height: 100px;
background: Red;
} .right2 {
position: absolute;
right: 0;
top: 0;
width: 200px;
height: 100px;
background: green;
} .center2 {
position: absolute;
left: 200px;
right: 200px;
top: 0;
background: blue;
}
/*table*/ .table {
display: table;
width: 100%;
} .table .child {
display: table-cell;
} .left3 {
width: 200px;
height: 100px;
background: Red;
} .right3 {
width: 200px;
height: 100px;
background: green;
} .center3 {
height: 100px;
background: blue;
}
/*flex*/ .flex {
display: box;
display: -webkit-box;
display: -moz-box;
} .left4 {
width: 200px;
height: 100px;
background: Red;
} .right4 {
width: 200px;
height: 100px;
background: green;
} .center4 {
box-flex: 1;
-webkit-box-flex: 1;
-moz-box-flex: 1;
background: blue;
}
</style>
</head> <body>
<div class="clear">
<div class="left">float法</div>
<div class="right">float法</div>
<div class="center">float法</div>
</div>
<br />
<div class="position clear">
<div class="left2">position法</div>
<div class="right2">position法</div>
<div class="center2">position法</div>
</div>
<br />
<div class="table clear">
<div class="left3 child">table法</div>
<div class="center3 child">table法</div>
<div class="right3 child">table法</div>
</div>
<br />
<div class="flex clear">
<div class="left4 child">flex法</div>
<div class="center4 child">flex法</div>
<div class="right4 child">flex法</div>
</div>
</body> </html>

效果图

最新文章

  1. MemoryMappedFile 在 Mono in Linux 的开发笔记
  2. 0020 Java学习笔记-面向对象-变量
  3. bash的一些小技巧
  4. YTU 3019: 螺旋方阵
  5. linux下手动安装apache详解
  6. 第八章CDC设备
  7. perl Exporter一些神奇写法
  8. 【mysql】phpMyadmin上传文件限制
  9. Scala编程入门---数组操作之Array.ArrayBuffer以及遍历数组
  10. WebApiClient的JsonPatch局部更新
  11. Java开发笔记(八十一)如何使用系统自带的注解
  12. [nodejs] nodejs开发个人博客(二)入口文件
  13. 用Python来玩微信跳一跳
  14. Inside The C++ Object Model(一)
  15. VNC实现Windows远程访问Ubuntu 16.04(无需安装第三方桌面,直接使用自带远程工具)
  16. XWIKI部署安装
  17. jpa orderby
  18. git学习笔记:一台电脑上配置两个git账户
  19. IIS 8 配置错误
  20. mySql连接报错

热门文章

  1. HDU 3555 (递推&amp;&amp;记忆化)
  2. asp.net技术(公共方法)
  3. Springboot 创建的maven获取resource资源下的文件的两种方式
  4. PHPCMS V9双语站建设切换
  5. R语言-组间差异的非参数检验
  6. django模型中auto_now和auto_now_add的区别
  7. poj2125 最小点权覆盖集
  8. JavaScript--for in循环访问属性用&quot;.&quot;和[ ]的区别
  9. 登录注册beta版
  10. CODE FESTIVAL 2017 qual B B - Problem Set【水题,stl map】