【问题标题】:Placing shape behind icon as hover state将形状放在图标后面作为悬停状态
【发布时间】:2020-02-25 20:36:29
【问题描述】:

我正在尝试在图标后面放置一个形状,因此当您将鼠标悬停时,该形状将显示在图标后面。这是我的html代码:

<div class="icon">
  <a class="hover1" href="#">
     <img src="images/marketing.png" alt="Marketing icon">
  </a>
  <h3>Marketing</h3>
</div>

这是 CSS:

.icon .hover1:hover {
  background-image: url(images/marketing_2.png);
  background-repeat: no-repeat;
  background-position: center bottom;
  background-size: cover;
}

目前该形状未正确显示。不知道现在该怎么做,因为我对这一切都很陌生。

Icon with text underneath
Shape I want to place behind icon when I hover

【问题讨论】:

标签: html css hover


【解决方案1】:

对你有用吗?

.hover1:hover .img2{
   display: block;
    
}

.img2{
  display:none;
  z-index: -1;
  position: absolute;
  top: -2px;
  right: 36%;
  width: 180px;
  height: auto;
  transition: all 0.5s ease-in;
}

.hover1{
    width:fit-content;
    height:fit-content;

}

.img1{
  width:50px;
  height:auto;
    margin-top:30px;
}

div{
  text-align:center;
}

h3{
  margin-top:0px;
}
<div class="icon">

   <a class="hover1" href="#">
         <img class="img2" src="https://i.stack.imgur.com/4Y6nb.png" alt="Marketing icon">
      <img class="img1" src="https://iservat.ir/wp-content/uploads/2017/01/Marketing-PNG-File-284x300.png" alt="Marketing icon">
   </a>
   <h3>Marketing</h3>
</div>

【讨论】:

  • 这会在屏幕中间放置一个大的背景形状。它没有直接出现在悬停图标的后面。
【解决方案2】:

我认为这个 CSS 一定能帮到你想要的东西

.icon .hover1{
            position: absolute;
            top: 10%;
            left: 10%;
            z-index: 1
        }
        .icon .hover1:hover{
            position: absolute;
            top: 10%;
            left: 10%;
            background-image: url(https://i.stack.imgur.com/JB1Xw.png);
            background-repeat: no-repeat;
            background-position: center;
            background-size: cover;
            z-index: 0
        }

【讨论】:

  • 随心所欲地设置你的位置
  • 恐怕这行不通。它将图标放在屏幕的左上角,悬停时没有任何反应。
  • 这个网站也需要响应式
猜你喜欢
  • 1970-01-01
  • 2014-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多