CSS-之外围容器自适应高度

css|自适应

 今天我在给客户制作网页(设计是采用xhtml+css)的时候遇到了这个问题,就是给外围容器左右加border,在IE下可以正常显示,FF下有的页面正常,有的就没有,产生的原因是不能自适应高度。

问题:
<div id="main">
<div id="sideleft">left</div>
<div id-"sideright">right</div>
</div>#main容器在非IE下不能很好的适应left和right的高度!

我的解决方案是:

我原来的:#mainContent {width:760px; height:100%; margin:2px auto 0 auto;padding:0; background-color:#fff; border-right:#eee 1px solid; border-left:#eee 1px solid;}

第一步修改:
加上 min-height:auto; max-height:100%;两句,没效果

第二步修改:
加上
#mainContent:after {content: '[DO NOT LEAVE IT IS NOT REAL]'; display: block; height: 0;clear: both; visibility: hidden;}
#mainContent {display: inline-block;}
/*\*/
#mainContent {display: block;}

效果实现了,达到了我的要求,而且兼容IE,FF,OPERA

其实最简单的方法是这样的
<div id="main">
<div id="sideleft">left</div>
<div id-"sideright">right</div>
<div style="clear:both;"></div>
</div>
只要清除了浮动就可以让外围容器的背景延伸了

时间: 2024-09-15 22:01:53

CSS-之外围容器自适应高度的相关文章

css float父元素自适应高度无效解决办法

当几个并列div元素使用float属性时,由于父容器没有定义实际高度(height),在IE中显示出现问题,无法显示父容器的背景颜色或背景图片 做了如下设置实验情况:1. 不正常显示的设置 子容器:使用float 父容器:不定义height 2. 在测试中发现,父容器在不定义高度时,取消float属性,背景颜色显示正常 子容器:不使用float 父容器:不定义height 3. 而给父容器定义了高度后,子容器再使用float则一切正常 子容器:使用float 父容器:定义height 原因及解决

css float引起div自适应高度无效解决方法

 代码如下 复制代码 <style> #main{float:left;min-height:500px;} #l{float:left;margin-bottom:10px;margin-right:10px;padding:6px 10px;width:117px;} #r{float:right;margin-right:10px;padding-top:10px;width:864px;overflow:hidden;} </style>   <div id=&quo

文本域 textarea:CSS让Textarea文本域根据内容自适应高度fenge文本域

  <title>文本域自适应高度 - www.cxybl.com</title> <textarea style="width:300px;overflow-y:visible">在这里输入一些字符看一下,当超出初设的文本域高度时,文本域自动伸缩变高. 本文链接http://www.cxybl.com/html/wyzz/CSS/20130908/40081.html

Div即父容器不根据内容自适应高度的解决方法

解决|自适应 Div即父容器不根据内容自适应高度,我们看下面的代码: <div id="main"><div id="content"></div></div> 当Content内容多时,即使main设置了高度100%或auto.在不同浏览器下还是不能完好的自动伸展.内容的高度比较高了,但容器main的高度还是不能撑开. 我们可以通过三种方法来解决这个问题. 一,增加一个清除浮动,让父容器知道高度.请注意,清除浮动的容

div+css自适应高度

  <html> <head> <style type="text/css"> body {  background:#999;  text-align:center;  color:#333;  font-family:Arial, Verdana, Sans-serif; } #header {  width:776px;  margin-left:auto;  margin-right:auto;  padding:0px;  backgrou

css 自适应高度的两列页面布局实现方法

最大宽度的样式 通过将 "margin: 1em 5%" 修改为 "margin: 0" 可以很容易的切换到最大宽度的样式    代码如下 复制代码 #container { margin: 0; /* changed from 1em 5% */ background-color: #FFF; background-image: url(background.jpg); background-repeat: repeat-y; border: 1px solid

css子级用float浮动而父级div没高度不能自适应高度

解决子级对象使用css float浮动 而父级div不能自适应高度,不能被父级内容撑开解决方法,父级div没有高度解决方法. 当在对象内的盒子使用了float后,导致对象本身不能被撑开自适应高度,这个是由于浮动产生原因. 方法一:使用css clear清除浮动 1.加clear效果完整div css代码 对父级div标签闭合</div>前加一个clear清除浮动对象.  代码如下 复制代码 <!DOCTYPE html> <html> <head> <

css 高度自适应代码与自适应高度css兼容ie,firefox

<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>css 高度自适应代码与自适应高度css兼容ie,firefox</title> </head> <style t

Iframe实现跨浏览器自适应高度解决方法_jquery

本文以实例形式讲述了Iframe实现跨浏览器自适应高度解决方法,非常具有实用价值.分享给大家供大家参考之用.具体方法如下: 该方法使用了jQuery,因此需要在iframe的src页面里面引入jQuery. 父页面里面相对简单一点,主要包含以下代码: <iframe id="if1" scrolling="no" src="2.html"></iframe> 在iframe的src页面里面代码如下: <script