div 自适应宽度

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
body {margin: 0 auto;text-align: center;}
#container {text-align: left;background-color: green;}
#top {height: 160px;background-color: red;}
#middle {height: 240px;background-color: yellow;}
#middle_left {height:240px;width: 200px;float: left;background-color: #333;}
#middle_right {height:240px;width: 220px;float: right;background-color: #ddd;}
/* 自适应宽度的 div:1.不要设置 width,即 width:auto ,2.不要设置 float,即 float:none,3.其div的位置应放在最后,比 float='right' 的 div 还靠后*/
#middle_center {height:240px;background-color: #aaa;}
#foot {height: 120px;background-color: teal;}
.clearDiv {clear:both;}
</style>
</head>
<body>
<div id="container">
<div id="top">top</div>
<div class="clearDiv"></div>
<div id="middle">
<!-- 居左 -->
<div id="middle_left">middle left</div>
<!-- 居右 -->
<div id="middle_right">middle right</div>
<!-- 自适应宽度的 div 应放在最后 -->
<div id="middle_center">middle center</div>
</div>
<div class="clearDiv"></div>
<div id="foot">foot</div>
</div>
</body>
</html>
ie6 下 float 元素的空隙 问题:
 
解决方案: 
float:left; 时 _margin-right:-3px;
float:right;时 _margin-left:-3px;
转自:http://kuchaguangjie.iteye.com/blog/752234

div 自适应宽度的更多相关文章

  1. div自适应宽度

    对于div自适应宽度,网上的说法基本上都是将要自适应宽度的div放在其它固定宽度的最后,不指定其float属性或将float属性指定为none,比如三栏布局居中的一栏为自适应宽度,就可以这样来定义三栏 ...

  2. 关于ie6中绝对定位或浮动的div中既有向左float也有向右float时候如何让外层div自适应宽度的解决方案--

    一个详细的说明请见: http://www.cnblogs.com/yiyang/p/3265006.html 我的问题大约为,如下代码: <!DOCTYPE html PUBLIC " ...

  3. 一个宽度不确定的DIV里放三个水平对齐的DIV,左右两个DIV宽度固定为100px,中间那个DIV自适应宽度

    方法一:浮动  注意三个div的位置 <html><head> <meta charset="utf-8"> <style type=&q ...

  4. CSS 圣杯布局升级版---多个固定宽度一个自适应宽度

    1.一个div固定,一个div自适应宽度.两种情况,固定在左或者在右. HTML: <div class="box1"> <div class="mai ...

  5. div 内容宽度自适应、超出后换行

    div 内容宽度自适应,超出后换行 { max-width:100%;width: fit-content;width: -webkit-fit-content;width: -moz-fit-con ...

  6. 纯CSS实现Div高度根据自适应宽度(百分百调整)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. 纯Css实现Div高度根据自适应宽度(百分比)调整

    在如今响应式布局的要求下,很多能自动调整尺寸的元素能够做到高宽自适应,如img,通过{width:50%;height:auto;}实现图片高度跟随宽度比例调整. 然而,用的最多的标签一哥Div却不能 ...

  8. 实现一个div,左边固定div宽度200px,右边div自适应

    实现一个div,左边固定div宽度200px,右边div自适应<div class= "container"> <div class="left&quo ...

  9. 从三栏自适应宽度布局到css布局的讨论

    如何实现一个三栏自适应布局,左右各100px,中间随着浏览器宽度自适应? 第一个想到的是使用table布局,设置table的宽度为100%,三个td,第1个和第3个固定宽度为100px,那么中间那个就 ...

随机推荐

  1. 红帽配置Centos仓库[红帽Redhat7替换Centos7网络源]

    1.卸载红帽yum源 rpm -e $(rpm -qa|grep yum) --nodeps 2.删除所有repo相关文件 rm -rf /etc/yum.conf rm -rf /etc/yum.r ...

  2. python进度条

    #!/usr/bin/env python# -*- coding:utf-8 -*- import urllib url = "http://www.163.com/" #htm ...

  3. 《GPU高性能编程CUDA实战》附录二 散列表

    ▶ 使用CPU和GPU分别实现散列表 ● CPU方法 #include <stdio.h> #include <time.h> #include "cuda_runt ...

  4. forward与redirect的区别

    1.从地址栏显示来说forward是服务器请求资源,服务器直接访问目标地址的URL,把那个URL的响应内容读取过来,然后把这些内容再发给浏览器.浏览器根本不知道服务器发送的内容从哪里来的,所以它的地址 ...

  5. js1:根据标签的Id获取value值

    例子:<input id="startDate" name="startDate" value="2015-09-14" class= ...

  6. 过滤器 ;spring拦截器 切片 小结

    1. springMVc的拦截器 实现HandlerInterceptor接口,如下: public class HandlerInterceptor1 implements HandlerInter ...

  7. win10/win7 笔记本 开启虚拟无线 批处理

    Microsoft Virtual WiFi Miniport Adapter 一.看网络网卡 有多出的这一项“Microsoft Virtual WiFi Miniport Adapter”,那么说 ...

  8. Jquery jcarousellite 参数说明

    参数说明: btnPrev     string 上一个按钮的class名, 比如  btnPrev: ".prev" btnNext     string 下一个按钮的class ...

  9. UI5-文档-4.28-Unit Test with QUnit

    现在我们在应用程序中有了一个测试文件夹,我们可以开始增加我们的测试覆盖率. 实际上,到目前为止我们添加到应用程序中的每个特性都需要单独的测试用例.到目前为止,我们完全忽略了这一点,所以让我们为步骤23 ...

  10. Mysql 知识(1)

    1. 请简洁地描述下MySQL中InnoDB支持的四种事务隔离级别名称,以及逐级之间的区别? 答: SQL标准定义的四个隔离级别为:read uncommited,read committed,rep ...