gpt4 book ai didi

html - 使用 CSS,如何将元素锚定到基线并根据另一个 "pinned"元素调整其大小?

转载 作者:太空狗 更新时间:2023-10-29 13:30:58 25 4
gpt4 key购买 nike

这是我所指的图像:

enter image description here

如果你有一些固定高度 h 从 pin 所在的基线开始,并且绿色元素是动态调整大小的,你如何让橙色元素占据两者之间的空间?

最佳答案

在这种情况下,使用 flexbox 就可以满足您的需求。

大头针大致保持在基线上方 1 像素的相同高度。

它是如何工作的:当绿色元素增长时说 10px 引脚升高 5px。但是 flex 设置意味着 dummyorange 框各减少 5px 从而使图钉保持在恒定高度。

* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
}
.wrapper {
display: flex;
flex-direction: column;
align-items: center;
height: 100px;
border-bottom: 1px solid black;
}
.dummy {
flex: 1;
}
.top {
height: 20px;
width: 20px;
border: 1px solid green;
position: relative;
}
.top div {
position: absolute;
height: 3px;
width: 3px;
background: #880015;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.bottom {
width: 50px;
border: 1px solid orange;
flex: 1;
}
<div class="wrapper">
<div class="dummy"></div>
<div class="top">
<div></div>
</div>
<div class="bottom"></div>
</div>

关于html - 使用 CSS,如何将元素锚定到基线并根据另一个 "pinned"元素调整其大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39003866/

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