zoukankan      html  css  js  c++  java
  • 关于float,clear

    苏昱的样式表中文手册中的示例


    我的ID是 idDiv2 。请选择我的 float 属性的值。
    我的ID是 idDiv1 。请从下方的第一个选择框内选择我的 clear 属性的值。从第二个选择框内选择 idDiv2float 属性的值。

    ---clear--- none left right both ---float--- none left right
    #idDiv1 { clear : none ; }
    #idDiv2 { float : none ; }

     
     
    苏昱作品·版权所有
    ?2002 Rainer Su . All rights reserved .

    使用float时出现的问题

    一个非常常见的CSS问题,定位使用浮动的时候,下面的层被浮动的层所覆盖,或者层里嵌套的子层超出了外层的范围。

    这是一个浮动在红框的层中的一个层
    style="border:1px solid green;float:left;color:green;"
    这是红框的层中的内容

    解决的方法

    陈旧的方法--使用clear:both

    通常的解决办法是在浮动层后面添加一个额外元素,例如一个div或者一个br,并且定义它的样式为clear: both。

    这是一个浮动在红框的层中的一个层
    style="border:1px solid green;float:left;color:green;"
    这是红框的层中的内容,红框层后面还嵌入了一个没有内容的层<div style="clear:both;"></div>

    通常的解决办法是在浮动层后面添加一个额外元素,例如一个div或者一个br,并且定义它的样式为clear: both。

    CSS的方法--使用:after

    这种方法在在文章《How To Clear Floats Without Structural Markup》中被提到。

    /*需要用到的CSS样式表的最初设想*/
    .clearfix:after {
    content: ".";
    display: block;
    height: 0;
    clear: both;
    visibility: hidden;
    }

    /*实际用到的CSS样式表(针对不同浏览器做了优化)*/
    .clearfix:after {
    content: ".";
    display: block;
    height: 0;
    clear:both;
    visibility: hidden;
    }
    .clearfix {display: inline-table;}
    /* Hides from IE-mac \*/ *
    html .clearfix {height: 1%;}
    .clearfix {display: block;}
    /* End hide from IE-mac */

    这是一个浮动在红框的层中的一个层
    style="border:1px solid green;float:left;color:green;"
    这是红框的层中的内容,对这个红框层应用了上面提到的CSS类.clearfix

    CSS的方法--使用overflow

    前面的2种方法可以很好解决浮动超出的问题,但是如果当你真的需要对层或者层里的对象进行clear的时候怎么办?一种简单的方法就是用overflow属性,这个方法最初的发表在《Simple Clearing of Floats》,又在《Clearance》和《 Super simple clearing floats》中被广泛讨论。

    /*需要用到的CSS样式表的最初设想(对IE不起作用)*/
    .clearfix2{overflow: auto}

    /*实际用到的CSS样式表(针对不同浏览器做了优化)*/
    .clearfix2{
    _height:1%; /*height前面的下划线是必须的*/
    overflow:auto;
    }

    这是一个浮动在红框的层中的一个层
    style="border:1px solid green;float:left;color:green;"
    这是红框的层中的内容,对这个红框层应用了上面提到的CSS类.clearfix2
  • 相关阅读:
    2019/5/15 写题总结
    CodeForces 804C Ice cream coloring
    CodeForces 367 C Sereja and the Arrangement of Numbers 欧拉回路
    CodeForces 464 B Restore Cube
    CodeForces 402 E Strictly Positive Matrix
    CodeForces 628 D Magic Numbers 数位DP
    CodeForces 340E Iahub and Permutations 错排dp
    CodeForces 780 E Underground Lab
    BZOJ 1010 [HNOI2008]玩具装箱toy 斜率优化dp
    CodeForces 715B Complete The Graph 特殊的dijkstra
  • 原文地址:https://www.cnblogs.com/zwl12549/p/889012.html
Copyright © 2011-2022 走看看