gpt4 book ai didi

html - 在 div 中居中三 Angular 形

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

我试图在我的 div 中居中放置一个黑色的右向三 Angular 形,但没有成功。三 Angular 形应该用作按钮。我希望三 Angular 形在盒子内部看起来像这样:

triangle inside box

目前,我的三 Angular 形位于框的最左侧。我如何修复它以使其垂直和水平居中?

我的代码:

.arrow-right {
width: 0;
height: 0;
border-style: solid;
border-width: 10px 0 10px 17.3px;
border-color: transparent transparent transparent black;
background-color: #ffcd11;
}
<div class="arrow">
<button class = "arrow-right"></button>
</div>

最佳答案

一个解决方案是(如果您已经在容器中放置了箭头)。使用绝对/相对位置。并将其定位在父元素的中间。

.arrow-right {
width: 0;
height: 0;
border-style: solid;
border-width: 10px 0 10px 17.3px;
border-color: transparent transparent transparent black;
background: yellow;
position:absolute;
top: calc(50% - 10px);
left: calc(50% - 8.65px);
}
.arrow {
width:200px;
height: 100px;
background: yellow;
position:relative;
}
<div class="arrow">
<button class = "arrow-right"></button>
</div>

关于html - 在 div 中居中三 Angular 形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55302869/

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