【问题标题】:Add gradient to pseudo element向伪元素添加渐变
【发布时间】:2013-10-09 08:26:04
【问题描述】:

如何将黄色渐变应用到白色箭头?

这里是小提琴链接: http://jsfiddle.net/VNnKR/

$('.white').hover(function() {
$(this).addClass('gradient');
})

【问题讨论】:

  • 你需要#arrow4里面的div还是删掉?
  • @LinkinTED 我只需要一个渐变箭头,可能会被删除

标签: javascript jquery css gradient linear-gradients


【解决方案1】:

我找到了一个解决方案,请注意它只适用于纯色背景。

HTML:

<div class="arrow">
    START HERE!
</div>

CSS:

body {
    background: #6cc5c3;
}
.arrow {
    margin-top: 150px;
    position: relative;
    font-weight: bold;
    margin-bottom: 5px;
    height: 20px;
    padding: 10px 30px 10px 10px;
    width: 140px;
    color: #6cc5c3;
    background: #fff;
    text-align: center;
}
.arrow:after {
    content:'';
    height: 0;
    width: 0;
    display: block;
    border-color: #6cc5c3 #6cc5c3 #6cc5c3 transparent;
    border-width: 20px;
    border-style: solid;
    position: absolute;
    top: 0;
    right: -20px;
}

.gradient {
    background: #ffe632;
    background: -webkit-gradient(linear, left top, left bottom, from(#fffe8d), to(#f6d23e));
    background: -moz-linear-gradient(top, #fffe8d, #f6d23e);
}

DEMO

箭头是透明的,“箭头”的其余部分与正文背景颜色相同。

【讨论】:

  • 实际上效果很好,我看到渐变,一个问题,为什么当鼠标离开按钮时,他是钢色的?
  • 因为您是这样编写脚本的... :) 使用 addClass jQuery 函数。如果您不希望只能使用 CSS,请将 .gradient 更改为 .arrow:hover。检查jsfiddle.net/LinkinTED/VNnKR/10
猜你喜欢
  • 1970-01-01
  • 2017-11-29
  • 1970-01-01
  • 1970-01-01
  • 2011-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-26
相关资源
最近更新 更多