html - 具有相同样式的链接和按钮

标签 html css

我对链接和按钮使用相同的样式。但他们看起来不同。我怎样才能得到相同的外观?

<button class="button blue">Hello</button>
<br /><br />
<a class="button blue" href"#">Hello</a>



body {
    background-color: #ccc;
    font-family: Arial;
    font-size: 12px;
    color: #747476;
    margin: 0 0 15px 0;
    height: 100%;
    width: 100%;
}

button, a.button {
    width: auto;
    min-width: 110px;
    height: 30px;
    line-height: 30px;
    padding: 10px;
    border: 0 none;
    font-weight: bold;
    text-align: center;
    cursor: pointer;
    text-decoration: none;
    font-family: Tahoma;
}

button.button, a.button {
    color: #fff !important;
}

button.button.blue, a.button.blue {
    background-color: #2bb0df;
}

button.button.orange, a.button.orange {
    background-color: #e95d0f;
}

JsFiddle

最佳答案

只需将以下两行添加到您的 button, a.button 的 css 代码中:

box-sizing: content-box; 显示:内联 block ;

大功告成。

body {
  background-color: #ccc;
  font-family: Arial;
  font-size: 12px;
  color: #747476;
  margin: 0 0 15px 0;
  height: 100%;
  width: 100%;
}
button,
a.button {
  width: auto;
  min-width: 110px;
  height: 30px;
  line-height: 30px;
  padding: 10px;
  border: 0 none;
  font-weight: bold;
  text-align: center;
  cursor: pointer;
  text-decoration: none;
  font-family: Tahoma;
  display: inline-block;
  box-sizing: content-box;
}
button.button,
a.button {
  color: #fff !important;
}
button.button.blue,
a.button.blue {
  background-color: #2bb0df;
}
button.button.orange,
a.button.orange {
  background-color: #e95d0f;
}
<button class="button blue">Hello</button>
<br />
<br />
<a class="button blue" href "#">Hello</a>

关于html - 具有相同样式的链接和按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28072870/

相关文章:

html - 如何为表格制作 Angular 边框。

html - 如何实现多行 flexbox?

jquery - 使用 jQuery 获取 DIV 中最后一个 DIV 的 ID

html - 如何让父div适应 child 的大小

html - 边距不会应用于页脚

javascript - 如何将长文本保持在一行而不将其扩展到 css 中的超过 1 行

javascript - 如何通过 grunt & jasmine 设置 PhantomJS 的视口(viewport)大小?

jquery - 连续悬停在多个元素上

html - background-image: url() 当所有文件都在桌面上但不包含其文件夹中的文件时有效

html - 用于在另一个节点之后获取节点的 XPath 语法?