html - 超链接 <div> 元素的集合

标签 html css css-animations

当我尝试超链接下面的代码时,它似乎弄乱了图像的包装并且只链接了图标而不是整个 flex-container。我试过用 <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

最佳答案

<a>元素不能包含 <a> children ,所以用 <a> 包装整个 .flex-container会失败。只需将占位符的标记从 <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

关于html - 超链接 <div> 元素的集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60200662/

相关文章:

html - 如何创建不同的过渡/动画延迟?

javascript - 使用 canvas + css 动画构建棋盘游戏

python - 如何查找对特定数据有效的所有 HTML 标签的列表

html - 剑道菜单错误位置元素第一次

PHP - xPath DOM 元素到 HTML 字符串

计算分数的Java程序

html - 如何使用 Google 开发者工具在本地主机上定位 HTML 文件?

jquery - 如何访问这个子分区

javascript - rcarousel 如何合并 jquery 语句

Css 动画无法正常工作