如何防止CSS背景图像移动时显示?

时间:2014-11-09 17:20:45

标签: javascript jquery html css background-image

我正在使用背景图片来提供有关当前选择的导航部分的其他用户说明;并使用" background-position:right center;"对于所述背景图像,代码使得背景图像每次显示时都会在容器中移动...而不是仅仅已经显示在所需位置而没有任何移动。

如何修改我的代码,使背景图像在其容器中移动,只显示在所需的位置(右侧和中间)?

Here is the JSFiddle demonstrating the unwanted movement

HTML

<div id="panel">
    <div class="panel-styling selected-panel">
    One
    </div>

    <div class="panel-styling">
    Two
    </div>

    <div class="panel-styling">
    Three
    </div>
</div>

CSS

#panel {
    float: left;
    width: 50%;
    margin: 2% 0 0 2%;
    padding: 0 0 0 0;
}

.panel-styling {
    width: 100%;
    padding: 8px 0 7px 0;
    text-align: left;
    border-bottom: 1px solid rgba(136,136,136,1);

    font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;
    font-size: 16px;
    line-height: 100%;
    color: rgba(136,136,136,1);
}

.panel-styling:hover {
    cursor: pointer;
    color: rgba(255,0,0,1);
      border-bottom: 1px solid rgba(255,0,0,1);

    -webkit-transition: all 0.25s;
    -moz-transition: all 0.25s;
    transition: all 0.25s;
}

.selected-panel {
    color: rgba(255,0,0,1);
    border-bottom: 1px solid rgba(255,0,0,1);

    background-image: url('http://s23.postimg.org/7urmjdktj/slider_arrow.png');
    background-position: right center;
    background-repeat: no-repeat;
}

的JavaScript

$('.panel-styling').click(function () {
    $('.panel-styling').removeClass('selected-panel');
    $(this).addClass('selected-panel');
});

谢谢!

Berklie

1 个答案:

答案 0 :(得分:2)

CSS中的transition属性是个问题。将all替换为更具体的内容。如果您想要文本颜色的转换,请使用color

.panel-styling:hover {
    cursor: pointer;
    color: rgba(255,0,0,1);
    border-bottom: 1px solid rgba(255,0,0,1);

    -webkit-transition: color 0.25s;
    -moz-transition: color 0.25s;
    transition: color 0.25s;
}