【问题标题】:Transition makes image shift 1px过渡使图像偏移 1px
【发布时间】:2018-09-26 18:18:44
【问题描述】:

我见过this thread,但它对我不起作用。 (除非我将建议的代码粘贴到错误的位置)

基本上,在 Firefox 中,当悬停链接时,下方的图像会移动 1px(只有其中的一部分,所以请四处寻找)。最重要的是,Chrome 会模糊所有图像。

See my Codepen

当我删除时

  -webkit-transition: opacity .3s ease-in-out;
  transition: opacity .3s ease-in-out;

问题消失了。

有没有办法让它在不丢失那条线的情况下工作?

完整代码:

HTML

<div class="main">
        <div class="hover_img animated fadeInUp">
            <a class="hover_link" href="work/sensory/">Sensory Possibilities<span>
              <img src="http://witch-house.com/NEW/sensory.png"/></span></a>
            /
            <a class="hover_link" href="work/designing/">Designing Humans<span>
                <img src="http://witch-house.com/NEW/deshum.png"/></span></a>
            /
            <a class="hover_link" href="work/daggerforest/">Dagger Forest<span>
                <img src="http://witch-house.com/NEW/dagger.jpg"/></span></a>
            /
            <a class="hover_link" href="work/wavelength/">Wavelength<span>
               <img src="http://witch-house.com/NEW/dagger.jpg" class="img4"></span></a>
            / 
            <a class="hover_link" href="work/talescrypt/">Tales From The Crypt<span>
                <img src="http://witch-house.com/NEW/tftc.jpg"/></span></a>
            /
            <a class="hover_link" href="work/dnahackers/">DNA Hackers<span>
                <img src="http://witch-house.com/NEW/dnahx.jpg"/></span></a>
            /
            <a class="hover_link" href="work/robots/" >Do Graphic Designers Need To Be Human?<span>
                <img src="http://witch-house.com/NEW/robots.jpg"/></span></a>
        </div>
    </div>
</div>

和 CSS:

.main {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 54%;
  font-size: 2.5vw;
  line-height: 2.8vw;
  font-family: 'Raleway';
  text-transform: uppercase;
  font-weight:200;
  margin: 0 auto;
}

.hover_link {
  color: #d2d2d2;
  font-family: 'Rubik';
  text-transform: uppercase;
  font-weight:900;
}
.hover_link:hover {
  text-decoration: none;
  color: #4b2de5;
}

/* PROJECTS IMAGES */

.hover_img span {
  pointer-events: none;
  z-index:-1;
  opacity: 0;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  -webkit-transition: opacity .3s ease-in-out;
  transition: opacity .3s ease-in-out;
}
.hover_img a:hover span {
  display: inline-block;
  opacity: 1;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

a {  text-decoration:none; }
img { width: 40vw; }

【问题讨论】:

  • 您确定您共享了正确的 codepen 吗?
  • 嗯,是的,这个:codepen.io/alanvkarlik/pen/PRMeJg?编辑。是的,这是错误的链接 - 现在应该修复,抱歉!

标签: css hover css-transitions css-transforms


【解决方案1】:

并改变我们以这种方式在 html 中插入图片的方式

    <div class="main">
         <div class="hover_img animated fadeInUp">
             <a class="hover_link" href="work/sensory/">Sensory Possibilities
                <span style="background-image: url(http://witch-house.com/NEW/sensory.png)" /> 
               </span></a>
                /
                <a class="hover_link" href="work/designing/">Designing Humans
                  <span style="background-image: url(http://witch-house.com/NEW/deshum.png)" /> 
                  </span></a>
                /
                <a class="hover_link" href="work/daggerforest/">Dagger Forest
                  <span style="background-image: url(http://witch-house.com/NEW/dagger.jpg)" /> 
                  </span></a>
                /
                <a class="hover_link" href="work/wavelength/">Wavelength
                  <span style="background-image: url(http://witch-house.com/NEW/dagger.jpg)" /> 
                  </span></a>
                / 
                <a class="hover_link" href="work/talescrypt/">Tales From The Crypt
                  <span style="background-image: url(http://witch-house.com/NEW/tftc.jpg)" /> 
                  </span></a>
                /
                <a class="hover_link" href="work/dnahackers/">DNA Hackers
                  <span style="background-image: url(http://witch-house.com/NEW/dnahx.jpg)"/>
                  </span></a>
                /
                <a class="hover_link" href="work/robots/" >Do Graphic Designers Need To Be Human?
                  <span style="background-image: url(http://witch-house.com/NEW/robots.jpg)"/>
                  </span></a>
            </div>
        </div>
  </div>

和 CSS

.main {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 54%;
    font-size: 2.5vw;
    line-height: 2.8vw;
    font-family: 'Raleway';
    text-transform: uppercase;
    font-weight:200;
    margin: 0 auto;
  }

  .hover_link {
    color: #d2d2d2;
    font-family: 'Rubik';
    text-transform: uppercase;
    font-weight:900;
  }
  .hover_link:hover {
    text-decoration: none;
    color: #4b2de5;
  }

  /* PROJECTS IMAGES */

  .hover_img span {
    z-index: -1;
    opacity: 0;
    display: inline-block;
    transition: opacity .3s ease-in-out;
    position: fixed;
    width: 100%;
    text-align: center;
    left: 0;
    top: -50%;
    height: 200%;
    background-position: center;
    background-size: auto 100%;
    background-repeat: no-repeat;
  }
  .hover_img a:hover span {
    opacity: 1;
  }

  a {  text-decoration:none; }
  img { width: 60%; margin: 0 auto;}

【讨论】:

  • 效果更好,但是当我将这些图像的大小更改为更大时 - 它们会被 .main 容器裁剪 - 请参阅:codepen.io/alanvkarlik/pen/WzVBzO
  • 背景尺寸:自动 100%;更改为 background-size: 100% auto ;
  • 仍然裁剪 - 这次是高度
【解决方案2】:

试试这个 CSS

  .main {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 54%;
    font-size: 2.5vw;
    line-height: 2.8vw;
    font-family: 'Raleway';
    text-transform: uppercase;
    font-weight:200;
    margin: 0 auto;
  }

  .hover_link {
    color: #d2d2d2;
    font-family: 'Rubik';
    text-transform: uppercase;
    font-weight:900;
  }
  .hover_link:hover {
    text-decoration: none;
    color: #4b2de5;
  }

  /* PROJECTS IMAGES */

  .hover_img span {
    z-index: -1;
    opacity: 0;
    display: inline-block;
    transition: opacity .3s ease-in-out;
    position: fixed;
    width: 100%;
    text-align: center;
    top: -50%;
    left: 0;
  }
  .hover_img a:hover span {
    opacity: 1;
  }

  a {  text-decoration:none; }
  img { width: 60%; margin: 0 auto;}

【讨论】:

  • 不幸的是,在您的示例中,图像没有居中,而且 Chrome 仍然模糊 :(
猜你喜欢
  • 2013-03-06
  • 1970-01-01
  • 1970-01-01
  • 2023-03-20
  • 1970-01-01
  • 2016-09-28
  • 1970-01-01
  • 2016-12-18
  • 2012-03-05
相关资源
最近更新 更多