css - 相对内部的绝对定位 - 使用底部:0 似乎不起作用
问题描述
我正在尝试相对于包含 div 的底部定位项目。使用 position: relative 作为父元素,然后使用 position: absolute 作为子元素似乎可以按预期工作。(我用这篇文章作为参考。)
我的问题是当我改变时:
top: 0;
至
bottom: 0;
对于其中一个内部元素,它会跳转到包含 div 的顶部。我希望它相对于灰色块的底部。
这是代码:
.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>
解决方案
推荐阅读
- arrays - 传递包含数组的结构,为什么数组名的值会改变?
- object-detection - 如何在不使用 scikit-learn 的情况下绘制 ROC-AUC 图形
- dialogflow-es - Dialogflow:创建代理 - 无法创建代理。面对错误
- scala - Scala中等效的JavaScript括号表示法?
- c++ - 为什么 c++ 文件系统 directory_iterator 是 LegacyIterator?
- apache-kafka - 在 Mac 和 Raspi 上同样的错误:EADDRINUSE: address already in use 0.0.0.0:9092
- graphql - Graphgql参数传递错误'语法错误:意外$'对于整数?
- flutter - 如何先查询最新的文档?
- c# - 这个 PHP 片段是否等同于 C# 片段?
- python - 如何在 Pyspark 中进行 groupby 汇总统计?