【问题标题】:Transition on gradient button? [duplicate]渐变按钮上的过渡? [复制]
【发布时间】:2013-04-21 01:51:28
【问题描述】:

我正在尝试为我正在制作的这个模型导航栏上的这个按钮设置一个转换,当我将鼠标悬停在上面时,我想要一个 0.5 秒的转换来改变背景,但它不起作用我没有'在 css 中确实使用了很多过渡,但这是伟大的谷歌告诉我的:

.btn-primary {
    border: 1px solid #e5e5e5;
    border-radius: 6px;
    padding: 6px;
    background: -webkit-linear-gradient(bottom, #0066FF 0, #0088FF 85%, #00AAFF 100% );
    font-size: 14px;
    color: white;
}

.btn-primary:hover {
    background: -webkit-linear-gradient(bottom, #0000CC 0, #0044CC 100%);
    cursor: pointer;
    -webkit-transition: background 0.3s linear;
}

演示:http://codepen.io/anon/pen/lApnj

任何信息都会非常感谢! :)

【问题讨论】:

  • 它可能“工作”,但它显然没有像 OP 期望的那样转换..
  • @kellyjohnson 它应该是一种淡入淡出/过渡,而不仅仅是颜色的瞬间变化
  • 是的,它在 Chrome 和 Firefox 中为我做了什么

标签: html css


【解决方案1】:

您必须像这样将转换置于类的正常状态:

.btn-primary {
    border: 1px solid #e5e5e5;
    border-radius: 6px;
    padding: 6px;
    background: -webkit-linear-gradient(bottom, #0066FF 0, #0088FF 85%, #00AAFF 100% );
    font-size: 14px;
    color: white;
    -webkit-transition: background 0.3s linear;
}

.btn-primary:hover {
    background: -webkit-linear-gradient(bottom, #0000CC 0, #0044CC 100%);
    cursor: pointer;

}

EDIT:这实际上是错误,因为正如 Kacey 所说,不支持使用渐变。抱歉弄错了

【讨论】:

    【解决方案2】:

    不支持 CSS3 渐变过渡。 还没有。但是,您可以尝试这样的事情:

    按钮

    <a class="btn_primary" href="#">A button</a>
    

    CSS

    .btn_primary {
        background-color : #6BFF8A;
        background-image : linear-gradient(to bottom, transparent 0%, rgba(0, 0, 0, 0.2) 100%);
        color : #fff;
        display : block;
        font-family : arial,sans-serif;
        font-size : 12px;
        padding : 5px 10px;
        text-align : center;
        text-decoration : none;
        transition : background-color 0.5s ease 0s;
        width : 75px;
    }
    .btn_primary:hover {
        background-color : #900;
    }
    

    这是我为你创建的little fiddle

    【讨论】:

    • codepen.io/anon/pen/lApnj 知道为什么我的按钮在鼠标悬停时会“闪烁”吗?
    • 这是因为您正在转换背景颜色,但它没有设置初始背景颜色。
    • 更新了笔,再次检查它仍然闪烁:/
    • @XCritics 我为你创建了一支新笔。检查一下,让我知道它是如何为你工作的。 codepen.io/anon/pen/fixtq
    猜你喜欢
    • 2016-01-25
    • 2021-12-13
    • 2021-07-27
    • 2020-10-16
    • 1970-01-01
    • 2014-12-10
    • 1970-01-01
    • 1970-01-01
    • 2020-07-11
    相关资源
    最近更新 更多