Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    29
    Thanked 1 Time in 1 Post

    [CSS]Any difference between background: url() and background-position in sprites?

    Hi all,

    Well just that, Is it the same to do this (just an example)
    PHP Code:
    .option1 background:url(foo.png0 0 no-repeat;
    .
    option2 background:url(foo.png-30px no-repeat;
    .
    option3 background:url(foo.png-60px no-repeat
    and this? (just an example too)
    PHP Code:
    .option-container background:url(foo.pngno-repeat;}
    .
    option1 background-position0 0 no-repeat;}
    .
    option2 background-position-30px no-repeat;}
    .
    option3 background-position-60px no-repeat;} 
    The question is oriented to the best solution for performance. Are there any significant differences?

    Thanks in advance

  • #2
    Regular Coder
    Join Date
    Oct 2010
    Location
    San Antonio Tx
    Posts
    251
    Thanks
    12
    Thanked 11 Times in 11 Posts
    sprites are seamless rollovers

  • #3
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,675
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Hello hernantz,
    They both load and position foo.png for each option. I would prefer the first example because it's more condensed than the second.
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • Users who have thanked Excavator for this post:

    hernantz (12-19-2010)

  • #4
    Regular Coder
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    29
    Thanked 1 Time in 1 Post
    it's good to know, thanks

  • #5
    The Apostate Apostropartheid's Avatar
    Join Date
    Oct 2007
    Posts
    3,215
    Thanks
    16
    Thanked 265 Times in 263 Posts
    I would just condense it as so:
    Code:
    #options div { background: url(foo.png) no-repeat; } 
    .option1 { background: 0 0;} 
    .option2 { background: 0 -30px;} 
    .option3 { background: 0 -60px;}
    with
    Code:
    <div id="options">
      <div class="option1"></div>
      <div class="option2"></div>
      <div class="option3"></div>
    </div>
    Last edited by Apostropartheid; 12-20-2010 at 01:49 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •