gpt4 book ai didi

css - 如何在 div 上使用 sprite 作为背景,将 sprite 的一部分定位到 div 的右侧

转载 作者:行者123 更新时间:2023-11-28 17:40:05 25 4
gpt4 key购买 nike

我要应用背景的 div 比我的 sprite 大,我想用作背景的 sprite 部分距离 sprite 顶部 100px。

如何将 div 的背景设置为我想要的 sprite 的一部分,将其定位到 div 的右侧。

我有:http://jsbin.com/yibesu/1/edit?html,css,output

我希望将“what-i-want”背景推到 div 的右侧,其余部分为红色。

我的 CSS:

div { 
background: url('http://i.imgur.com/VBe5ey2.png') red;
background-position: 0 -100px;
background-repeat: no-repeat;
width: 400px;
height: 200px;
}

这就像我希望背景位置为“0 -100px”推到 div 的右侧。 Sprite 的宽度小于 div。这可能吗?或者我是否需要将部分从 Sprite 中撕下来并让它成为自己的形象?谢谢!

最佳答案

你很接近。您唯一需要做的就是使用 background-position 将其右对齐。新的css如下:

div { 
background: url('http://i.imgur.com/VBe5ey2.png') red;
background-position: right -100px;
background-repeat: no-repeat;
width: 400px;
height: 200px;
}

我用 Firefox、Chrome 和 IE11 对其进行了测试,一切似乎都正常。

关于css - 如何在 div 上使用 sprite 作为背景,将 sprite 的一部分定位到 div 的右侧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24295243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com