Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

<div id='html'>html</div>
<div id='content'>
<textarea id="text"></textarea>
</div>

为何无法清除浮动?

div#html{
    border:1px solid black;
    height:80px;
    width:80px;
    float:left;
 }
div#html::after{
    content:'';
    clear:both;
    display:block;        
 }
#content{
    width:900px;
    height:100px;
    border:2px solid red;
}
textarea{
    border:2px solid green;
    width:80%;
    height:80%;
}

显示成这样了

image.png

这是典型的清除浮动的方法

content:'';
clear:both;
display:block;

问题在哪里?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
326 views
Welcome To Ask or Share your Answers For Others

1 Answer

::after

是写在父级清除子元素的浮动

#content{
    clear:both;     
 }

image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...