html - 样式输入和跨度作为按钮类,略有不同

标签 html css

我想让我网站上的所有按钮都遵循一个平面按钮类,输入按钮或跨度按钮应该完全相同。

我应用了相同的类,删除了边框,添加了填充等。但是,使用该元素的按钮看起来比使用表单按钮的按钮稍大。

这是为什么呢?我还可以编辑哪些其他 css 属性以使它们看起来相同(除了为所有这些设置预设高度之外?)

这是我的按钮类:

.button{
    padding: 10px;
    display: inline;
    border-radius: 2px;
    font-family: "Arial";
    border: 0;
    margin: 0 10px;
    background: red;
    font-size: 15px;    
    line-height: 15px;
    color: white;
    width: auto;
    height: auto;
    box-sizing: content-box;
}

这是 fiddle :http://jsfiddle.net/raphadko/f3293yeL/

最佳答案

最佳解决方案是将按钮包裹在 span 内。这样,您就可以完全控制按钮的位置。不要将它们用作表单内的按钮!

span > .button {
    padding: 10px;
    display: inline;
    border-radius: 2px;
    font-family: "Arial";
    border: 0;
    margin: 0 10px;
    background: red;
    font-size: 15px;
    line-height: 15px;
    color: white;
    width: auto;
    height: auto;
    box-sizing: content-box;
}
<form>
   <span>
       <input type="submit" class="button" value="Button1" />
        </span>
  
  <span>
       <input type="submit" class="button" value="Button2" />
        </span>
  
  <span>
       <input type="submit" class="button" value="Button3" />
        </span>
    
</form>

注意: span 可以帮助您轻松定位元素,但不建议在涉及表单时将其用作按钮。

关于html - 样式输入和跨度作为按钮类,略有不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27570581/

相关文章:

php - 如何让我的 CSS 链接到不同目录中的文件

html - 如何使我的页面标题响应 CSS?

html - 在 div 上显示 md-dialog,而不是在整个 body 上

jquery - 单击主菜单 li>a 一次仅打开一个子菜单

html - 使div不可见并在单击链接后使其可见

html - 如何在 Bootstrap 5 中留下填充?

html - 垂直对齐 html 引导行中的文本

html - 高度100%误差

android - 尝试在 css 中绘制图像

html - 无法解释的 CSS float 和位置堆叠 :relative