【问题标题】:How to link button? [duplicate]如何链接按钮? [复制]
【发布时间】:2017-11-03 07:52:57
【问题描述】:

这里的问题很简单,如果是愚蠢的,请见谅。

我这里有代码 - 但是按钮没有链接到任何地方,有人可以帮忙吗?

<div class="buttonwrapper">
  <button class="mdl-button mdl-js-button mdl-js-ripple-effect">
          <a target="_blank" href="https://twitter.com/CSGOFlair">Twitter</a>
        </button>
</div>

【问题讨论】:

  • 为什么你认为&lt;button&gt; 中的&lt;a&gt; 有意义?
  • 不行,我只是试了一下,因为直接给按钮添加href和target属性不起作用。
  • 如果您需要链接到另一个页面,请使用&lt;a&gt; 元素。你不需要按钮。如果您希望它看起来像一个按钮,请使用 CSS。

标签: html material-design


【解决方案1】:

一个简单的 CSS 按钮,使用您的按钮 CSS 为 &lt;a&gt; 创建一个,使其成为按钮外观链接。

.buttonwrapper {
  margin-top: 100px;
}
.button-link {
  padding: 10px 15px;
  background: #4479BA;
  color: #FFF;
  -webkit-border-radius: 4px;
  -moz-border-radius: 4px;
  border-radius: 4px;
  border: solid 1px #20538D;
  text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.4);
  -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2);
  -moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2);
  -webkit-transition-duration: 0.2s;
  -moz-transition-duration: 0.2s;
  transition-duration: 0.2s;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  text-decoration: none;
}

.button-link:hover {
  background: #356094;
  border: solid 1px #2A4E77;
  text-decoration: none;
}

.button-link:active {
  -webkit-box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.6);
  -moz-box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.6);
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.6);
  background: #2E5481;
  border: solid 1px #203E5F;
}
<div class="buttonwrapper">
  <a target="" class="button-link" href="https://twitter.com/CSGOFlair">Twitter</a>
</div>

【讨论】:

    【解决方案2】:

    你做错了,但别担心。

    <div class="buttonwrapper">
     <a target="_blank" href="https://twitter.com/CSGOFlair">
     <button class="mdl-button mdl-js-button mdl-js-rippleeffect">Twitter Button</button>
    </a>
    
    </div>
    

    将按钮嵌套在 a 元素中并为其命名 更多关于锚元素的信息:htmldog

    【讨论】:

    • 你可以移除 .buttonwrapper 的 div 并给锚点一个 display:block
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-26
    • 1970-01-01
    • 2021-02-18
    • 2015-10-10
    • 2020-12-15
    • 2015-03-16
    • 1970-01-01
    相关资源
    最近更新 更多