html - 在 div 中居中三 Angular 形

标签 html css

我试图在我的 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/

相关文章:

php - 我在使用此 sql 查询 html/php 时遇到问题

css - 我应该添加 Invisible <h2 >'s to <sections>' s 吗?

html - 为简单的响应式 header 编写代码

javascript - 如何在php中设置li激活

css - Firefox 输入占位符和框大小

html - 如何将标题括起来的元素符号垂直居中

javascript - 如何使用 contenteditable 获取 div 元素内标记文本的父元素?

html - 固定侧边栏,可滚动内容

css - CSS 中的 HTML colspan

html - RTL 中的星级评定系统