html - 删除 HTML、CSS 中按钮之间的空格

标签 html css button hover

我想删除按钮之间的空格,这样当我将鼠标悬停在 NORMAL 按钮上时,它和 HARD 按钮之间就没有空格了。我该怎么做,这些空白是从哪里来的?

body {
  margin: 0;
}
#stripe {
    background-color: white;
    text-align: center;
    height: 50px;
    color: black;
}

button {
    border: none;
    background: none;
    text-transform: uppercase;
    height: 100%;
    font-weight: 700;
    color: black;
    letter-spacing: 1px;
    font-size: inherit;
    transition: all 0.3s;
    outline: none;
}

button:hover {
    color: white;
    background: black;
}

.selected {
    color: white;
    background: black;
}
<div id="stripe">
    <button class="mode">Easy</button>
    <button class="mode">Normal</button>
    <button class="mode selected">Hard</button>
</div>

最佳答案

浏览器总是在一些元素之间添加空格,包括按钮。要删除它们,您需要将其父容器的字体大小设置为零。然后,要恢复按钮内的文本大小,请为它们设置字体大小。

#stripe {
  font-size: 0;
}

button {
  font-size: 14px; // Set font size that you need here
}

关于html - 删除 HTML、CSS 中按钮之间的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43431856/

相关文章:

android - 选择标签在原生 Android 浏览器上的样式不正确

html - 粘性页脚无法与 jquery 动画菜单一起正常工作

android - 更改按钮图像onClick android

Python:如何让按钮在按下时卡住? - Tkinter

html - 匹配不包含特定值的 HTML 表行 ( <tr> ) 的正则表达式

html - 将文字放在图像上

php - 如何使弹出式目录类似于 CodeIgniter 用户指南中的目录?

javascript - 使 div 可点击,仅当 div 中存在 anchor 时(多个 div)

c# - 在 asp.net 视频上创建控件时出错

android - 如何禁用按钮点击?