html - 将箭头选择器添加到按钮中心

标签 html css

我试图通过 CSS 向链接按钮的底部添加一个白色箭头。但是,我无法将所有按钮的箭头统一居中。

JSFIDDLE

HTML:

<div class="help-buttons">
    <a href="#" class="help-button">User Information</a>
    <a href="#" class="help-button">Company Information</a>
    <a href="#" class="help-button">Driver Information</a>
</div>

CSS:

.help-buttons {
  margin: 75px auto;
  text-align: center;
}
.help-button {
  background: #1795db;
  color: #fff;
  padding: 15px 20px;
  font-family: 'Open sans';
  box-shadow: 3px 3px 0px 0px rgba(0,0,0,0.2);
  margin: 0 30px;
}
.help-button:after {
  content: "";
  position: absolute;
  margin-top: 25px;
  margin-left: -75px;
  width: 0;
  height: 0;
  border-left: 13px solid transparent;
  border-right: 13px solid transparent;
  border-bottom: 13px solid #ffffff;
}

最佳答案

  1. 制作 .help-button position: relative; 以便箭头相对于按钮定位。

  2. :after 上的负边距应与边框大小相同。

  3. 调整 bottom: -6px 以获得您想要的大小。

Have a fiddle!

HTML

<div class="help-buttons">
        <a href="#" class="help-button">User Information</a>
        <a href="#" class="help-button">Company Information</a>
        <a href="#" class="help-button">Driver Information</a>
    </div>

CSS

.help-buttons {
    margin: 75px auto;
    text-align: center;
}
.help-button {
    background: #1795db;
    color: #fff;
    padding: 15px 20px;
    font-family: 'Open sans';
    box-shadow: 3px 3px 0px 0px rgba(0,0,0,0.2);
    margin: 0 30px;
    position: relative;
}
.help-button:after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: -6px;
    margin-left: -13px;
    width: 0;
    height: 0;
    border-left: 13px solid transparent;
    border-right: 13px solid transparent;
    border-bottom: 13px solid #ffffff;
}

关于html - 将箭头选择器添加到按钮中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25252177/

相关文章:

html - 我无法填写代码中的空白

javascript - D3.js 在两条路径之间添加截取点和区域

javascript - 我怎样才能使用纯 Javascript 而不使用插件来简单地卡住表格的第一行?

html - 如何在页面调整大小时保持 div 居中?

css - :hover not working on svg when svg is in external file

html - 使用 CSS 均匀分布高度

html - 在新的 div 上淡化颜色

javascript - 宽度改变功能后宽度不跨越整个 parent 的宽度

javascript - 使用按钮将时间插入字段

javascript - javascript 和@media 相互干扰吗?