gpt4 book ai didi

css - 将全宽 div 包裹在 float div 周围

转载 作者:行者123 更新时间:2023-11-28 11:16:39 24 4
gpt4 key购买 nike

我正在尝试使用 float div 做一些事情,我认为这是最简单的,但我似乎完全无法实现我想要的。我想要一个固定宽度的 float div,并让它周围的所有 div 尽可能地水平扩展而不与 float div 重叠。也就是说,在 float div 旁边,它们应该填满它旁边的可用空间,在 float div 下面,它们应该占据容器的整个宽度。

我已经尝试了所有我能想到的 positiondisplaywidthright 属性的组合的,但没有什么能给我我想要的。我认为我需要将 .fill div 设置为 display: inline-block; 然后用 width 管理它们的宽度或 right 属性,但我尝试的任何操作都无法提供可用宽度。

请注意,由于所有 div 的高度都是可变的,因此我无法事先知道哪些 div 将紧挨着 float div,因此我无法为 .fill div 设置明确的宽度。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html version="-//W3C//DTD XHTML 1.1//EN" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:s
chemaLocation="http://www.w3.org/1999/xhtml http://www.w3.org/MarkUp/SCHEMA/xhtml11.xsd">
<head>
<title>float test</title>
<style type="text/css">
html, body, div {
margin: 0;
border: 0;
padding: 0;
}
#container {
position: relative;
width: 100%;
overflow: hidden;
}
#right {
width: 20em;
height: 40em;
margin: 0 0 0 1em;
float: right;
background-color: #88f;
opacity: .5;
}
.fill {
height: 3em;
margin: 1em;
background-color: #f88;
opacity: .5;
}
</style>
</head>
<body>
<div id="container">
<div id="right"></div>
<div id="left">
<div class="fill"></div><div class="fill"></div><div class="fill"></div><div class="fill"></div>
<div class="fill"></div><div class="fill"></div><div class="fill"></div><div class="fill"></div>
<div class="fill"></div><div class="fill"></div><div class="fill"></div><div class="fill"></div>
<div class="fill"></div><div class="fill"></div><div class="fill"></div><div class="fill"></div>
</div>
</div>
</body>
</html>

最佳答案

overflow: hidden; 添加到 .fill

关于css - 将全宽 div 包裹在 float div 周围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5790340/

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