【问题标题】:CSS transition is not working, it was working beforeCSS 过渡不工作,它之前工作
【发布时间】:2021-12-07 20:40:15
【问题描述】:
#front{
    margin-left:100px;
    margin-right:100px;
    transition:margin-left 1s;
    
    text-align:center;
     
    margin-bottom:-30px;  
  
}

上述转换代码之前可以正常工作,但在 2-3 周后它停止工作。不知道为什么?

我也检查了不同的浏览器,但转换不起作用。

【问题讨论】:

  • 要发生转换,需要有两种状态。在这里你只显示一种状态,不应该有任何过渡。请包含重现您的问题所需的所有代码。

标签: html css css-transitions


【解决方案1】:

当您更改margin-left 的设置时,它可以正常工作。请参阅下面的示例。

#front {
  margin-left: 100px;
  margin-right: 100px;
  transition: margin-left 1s;
  text-align: center;
  margin-bottom: -30px;
}

#front:hover {
  margin-left: 50px;
}
<div id="front">Hello world</div>

【讨论】:

【解决方案2】:

我不知道你想要什么结果,但根据@gerad 的回答,我只是稍微修改了一下。将 transition 更改为 animation 并添加 keyframes 如果你想加载

#front {
  margin-left: 100px;
  margin-right: 100px;
  animation: margin-left 1s;
  text-align: center;
  margin-bottom: -30px;
}

@keyframes margin-left {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-50px);
  }
}
<div id="front">Hello world</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-06
    • 1970-01-01
    • 2011-12-25
    • 2020-11-25
    • 1970-01-01
    • 2016-10-17
    • 2012-06-24
    • 1970-01-01
    相关资源
    最近更新 更多