gpt4 book ai didi

css - 我怎样才能在这里给我正确的 div margin top 属性?

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

嗨,

我想要带有红色背景的右侧 div 一些 margin top 属性,但在蓝色框中仍然保持不变。我怎样才能做到这一点?如果我现在给 div 顶部边距,它会移动整个蓝色 div。

<div id="wrapper" style="width: 100%;height: 100px; background-color: blue">
<div id="left" style="background-color: green; height: 50px; width: 50px; display: inline-block; float: left">
left
</div>
<div id="right" style="background-color: red; height: 50px; width: 50px; margin-left: 50px;">
right
</div>
</div>

最佳答案

只需在红色 div 中添加 float: left; 并删除 margin-left

<div id="wrapper" style="width: 100%;height: 100px; background-color: blue">
<div id="left" style="background-color: green; height: 50px; width: 50px; display: inline-block; float: left">
left
</div>
<div id="right" style="background-color: red; height: 50px; width: 50px; float: left; margin-top: 10px;">
right
</div>
</div>

关于css - 我怎样才能在这里给我正确的 div margin top 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47694347/

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