gpt4 book ai didi

css - 带有 float 元素的背景色

转载 作者:太空宇宙 更新时间:2023-11-04 04:24:52 26 4
gpt4 key购买 nike

我想在主 DIV 中放置 2 个垂直 DIV 时遇到问题。 background-color 值不适用于主 DIV。我想我必须看到一些红色背景的部分。
请看一下它的jsFiddle并帮助我解决它。

最佳答案

尝试使用 clear:both CSS 属性添加一个空的 div,或者为你的主 div 设置一个高度。

<div id="content">
<div id="float-left">Some Text floating left</div>
<div id="float-right">Some Text floating right</div>
<div id="clear"></div>
</div>

CSS 代码

#content {
background-color:red; /* The background you want */
width:500px; /* Demo: not important */
}

#float-right {
float:right;
width:300px;
padding-right:20px;
line-height:200%;
background-color:#f2f2f2
}

#float-left {
float:left;
width:50px;
background-color:#e1e1e1
}

#clear{
clear:both
}

See Demo

关于css - 带有 float 元素的背景色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18460213/

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