gpt4 book ai didi

html - 带有按钮和空内容的 CSS 布局错误

转载 作者:太空宇宙 更新时间:2023-11-04 11:20:12 24 4
gpt4 key购买 nike

我在 IE11、Chrome、Firefox 中遇到了以下代码片段的布局错误 - 第二个按钮没有正确地与第一个按钮内联。

一旦我将任何非空白内容添加到第二个按钮的内部跨度,问题就会消失。

是否有一个 CSS 修复程序可以在不需要实际内容的情况下使按钮内联,理想情况下无需更改其余 CSS?

<!DOCTYPE html>
<html>
<head>
<title>CSS Problem</title>
<meta charset="utf-8"/>
<style>
.mainBorder { padding: 20px; background-color: #254669 }

button {
font-family: Verdana;
font-size: 13px;
color: white;
position: relative;
padding: 0 8px 1px 8px;
height: 24px;
background-color: #254669;
border: 1px solid #53779D;
transition: all 150ms ease-out;
outline: none;
}

button:disabled {
opacity: 0.65;
}

button:enabled {
cursor: pointer;
}

button:hover:enabled {
background-color: #53779D;
}

button:active:enabled > span.content {
display: inline-block;
transform: translateY(-1px);
}

button:focus {
border-color: white;
}

button.iconButton {
width: 24px;
padding: 0;
}

span.icon {
display: block;
height: 16px;
}
</style>
</head>
<body>
<h1>Button</h1>
<div class="mainBorder">
<button><span class="content">Default</span></button>&nbsp;&nbsp;&nbsp;
<button class="iconButton"><span class="icon"></span></button>&nbsp;&nbsp;&nbsp;
</div>
</body>
</html>

最佳答案

只需将 vertical-align:middle 添加到按钮类中,如下所示: Demo

button {
font-family: Verdana;
font-size: 13px;
color: white;
position: relative;
padding: 0 8px 1px 8px;
height: 24px;
background-color: #254669;
border: 1px solid #53779D;
transition: all 150ms ease-out;
outline: none;
vertical-align:middle; /* added this */
}

关于html - 带有按钮和空内容的 CSS 布局错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32857730/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com