【问题标题】:span inside anchor not working, any ideas?跨度内锚不起作用,有什么想法吗?
【发布时间】:2017-11-25 06:27:57
【问题描述】:

我在这里编写一段代码,其中跨度嵌套在链接中,这适用于 Chrome,但不适用于 FF 或 IE,有什么想法吗?我也尝试过使用 span 的嵌套链接,但也没有工作。我知道锚点内有一些关于跨度的规则,但我目前的编码无法弄清楚。 非常感谢

.button {
  position: relative;
  display: inline-block;
  border-radius: 20px;
  border: 2px solid #ffcc00;
  background-color: #006534;
  color: #FFFFFF;
  text-align: center;
  font-size: 16px;
  padding: 9px;
  width: 230px;
  transition: all 0.5s;
  cursor: pointer;
  margin: 5px;
  top: -40px;
  left: -255px;
}

.button span {
  cursor: pointer;
  display: inline-block;
  position: relative;
  transition: 0.5s;
  color: #FFFFFF;
}

.button span:after {
  content: '»';
  position: absolute;
  opacity: 0;
  top: 0;
  right: -20px;
  transition: 0.5s;
  color: #FFFFFF;
}

.button:hover span {
  padding-right: 25px;
  color: #FFFFFF;
}

.button:hover span:after {
  opacity: 1;
  right: 0;
  color: #FFFFFF;
}
<div>
  <button class="button" style="vertical-align: middle;">
    <a href="link"><span>Become a member today</span></a></button>
</div>

【问题讨论】:

  • “不工作”是什么意思? - 还有,为什么你有一个里面有锚的按钮?这似乎很奇怪。

标签: html css button hyperlink anchor


【解决方案1】:

.button {
  position: relative;
  display: inline-block;
  border-radius: 20px;
  border: 2px solid #ffcc00;
  background-color: #006534;
  color: #FFFFFF;
  text-align: center;
  font-size: 16px;
  padding: 9px;
  width: 230px;
  transition: all 0.5s;
  cursor: pointer;
  margin: 5px;
  top: 0px;
  left: 0px;
}

.button span {
  cursor: pointer;
  display: inline-block;
  position: relative;
  transition: 0.5s;
  color: #FFFFFF;
}

.button span:after {
  content: '»';
  position: absolute;
  opacity: 0;
  top: 0;
  right: -20px;
  transition: 0.5s;
  color: #FFFFFF;
}

.button:hover span {
  padding-right: 25px;
  color: #FFFFFF;
}

.button:hover span:after {
  opacity: 1;
  right: 0;
  color: #FFFFFF;
}
<div>
  <a href="link" class="button"><span>taddaa</span></a>
</div>

您可以在锚标记中使用您的按钮类。所以不需要在按钮中添加锚标记

【讨论】:

  • “简单是辉煌的关键”~李小龙
【解决方案2】:

a {
  display: inline-block; /* inline by default */
  padding: 1rem 2rem;
  background: gray;
  color: white;
}

a span {
  border: 1px solid white;
}
<a class='link' href='http://example.com'>
  <span>Link title?</span>
</a>

【讨论】:

    【解决方案3】:

    Tyy 按钮样式

    .button {
       display: inline-block;
       border-radius: 20px;
       border: 2px solid #ffcc00;
       background-color: #006534;
       color: #FFFFFF;
       text-align: center;
       font-size: 16px;
       padding: 9px;
       width: 230px;
       transition: all 0.5s;
       cursor: pointer;
       margin: 5px;
    }
    

    【讨论】:

      【解决方案4】:

      这是更好的方法,无需使用按钮,适用于所有浏览器

      a {
          background: #000;
          padding: 10px 20px;
          border-radius: 5px;
          text-decoration: none;
          color: orange;
          font-weight: bold;
          transition: all 6000;
          box-sizing: border-box;
      }
      
      span {
          position: relative;
          left: 0;
      }
      
      a:hover span {
          left: -5px;
          transition: left 1s;
      }
      
      a:hover span:after {
          content: ' »';
          position: absolute;
      }
      &lt;a href="link"&gt;&lt;span&gt;Become a member today&lt;/span&gt;&lt;/a&gt;

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-31
        • 1970-01-01
        • 2014-12-07
        • 1970-01-01
        • 2020-03-12
        • 2010-12-18
        相关资源
        最近更新 更多