【发布时间】:2020-09-08 09:14:15
【问题描述】:
我试图将箭头放在两个 div 中间的顶部,如下图所示:link。
下面的代码不起作用,我正在尝试使其与 position : absolute ; 一起使用,但我不知道如何。
.section1 {
background-color: lightgray;
text-align: center;
padding: 100px;
}
.content {
display: inline-block;
}
.section1 .separator {
margin: 0 auto;
position: absolute; /* XXX this does something weird */
bottom: 0;
}
.section2 {
height: 200px;
background-color: coral;
}
<div class="section1">
<div class="content">
Hello, world!
</div>
<div class="separator">
▼
</div>
</div>
<div class="section2">
<div class="content">
Hello, world!
</div>
</div>
【问题讨论】:
-
我会考虑使用绝对定位将其与容器底部对齐,然后使用 CSS transform: translate 将其向下移动 50% 的高度。