【问题标题】:Have the same height for a link, button and input链接、按钮和输入具有相同的高度
【发布时间】:2018-07-31 01:52:45
【问题描述】:

我希望我的按钮、链接和输入具有相同的样式。我的身高有问题,我无法确定原因。

在这个例子中,我的按钮和我的输入是 30 像素高,但我的链接只有 29 像素。

* {
  box-sizing: border-box;
}

html {
  font-size: 62.5%;
}

body {
  font-size: 2rem;
}

button, input, a {
  background: none;
  border: 1px solid grey;
  color: black;
  font-size: 1.6rem;
  outline: none;
  padding: 5px;
  text-decoration: none;
}
<button>Hello</button>
<input type="text" placeholder="Hello" />
<a href="#">Hello</a>

这有什么区别?

【问题讨论】:

    标签: css button input hyperlink


    【解决方案1】:

    您需要确保所有元素的字体系列都相同(当前您的锚具有不同的字体),并确保您的元素是块或内联块,否则不会应用填充:

    * {
      box-sizing: border-box;
    }
    
    html {
      font-size: 62.5%;
    }
    
    body {
      font-size: 2rem;
    }
    
    button,
    input,
    a {
      display: inline-block;
      font-family: arial;
      background: none;
      border: 1px solid grey;
      color: black;
      font-size: 1.6rem;
      outline: none;
      padding: 5px;
      text-decoration: none;
    }
    <button>Hello</button>
    <input type="text" placeholder="Hello" />
    <a href="#">Hello</a>

    【讨论】:

    • 非常感谢您的解释解决了我的问题。
    猜你喜欢
    • 2021-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-01
    • 2018-11-24
    • 2013-06-05
    相关资源
    最近更新 更多