zoukankan      html  css  js  c++  java
  • Div自适应高度的方法

    http://www.yutheme.cn/website/index.php/content/view/39/63.html
     

    div高度自适应是个比较麻烦的问题,在朋友artery那里看到这个文章,帮我解决了不少问题,摘录下来:

    Div即父容器不根据内容自适应高度,我们看下面的代码:

    <div id="main">
    <div id="content"></div>
    </div>
      当Content内容多时,即使main设置了高度100%或auto。在不同浏览器下还是不能完好的自动伸展。内容的高度比较高了,但容器main的高度还是不能撑开。

      我们可以通过三种方法来解决这个问题。 

    1增加一个清除浮动,让父容器知道高度。请注意,清除浮动的容器中有一个空格。
    <div id="main">
    <div id="content"></div>
    <div style="font: 0px/0px sans-serif;clear: both;display: block"> </div>
    </div>
      
    2增加一个容器,在代码中存在,但在视觉中不可见。
    <div id="main">
    <div id="content"></div>
    <div style="height:1px; margin-top:-1px;clear: both;overflow:hidden;"></div>
    </div>
       
    3增加一个BR并设置样式为clear:both。
    <div id="main">
    <div id="content"></div>
    <br style="clear:both;" />
    </div>

    补充:

    <div id="main">
    <div id="content">
      <p>demo1</p>
      <p>demo2</p>
      <p>demo3</p>
    </div>
    </div>
    #main { border:1px solid #999999; background-color:#CCCCCC; height:100%; overflow:hidden;}
    #content { float:left;}

    以上三个方法都不是最好的解决方法,因为在程序代码观念中是提倡尽量不要添加无意义的标签代码

    介绍我的解决方法是直接在最外层div加以下样式

    #main {
    height:100%;
    overflow:hidden;
    }      




  • 相关阅读:
    mysql索引及优化
    mysql5.5 uuid做主键与int做主键的性能实测
    php生成UUID
    Android 图片的裁剪与相机调用
    Android GPS 临近触发
    Android中GPS类及方法简介
    永久删除 tadb.exe
    linux服务器调整参数支持高并发
    隐藏nginx 版本号信息
    nginx 重写 rewrite 基础及实例
  • 原文地址:https://www.cnblogs.com/fumj/p/3284279.html
Copyright © 2011-2022 走看看