首页 > 解决方案 > 超链接集合

元素

问题描述

当我尝试超链接下面的代码时,它似乎弄乱了图像的包装,并且只链接了图标而不是整个 flex 容器。我尝试过尝试<span>元素,但没有任何成功。

.flex-container {
  padding: 0;
  margin: 0;
  list-style: none;
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-flow: row;
  transition: opacity .2s ease-in-out;
  flex-wrap: nowrap
}

.flex-item {
  text-align: center;
  text-decoration: none;
  color: #ffffff;
  font-family: verdana;
  width: 100%;
  display: flex;
  flex-shrink: 1;
  justify-content: center;
  align-items: center;
  font-size: calc(8px + (26 - 18) * ((100vw - 300px) / (1600 - 300)));
  z-index: 10;
  flex-wrap: nowrap
}

.flex-item:before {
  content: '';
  float: left;
  padding-top: 100%;
}

.red-box {
  background: #fd6f71;
  transition: opacity .2s ease-in-out;
  opacity: 1;
}
<div class="flex-container">
  <div class="red-box flex-item">
    <div class="lh-icon"><img src="https://i.imgur.com/NCp8Sst.png"></div>
    <a>Placeholder</a>
  </div>
</div>

代码笔:

https://codepen.io/adms2000/pen/LYVpaBB

标签: htmlcsscss-animations

解决方案


由于<a>元素不能包含<a>子元素,因此用 .flex-container 包裹整个容器<a>会失败。只需将占位符的标签从 更改<a><span>

<a href="http://yourlinkhere.com">
  <div class="flex-container">
    <div class="red-box flex-item">
      <div class="lh-icon"><img src="https://i.imgur.com/IyLYxCc.png"></div>
      <span>Placeholder</span>
    </div>
  </div>
</a>

希望这有帮助:D


推荐阅读