gpt4 book ai didi

css - 相对内的绝对定位 - 使用底部 : 0 doesn't seem to work

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

我正在尝试相对于包含的 div 的底部定位一个元素。对父元素使用 position: relative 然后对子元素使用 position: absolute 似乎按预期工作。 (我使用了 this article 作为引用。)

我的问题是当我改变时:

top: 0;

bottom: 0;

对于其中一个内部元素,它会跳转到包含的 div 的顶部。我希望它相对于灰色 block 的底部。

代码如下:

 .channeldiv {
margin: 0px;
position: relative;
display: inline-block;
}

.channel_summary {
position: absolute;
top: 0px;
right: 0px;
width: 50px;
height: 50px;
background-color: gray;
}

.channel_wrap {
position: relative;
}

.inner_pink {
position: absolute;
bottom: 0;
right: 0;
width: 100%;
height: 30px;
z-index: 3;
}

.inner_green {
position: absolute;
top: 0;
right: 0;
width: 100%;
height: 30px;
z-index: 3;
}

.big_background {
height: 73px;
width: 128px;
background-color: orange;
}

.overlaytext {
position: absolute;
top: 0px;
right: 0px;
width: 100%;
text-align: right;
z-index: 3;
background-color: black;
color: lightgreen;
font-family: monospace;
}

.trades_num {
position: absolute;
top: 0px;
left: 0px;
z-index: 3;
background-color: black;
color: lightgray;
}
<div class="channeldiv">
<div class="big_background">
<div class="channel_summary">
<div class="channel_wrap">
<svg class="inner_green" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect id="rect1" width="100%" height="100%" fill="green" />
</svg>
<span class="overlaytext">+1.00</span>
</div>
</div>
<span class="trades_num">1</span>
</div>
</div>

<div class="channeldiv">
<div class="big_background">
<div class="channel_summary">
<div class="channel_wrap">
<svg class="inner_pink" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect id="rect1" width="100%" height="100%" fill="pink" />
</svg>
<span class="overlaytext">+1.00</span>
</div>
</div>
<span class="trades_num">2</span>
</div>
</div>



这是 fiddle :https://jsfiddle.net/davemabe/h6cv7prs/

enter image description here

最佳答案

您不需要在 channel_wrap 类中设置 position: relative;,因为在这种情况下它会禁用其子定位。这样做之后,它就会如您所愿地工作。

您建议的文章只是彼此内部的两个定位(绝对相对),而您要尝试做的是三重定位(绝对相对相对)这不会导致您期望的结果.

事实上,如果你想像这样保持三倍,你至少需要给 channel_wrap div,例如一个高度,这样它的 child 就会知道如何对 parent 的定位使用react,只有这样他们才会知道他们应该底部到哪里。

关于 positioning 的更多信息和 bottom属性

关于css - 相对内的绝对定位 - 使用底部 : 0 doesn't seem to work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51338406/

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