我在容器中有一些按钮。我希望它们的事件状态向下偏移 1px 左右。与其为每个按钮编写 css,我宁愿对它们进行分类并使它们的事件状态相对于它们的原始位置。
当前的 css 如下所示。或查看 this working fiddle .问题是底部 2x 按钮的事件状态偏移量似乎大于 1px。不知道我错过了什么。
#buttons {
position: absolute;
top: 10px;
left: 10px;
}
.greenButtClass {
font-family: 'avenirMedium';
position: absolute;
z-index: 10;
color: #ffffff;
font-size: 22pt;
width: 200px;
background-color: #7ac144;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
border-radius: 35px;
padding: 8px;
cursor: pointer;
border: 1px solid #7ac144;
}
.greenButtClass:hover {
background-color: #6DA840;
}
.greenButtClass:active {
position: relative;
top: 1px;
}
最佳答案
如果我理解你的问题,我的建议是:
html:
<div id='buttons'>
<br>
<button id='places' class='greenButtClass' style="top:15px">Button 1</button><br>
<button id='nature' class='greenButtClass' style="top:105px">Button 2</button><br>
<button id='trails' class='greenButtClass' style="top:205px">Button 3</button>
</div>
CSS:
#buttons{
position: absolute;
top:10px;
left:10px
}
.greenButtClass{
font-family: 'avenirMedium';
z-index: 10;
color: #ffffff;
font-size: 22pt;
width:200px;
background-color:#7ac144;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
border-radius:35px;
padding:8px;
cursor:pointer;
border:1px solid #7ac144;
}
.greenButtClass:hover {
background-color:#6DA840;
}
.greenButtClass:active {
position:relative;
top:1px;
}
还有一个工作 fiddle
另一个按钮之间有更多空格的示例:
关于html - 通过类偏移按钮事件状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23744502/