我正在尝试通过CSS将白色箭头添加到链接按钮的底部。但是,我无法统一所有按钮的箭头中心..
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;
}
答案 0 :(得分:3)
制作.help-button
position: relative;
,以便箭头相对于按钮定位。
:after
上的负边距应与边框的尺寸相同。
调整bottom: -6px
以获得所需的尺寸。
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;
}
答案 1 :(得分:2)
这就是你追求的吗? http://jsfiddle.net/6ysbwrx8/4/
诀窍在于将left
位置设为50%
,将margin-left
设为负值,将箭头的宽度减半(以补偿“过冲”#39;) 。另请注意,我添加了position: rekative;
以使绝对定位正常工作。
这是完整的CSS:
.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;
white-space: no-wrap;
}
.help-button:after {
content: "";
position: absolute;
bottom: 0;
left: 50%;
margin-left: -13px;
margin-bottom: -3px;
width: 0;
height: 0;
border-left: 13px solid transparent;
border-right: 13px solid transparent;
border-bottom: 13px solid #ffffff;
}
(我还添加了white-space: no-wrap;
以防止您的按钮分成多行)