css - 如何修复影响整行按钮的边距
问题描述
我有几排按钮。我正在努力做到这一点,如果我按下一个按钮,它将获得 5px 的边距,所以它看起来就像被点击了一样。这样做整排按钮也获得了边距,这非常烦人。我该如何解决?
button {
font-size: 65px;
font-weight: 800;
text-shadow: 2px 2px 10px black;
width: 80px;
height: 80px;
border-radius: 20px;
margin-top: 7.5px;
margin-bottom: 7.5px;
margin-left: 7.5px;
margin-right: 7.5px;
background-color: rgb(36, 36, 36);
color: white;
border: 0;
cursor: pointer;
box-shadow: 0px 5px black;
}
button:active {
margin-top: 12.5px;
box-shadow: 0px 0px;
}
<button onclick="addText(7)" id="num7">7</button>
<button onclick="addText(8)" id="num8">8</button>
<button onclick="addText(9)" id="num9">9</button>
解决方案
为按钮提供 top 的垂直对齐属性,而不是默认的基线:
button {
font-size: 65px;
font-weight: 800;
text-shadow: 2px 2px 10px black;
width: 80px;
height: 80px;
border-radius: 20px;
margin-top: 7.5px;
margin-bottom: 7.5px;
margin-left: 7.5px;
margin-right: 7.5px;
background-color: rgb(36, 36, 36);
color: white;
border: 0;
cursor: pointer;
box-shadow: 0px 5px black;
vertical-align: top;
}
button:active {
margin-top: 12.5px;
box-shadow: 0px 0px;
}
<button id="num7">7</button>
<button id="num8">8</button>
<button id="num9">9</button>
推荐阅读
- python - python中多线程读写json文件的并发性
- codeigniter - 在 codeignter 模型中从两列到两个日期中选择
- php - 如何将大量 HTML 表单的表值发布到 PHP 数组?
- c++ - 如何计算和存储向量中目录中的文件
- python - KeyError: ((1, 1, 1280), '|u1') while using PIL's Image.fromarray - PIL
- protocol-buffers - 如何在 ProtoBuf (gRPC) - Proto3 语法中添加消息类型作为对象?
- typescript - 输入'HTMLCollectionOf
' 必须有一个返回迭代器的 '[Symbol.iterator]()' 方法 - spring - 从所有其他微服务获取当前经过身份验证的用户
- sql - 查询中的多个 Drop table 语句失败
- google-apps-script - 活动工作表中的 getUi