gpt4 book ai didi

html - 理解围绕 float div 的文本换行

转载 作者:行者123 更新时间:2023-11-28 02:25:05 25 4
gpt4 key购买 nike

我刚刚观看了这个视频以了解 float 在 CSS 中的工作原理

https://www.youtube.com/watch?v=xara4Z1b18I

以下是我的代码

index.html

  <head>
<link rel="stylesheet" href="./style.css"
</head>
<body>
<div class="wrapper">
<div class="box red"></div>
<div class="box yellow"></div>
<div class="box green"></div>
<p>This is a block element</p>
<p>This is another block element</p>
<p>And another</p>
<p>Yet another</p>
</div>
</body>
</html>

样式.css

  height: 100px;
width: 100px;
}

.red{
background-color: red;
float: left;
}


.yellow{
background-color: yellow;
float: left;

}


.green{
background-color: green;
float: left;


}

我得到的输出是这样的

1.

enter image description here

2.

enter image description here

3.

enter image description here

4.

enter image description here

我的疑问是:

在漂浮的红色上,正如预期的那样,黄色被隐藏了,绿色向上移动。在漂浮的黄色上,它移动到红色的右边,绿色被隐藏。但是在漂浮的绿色上,为什么文本会环绕绿色。它不应该隐藏在红色 div 后面吗?

最佳答案

文本以不同方式处理,并环绕 float 元素。

https://www.w3schools.com/css/css_float.asp

请看这个 fiddle 。一旦您添加文本,它就会与非文本元素区别对待。

https://jsfiddle.net/jennifergoncalves/bgsotpvk/20/

p {
display: block;
width: 200px;
height: 200px;
background: orange;
}

.box {
height: 200px;
width: 200px;
display: block;
}

.red {
background-color: red;
opacity: .5;
}

.yellow {
background-color: yellow;
opacity: .5;
}

.green {
background-color: green;
opacity: .5;
float: left;
}
<div class="wrapper">

<div class="box red"></div>
<div class="box yellow"></div>
<div class="box green"></div>


<p>This is a block element</p>
<p>This is another block element</p>
<p>And another</p>
<p>Yet another</p>
</div>

关于html - 理解围绕 float div 的文本换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54736125/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com