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

时间:2015-01-21 17:06:07

标签: 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

1 个答案:

答案 0 :(得分:1)

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

box-sizing: content-box; display: inline-block;

你已经完成了。

&#13;
&#13;
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;
}
&#13;
<button class="button blue">Hello</button>
<br />
<br />
<a class="button blue" href "#">Hello</a>
&#13;
&#13;
&#13;