如何清除html按钮中的黑色破折号?

Jee*_*ama 4 html css

我不知道如何描述我的问题,但看看我的输出你就会明白。我用谷歌搜索了我的问题,但找不到解决方案。 输出图像

.btn1 {
  font-family: 'Times New Roman', Times, serif;
  margin-right: 0px;
  width: 100px;
  height: 30px;
  font-size: 17px;
  font-weight: 200;
  background-color: #f7e7e7;
  color: rgb(49, 126, 126);
  border-radius: 5px;
  border: 1px solid rgb(186, 230, 173);
  box-shadow: 3px 3px rgb(98, 151, 98);
}
Run Code Online (Sandbox Code Playgroud)
<div>
  <a href="#">
    <button class="btn1">Home</button>
  </a>
  <a href="product.html">
    <button class="btn2">Products</button>
  </a>
  <a href="#">
    <button class="btn3">Buy Now</button>
  </a>
  <a href="findus.html">
    <button class="btn4">Find us</button>
  </a>
</div>
Run Code Online (Sandbox Code Playgroud)

每个按钮在 CSS 中都有相同的代码。你能告诉我,我做错了什么吗?谢谢你。

ksa*_*sav 8

您不必要地将每个<button>s包装在一个<a>标签中,这是<a>您可以看到的标签的浏览器默认下划线样式。

注意:其他一些答案建议简单地隐藏下划线,但将 a 包裹<button>在 an 中<a> 被认为是应该避免的反模式。

链接

.btn1 {
  font-family: 'Times New Roman', Times, serif;
  margin-right: 0px;
  width: 100px;
  height: 30px;
  font-size: 17px;
  font-weight: 200;
  background-color: #f7e7e7;
  color: rgb(49, 126, 126);
  border-radius: 5px;
  border: 1px solid rgb(186, 230, 173);
  box-shadow: 3px 3px rgb(98, 151, 98);
  text-decoration: none;
}
Run Code Online (Sandbox Code Playgroud)
<div>
  <a class="btn1" href="#">Home</a>
  <a class="btn1" href="product.html">Products</a>
  <a class="btn1" href="#">Buy Now</a>
  <a class="btn1" href="findus.html">Find us</a>
</div>
Run Code Online (Sandbox Code Playgroud)

纽扣

.btn1 {
  font-family: 'Times New Roman', Times, serif;
  margin-right: 0px;
  width: 100px;
  height: 30px;
  font-size: 17px;
  font-weight: 200;
  background-color: #f7e7e7;
  color: rgb(49, 126, 126);
  border-radius: 5px;
  border: 1px solid rgb(186, 230, 173);
  box-shadow: 3px 3px rgb(98, 151, 98);
}
Run Code Online (Sandbox Code Playgroud)
<div>
  <button class="btn1">Home</button>
  <button class="btn2">Products</button>
  <button class="btn3">Buy Now</button>
  <button class="btn4">Find us</button>
</div>
Run Code Online (Sandbox Code Playgroud)

您可以阅读有关链接与按钮的信息,以及为什么您可能会在此处选择其中之一。


Rob*_*per 5

您看到的破折号实际上是锚元素附带的默认下划线。您需要添加的是:

a {
  text-decoration: none;
}
Run Code Online (Sandbox Code Playgroud)

也就是说,在锚元素内嵌套按钮元素是无效的 HTML,应该避免。