CSS外框高度自动适应
当有浮动float时,最外框会不跟随内容的高度而高;
解决办法一:
清除浮动 clear:both
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
*{margin:0px;padding:0px;}
.wrap{background:red;width:1000px;margin:auto;}
.left,.right{float:left;height:50px;}
.left{width:960px;background:red;}
.right{width:40px;background:green;}
.clear{clear:both;}
</style>
</head>
<body>
<div class="wrap">
<div class="left"></div>
<div class="right"></div>
<div class="clear"></div>
</div>
</body>
</html>
解决办法二:
给最外框加 overflow:hidden; zoom:1;
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
*{margin:0px;padding:0px;}
.wrap{background:red;width:1000px;margin:auto;overflow:hidden; zoom:1;}
.left,.right{float:left;height:50px;}
.left{width:960px;background:red;}
.right{width:40px;background:green;}
</style>
</head>
<body>
<div class="wrap">
<div class="left"></div>
<div class="right"></div>
</div>
</body>
</html>
解决办法三:
给外框加属性 content: "";display: table;line-height: 0;clear: both;
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
*{margin:0px;padding:0px;}
.wrap:before, .wrap:after {content: "";display: table;line-height: 0;clear: both;}
.wrap:after {clear: both;}
.wrap {margin: 0 auto;width: 1000px;}
.left,.right{float:left;height:50px;}
.left{width:960px;background:red;}
.right{width:40px;background:green;}
</style>
</head>
<body>
<div class="wrap">
<div class="left"></div>
<div class="right"></div>
</div>
</body>
</html>
CSS最小高度与自适应高度并存
div{_height:200px; min-height:200px
/* 注释:两个放置不分前后顺序,兼容所有浏览器 */}

CSS外框高度自动适应的更多相关文章
- 纯CSS实现侧边栏/分栏高度自动相等
by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=694 一.为何要分栏高 ...
- 纯CSS兑现侧边栏/分栏高度自动相等(转)
这里直接介绍我认为的最佳的侧边栏/分栏高度自动相等方法.核心的CSS代码如下(数值不固定): margin-bottom:-3000px; padding-bottom:3000px; 再配合父标签的 ...
- 右边根据左边的高度自动居中只需要两行CSS就可以完成
右边根据左边的高度自动居中只需要两行CSS就可以完成 <style type="text/css" > div{ display: inline-block; vert ...
- textarea宽度、高度自动适应处理方法
textarea自动高度 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http: ...
- textarea 实现高度自动增长
有时候希望textarea 能够自动调整高度来适应输入的内容 网上看到了很多解决方案,比如动态创建一个隐藏的div,当用户输入的时候将textarea的内容绑定到div,由于div的高度会自动撑开,因 ...
- css修改input自动提示的黄色背景
css修改input自动提示的黄色背景 input:-webkit-autofill { background-color: #FAFFBD; background-image: none; -web ...
- css文字超出自动显示省略号
只针对单行文本有效: 01.针对块状元素 ul li{ width: 180px; text-overflow: ellipsis; white-space: nowrap;/*禁止自动换行*/ ov ...
- css+js实现自动伸缩导航栏
用css+js实现自动伸缩导航栏 需要达到的效果: 默认首页选中样式 设置鼠标滑过效果:颜色变化(#f60),宽度变化,字体变化 所涉及的知识点: 布局:float css: 元素状态切换(displ ...
- css 分栏高度自动相等
方法2: <div class="ticket_table"> <div class="ticket_l"> <h3>全票& ...
随机推荐
- iOS 7.1 系统可以设置 button shapes,此功能可让按钮多一条下滑线
IniOS 7, Apple completely revamped the user interface to give it a fresh and modern look. One of the ...
- com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed. 解决
ERROR - No operations allowed after connection closed. 2011-12-07 11:36:09 - ERROR - query failed or ...
- JQuery攻略(三)数组与字符串
在上两章,JQuery攻略(一) 基础知识——选择器 与 DOM 和 JQuery攻略(二) Jquery手册 我们为后面的章节打好了基础,在这一章节中,我们继续. 在这一章节中,我们记录的是JQue ...
- 【转】解决Android因加载多个大图引起的OutOfMemoryError,内存溢出的问题
本文来自:http://blog.csdn.net/wulianghuan/article/details/11548373,感谢原作者的分享. 目标是读取SD卡中的图片并且展示出来 主要思路是通过一 ...
- 在 JDK 9 中更简洁使用 try-with-resources 语句
本文详细介绍了自 JDK 7 引入的 try-with-resources 语句的原理和用法,以及介绍了 JDK 9 对 try-with-resources 的改进,使得用户可以更加方便.简洁的使用 ...
- caffe中的学习率的衰减机制
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/Julialove102123/article/details/79200158 根据 caffe/ ...
- Keras教程
In this step-by-step Keras tutorial, you’ll learn how to build a convolutional neural network in Pyt ...
- vim去除行显示;vim全部复制命令
行显示和隐藏: set nu set nu! 直接上命令: ggVG*y 解释一下上面的命令: ggVG ——全选 *y —— 复制到剪贴板 gg 是光标定位到文件首行 V 是进入可视模式 G ...
- POJ 1451 T9 (字典树好题)
背景:为了方便九宫格手机用户发短信,希望在用户按键时,根据提供的字典(给出字符串和频数),给出各个阶段最有可能要打的单词. 题意: 首先给出的是字典,每个单词有一个出现频率.然后给出的是询问,每个询问 ...
- Linux下的串口编程实例
//串口相关的头文件 #include<stdio.h> /*标准输入输出定义*/ #include<stdlib.h> /*标准函数库定义*/ #in ...