【发布时间】:2021-04-14 08:28:15
【问题描述】:
我尝试显示这样的 html 元素: here
这是一个底部带有箭头的正方形,我使用这种样式创建了它:
.square {
min-width: 60px;
height: 60px;
margin-left: 5px;
display: flex;
justify-content: center;
align-items: center;
background-color: #1db911;
border-radius: 15px;
font-size: 14px;
color: #ffffff;
}
.square:after,
.square:before {
bottom: 30%;
left: 31%;
border: solid transparent;
content: ' ';
height: 0;
width: 0;
position: absolute;
pointer-events: none;
display: block;
}
.square:after {
border-color: rgba(238, 238, 238, 0);
border-top-color: #1db911;
border-width: 10px;
margin-left: -10px;
display: block;
}
.square:before {
border-color: rgba(204, 204, 204, 0);
border-top-color: #1db911;
border-width: 10px;
margin-left: -10px;
display: block;
}
但是有一个问题。当我水平滚动三角形时:
here
这是我的父元素:
here
可以水平滚动。
我也尝试将position: relative 用于square 类,但它存在问题。它没有在正方形上显示三角形。
像这样:
here(我将三角形涂成黑色以更好地显示)
这是我在这个州的风格
.square {
min-width: 60px;
height: 60px;
margin-left: 5px;
display: flex;
justify-content: center;
align-items: center;
background-color: #1db911;
border-radius: 15px;
font-size: 14px;
color: #ffffff;
position: relative;
}
.square:after,
.square:before {
bottom: -22%;
left: 50%;
border: solid transparent;
content: ' ';
height: 0;
width: 0;
position: absolute;
pointer-events: none;
display: block;
}
.square:after {
border-color: rgba(238, 238, 238, 0);
border-top-color: black;
border-width: 10px;
margin-left: -10px;
display: block;
}
.square:before {
border-color: rgba(204, 204, 204, 0);
border-top-color: #1db911;
border-width: 10px;
margin-left: -10px;
display: block;
}
<div class="square">
<span>sample</span>
</div>
谢谢!
【问题讨论】:
标签: html css css-selectors pseudo-element