gpt4 book ai didi

html - :after is not working as expected - CSS

转载 作者:行者123 更新时间:2023-11-28 17:05:58 26 4
gpt4 key购买 nike

下面是我想要的按钮

enter image description here

JSFIddle

HTML

<div>
<h5 style="margin: 0;position: relative;" class="right-arrow">LEARN MORE</h5>
</div>

CSS

div {
background-color: red;
border-radius: 10px;
padding: 0.5em;
float: left;
position: relative;
}

.right-arrow:after {
content: '';
content: '';
vertical-align: middle;
border: 20px solid transparent;
border-left-color: white;
border-width: 8px 20px;
position: absolute;
padding-left: 10px;
}

问题

不知道为什么右箭头要往外...

我不想要的可能解决方案

我不想要固定宽度的 div !!所以 float: left;div 中是需要的。欢迎使用其他解决方案。谢谢

最佳答案

像这样尝试:

div {
background-color: red;
border-radius: 10px;
padding: 0.5em 30px .5em .5em; /* added right padding */
float: left;
position: relative;
}

.right-arrow:after {
content: '';
content: '';
vertical-align: middle;
border: 20px solid transparent;
border-left-color: white;
border-width: 8px 15px;
position: absolute;
margin-left: 8px; /* newly added */
}

您需要像这样为背景 div 设置填充 demo

关于html - :after is not working as expected - CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30342245/

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