gpt4 book ai didi

html - 使用 float 来模拟具有不同大小对象的表格布局时遇到问题

转载 作者:太空宇宙 更新时间:2023-11-04 05:14:10 25 4
gpt4 key购买 nike

我正在尝试使用 float 创建无表格布局,但我无法让小对象 float 在较大对象的两侧。这可能吗?

这是我正在尝试做的事情的视觉效果:

How can I get the blue boxes on box sides of the pink box?

更新:我希望能够随时随地在文档中添加新的蓝色方框和粉红色方框,而不必将自定义 float 应用于单个元素...

我已将实际代码保存在 JSFiddle 上:http://jsfiddle.net/TuZfm/

如果你更喜欢看原始代码,这里是:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<style type="text/css">
.wrapper {
width:100px;
margin:2em auto;
}
.box {
height:10px;
width:10px;
margin:5px;
float:left;
background-color:blue;
}
.box-medium {
height:30px;
width:30px;
margin:5px;
float:left;
background-color:pink;
}
</style>
</head>
<body>
<div class="wrapper">
<img class="box"/>
<img class="box"/>
<img class="box-medium"/>
<img class="box"/>
<img class="box"/>
<img class="box"/>
<img class="box"/>
<img class="box"/>
<img class="box"/>
<img class="box"/>
<img class="box"/>
<img class="box"/>
<img class="box"/>
<img class="box"/>
<img class="box"/>
<img class="box"/>
</div>
</body>
</html>

感谢您的帮助!

这是我尝试内联 block 时得到的结果:

inline-block

它几乎是完美的,除了粉红色框旁边的死 Angular ......我想要在粉红色框旁边有两排蓝色框。

这是我在尝试内联 block 时使用的代码:http://jsfiddle.net/QCAFM/

最佳答案

如果您希望能够动态添加新元素,您应该考虑使用 javascript 解决此问题。

这是一个很好的。 http://masonry.desandro.com/

关于html - 使用 float 来模拟具有不同大小对象的表格布局时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8592774/

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