[英]Change background position in css doesn't work
I have an image with size of 5760x496px. 我有一个尺寸为5760x496px的图像。 This image is composed by three images of 1920x496px.
该图像由1920x496px的三幅图像组成。 Now i'm trying only to change the position with
:hover
and when i'll know how it works i'll change it in jQuery. 现在,我仅尝试使用
:hover
更改位置,当我知道其工作方式时,将在jQuery中进行更改。 The problem is that the result of my code is a white background so i think that something isn't working in it. 问题是我的代码的结果是白色背景,所以我认为其中有些不起作用。 This is my css:
这是我的CSS:
.slider {
position:relative;
height: 496px;
border-bottom: 1px solid #ddd;
background: url(../images/full_slider.jpg) no-repeat;
background-position-x: 0px;
}
.slider:hover{
background-position-x: 1920px;
}
In this case i expected to translate the background from the first slide to the second slide only but this isn't the result. 在这种情况下,我希望仅将背景从第一张幻灯片转换到第二张幻灯片,但这不是结果。
you can set the x property for background-position like this:
您可以像这样将x属性设置为背景位置:
background-position: x-px y-px;
Ex: background-position: 40px 0;
例如:
background-position: 40px 0;
see this works with your example: http://jsfiddle.net/hboq09p9/ 看到它与您的示例一起使用: http : //jsfiddle.net/hboq09p9/
code: 码:
.slider {
position:relative;
height: 496px;
border-bottom: 1px solid #ddd;
background: url('http://images.visitcanberra.com.au/images/canberra_hero_image.jpg') no-repeat;
background-position: 0px 0px;
}
.slider:hover{
background-position: 40px 0;
}
(I have just moved it 40px because my image is not 1920px wide) (我刚刚将其移动了40px,因为我的图像宽度不是1920px)
Take a look at this - http://www.w3schools.com/cssref/pr_background-position.asp 看看这个-http://www.w3schools.com/cssref/pr_background-position.asp
background-image: url('smiley.gif');
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.