简体   繁体   English

精灵图像重复x

[英]sprite image repeat in x

i have one image and i want to set this image into diff. 我有一个图像,我想将此图像设置为差异。 place like heading image plack. 像标题图片一样的地方。
i am done this to sprite. 我这样做是为了精灵。

<style type='text/css'> 
    img {
        margin: 5px;
        border: 1px solid silver;
    }

    .sprite {
        width: 20%;
        background-image: url('sprite.png');
    }

    .sprite.head {
        background-position: 0 -47px;
        height: 70px;
    }           

    .sprite.logo {
        background-position: 6px 0;
        height: 43px;
        width: 250px;
    }

</style>
<div alt='smile' title='smile' class='sprite head'></div>   
<div alt='fish' title='fish' class='sprite logo'></div>

this is the my 这是我的

Try 尝试

i want to set heading repeat. 我想重复标题。
black image repeat. 黑色图像重复。
thanks. 谢谢。

Sprites do not work this way. 子画面无法以这种方式工作。

You cannot repeat a part of the background-image with pure css alone. 您不能仅使用纯CSS来重复背景图像的一部分。

Don't wrestle with this. 不要为此苦苦挣扎。 Make the background-image a image of itself and use that. 使背景图像成为其自身的图像并使用它。 Don't do repeats in sprites. 不要在精灵中重复。


edit 编辑

BTW, that's not the whole story. 顺便说一句,这还不是全部。 It is possibly under certain circumstances as easwee stated in his/her comment. 如easwee在其评论中所述,可能是在某些情况下。 But it's not worth the fuss. 但这不值得大惊小怪。 Because you always have to see, if you whole sprite thing is not destroyed by it. 因为您始终必须看到,如果您整个sprite事物都不会被它破坏。 So, I will not bring a solution to this. 因此,我不会对此提出解决方案。

It can be done but with limitations and loss of sprite optimal space use . 可以这样做,但有局限性,并且会浪费精灵最佳空间

What you can do is to: 您可以做的是:

1.) Extend the part you want to repeat across the whole width of the image sprite. 1.)将要重复的部分扩展到整个图像精灵的整个宽度上。 It has to be in it's own row. 它必须在它自己的行中。

在此处输入图片说明

2.) Set a fixed height to the element that needs the repeated background (to ensure the parts of the sprite below the repeat pattern won't be visible if the element breaks in two lines). 2.)为需要重复背景的元素设置固定的高度(以确保如果元素分成两行,则在重复模式下的子画面部分将不可见)。

3.) Set background-repeat: repeat-x 3.)设置background-repeat: repeat-x

Fidle: http://jsfiddle.net/kZLsL/4/ Fidle: http//jsfiddle.net/kZLsL/4/

You can't repeat just part of the image. 您不能仅重复图像的一部分。

I would suggest you use a separate image for your background. 我建议您为背景使用单独的图像。

You can also edit your image sprite to stretch the part you want to repeat to cover the full width of your image sprite. 您还可以编辑图像精灵,以拉伸要重复的部分,以覆盖图像精灵的整个宽度。 This has the benefit of reducing the number of get requests when loading the page. 这样做的好处是减少了加载页面时获取请求的数量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM