创建具有鼠标悬停效果的箭头

时间:2016-06-02 15:34:20

标签: css mouseover css-shapes

我想创建一个带有鼠标悬停效果的简单箭头。我创建了一个跨度和一个三角形。但现在我需要一个应该适用于整个箭头的鼠标悬停效果。任何的想法?我把我的Sourcetext放在一个小提琴里。

HTML

<span id="series" class="rectangle"></span>
<div class="series-triangle"></div>

CSS

#series { 
    width: 60px;
}

.series-triangle{
    float:left;
    width: 0px;
    position: relative;
}

.series-triangle:after {
    content: '';
    position: absolute;
    top: 3px;
    left: -3px;
    width: 0;
    height: 0;
    border-color: transparent transparent transparent #EFDF00;
    border-style: solid;
    border-width: 31px;
}

.series-triangle:before {
    content: '';
    position: absolute;
    top: 1px;
    left: -2px;
    width: 10;
    height: 10;
    border-color: transparent transparent transparent #444;
    border-style: solid;
    border-width: 33px;
}

.series-triangle:hover {
    background-color: white;
}

.rectangle {
    float:left;
    height: 60px;
    border: 2px solid #444;
    padding: 2px;
    text-align: center;
    border-radius: 5px;
    background-color: #EFDF00;
}

.rectangle:hover { 
    background-color: white;
}

http://jsfiddle.net/u7tYE/8089/

1 个答案:

答案 0 :(得分:1)

将它们放在父元素中并对父元素的:hover状态作出反应:

HTML:

<div class="parent">
    <span id="series" class="rectangle"></span>
    <div class="series-triangle">
    </div>
</div>

CSS:

.parent:hover .rectangle, .parent:hover .series-triangle{
    /* Do something */
}

父悬停时两个部分的颜色更改示例: http://jsfiddle.net/u7tYE/8091/