gpt4 book ai didi

html - 在窗口调整大小时移动 div

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

我想将 divA 重新定位到 divB 下方,但我就是做不到。我试过使用 float,它似乎是解决这个问题的方法,但它仍然不起作用。

这是我的 CSS 代码:

.tweet-box{
position:fixed;
top: 140px;
left: 75px;
float: left;
width:100%;
}

HTML:

<div id="logo"></div>    
<div id="div1">
Some content
</div>
<div id="div2">
Some content
</div>

例子:

eg

最佳答案

您必须将 #div1#div2 包装在一个共同的父级中,使用 display:flex 并在设备下方指定不同的顺序您选择的宽度(下例中的 768px):

.reorder-wrapper {
display: flex;
}
#div1, #div2 {
border: 2px solid red;
flex-grow: 1;
margin: 5px;
padding: 5px;
}
#logo {
text-align: center;
}

#div2 {
order: -1;
}
@media (max-width: 768px) {
.reorder-wrapper {
flex-direction: column;
}
#div2 {
order: 1;
}
}
<div id="logo">This is logo</div>
<div class="reorder-wrapper">
<div id="div1">
Some content: #div1
</div>
<div id="div2">
Some content: #div2
</div>
</div>

注意:这不是唯一的方法,根据您的需要,另一种技术可能会更好。您需要使用 Minimal, Complete and Verifiable example 更新您的问题如果您无法将上述原则应用到您的案例中。

关于html - 在窗口调整大小时移动 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48854211/

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