【问题标题】:css transition is not working on gradients? [duplicate]css 过渡不适用于渐变? [复制]
【发布时间】:2021-07-27 07:08:12
【问题描述】:
.body {
    background-color: #18181a;
    color: white;
    font-size: 2.5rem;
    margin-left: 0%;
    border-radius: 5px;
}

.body  .card{
    background:linear-gradient(90deg, rgba(0,0,0,1) 0%, rgba(0,212,255,0) 100%),url("./images/yuuki_mikan_bg.jpg");
    background-repeat: no-repeat;
    background-position: right;

    width: 90%;
    height: 80%;
    border-radius: 10px;
    margin: 10px;
    margin-left: auto;
    margin-right: auto;
    display: flex;
    justify-content: space-between;
    flex-direction: row-reverse;

    transition: background 0.5s linear;
}

.body .card:hover {
    background:linear-gradient(90deg, rgba(0,0,0,0.17690826330532217) 0%, rgba(0,212,255,0) 100%),url("./images/yuuki_mikan_bg.jpg");
    background-position: right;
}

.body  .card .card_img{
    max-width: 80%;
    max-height: 95%;
    border-radius: 5px;
    /* bottom: 9px; */
    /* left: -10px; */
    /* top: -10px; */
    transition: 0.5s;
    opacity: 1;
    display: flex;
    justify-content: flex-start;
    align-self: center;
}

.body  .card .card_name{
    margin-right: 2%;
    margin-top: auto;
    margin-bottom: auto;
    font-size: 2.5rem;
    text-shadow: 0px 0px 18px black;
    opacity: 1;
}

这是我使用的代码,当我将鼠标悬停在.card 上时,它会更改背景颜色,但过渡不会延迟其过渡时间。如果你想要更多的上下文,这是我的代码在https://oniichann.tk/waifus运行的网站

【问题讨论】:

    标签: css


    【解决方案1】:

    我相信背景渐变上唯一的动画属性是background-position

    您可以通过执行以下操作来实现您想要的:

    .card {
      position: relative;
      text-align: center;
      color: white;
      padding: 100px;
      background: url("https://oniichann.tk/waifus/images/bg.jpg");
      background-repeat: no-repeat;
      background-position: right;
      background-size: cover;
    }
    
    .card:before {
      content: "";
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: linear-gradient(
        90deg,
        rgba(0, 0, 0, 1) 0%,
        rgba(0, 0, 0, 0) 100%
      );
      background-size: 200% 200%;
      transition: background-position 0.5s linear;
    }
    
    .card:hover:before {
      background-position: 100% 50%;
    }
    <div class="card"></div>

    【讨论】:

    • 天哪,非常感谢兄弟
    猜你喜欢
    • 2018-06-16
    • 1970-01-01
    • 2014-12-10
    • 2016-09-30
    • 2016-12-03
    • 2020-12-07
    • 2017-12-17
    • 1970-01-01
    • 2015-01-02
    相关资源
    最近更新 更多