CSS Sprite Position and Menu LI width

Discussion in 'CSS' started by fAdEd247, Mar 11, 2010.

  1. #1
    Hi,

    I'm applying css sprites to my custom html menu. I'm unable to figure out how to position the sprite above the content of the line item, without losing visibility of the image. When I apply a background position of 0 -25px, the image locates above the content, however the image does not display properly.

    I have a sprite that is 80px wide, with 2 images inside it, each 40px wide. When I set the width of line item to 40px, the menu item's content does not have enough width, and squeezes together.

    How should I display the image on top of the menu content?

    How can I display only 40px of the sprite, while the menu item has a width of about 55px, so the content of the menu item displays correctly?

    My site is at http://www.infinitesolutionsonline.com

    Thank you very much!

    Ty
     
    fAdEd247, Mar 11, 2010 IP
  2. pmek

    pmek Guest

    Messages:
    101
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    When you make a sprite you don't need to put the two states right next to eachother. You can have as much space between them as you want. You can even put them on top of each other.

    So, instead of this - (O represents and image} OO

    Make your image like this - O_____________________O

    Or this - O
    _______O
     
    pmek, Mar 12, 2010 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #3
    pmek hit it on the head, add more padding between them, and given your approach you'd be better off putting them one over the other so that they are chopped off on the Y axis, since on the X axis it's going to show the other half.

    Though honestly I'd probably end up putting a dummy span in the markup and positioning the dummy span for that image. That way I could set an overflow:hidden and use both axis for sliding the background around; That would allow for you to take all those separate -sprite- images and make them a single file. eleven bytes per element for <span></span> is a small price to pay for eliminating five or more server requests.
     
    deathshadow, Mar 12, 2010 IP
  4. fAdEd247

    fAdEd247 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi,

    Thanks for the replies.

    How do I update the inner element background upon hovering on the anchor text?

    <li><a><span id="inner-element"></span><br />Anchor Text</a></li>

    #mymenu li a:hover inner-element {
    background:url..

    Thanks for your help.

    Ty
     
    fAdEd247, Mar 13, 2010 IP
  5. fAdEd247

    fAdEd247 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Update -

    Wow, I was almost right!

    By applying
    #mymenu li a.topa:hover #inner-element {
    background:url..

    I was able to successfully display all the sprites! :D

    I'm unable to figure the correct syntax to display the hover image when hovering over the sub menu anchor text. I tried applying;

    #mymenu a.topb ul li:hover #computer-element {
    background:url("http://infinitesolutionsonline.com/images/menu-sprite-1.jpg") no-repeat scroll -68px -48px transparent;
    }

    But this doesn't work..

    And lastly, to align these images, I can apply margin-left to the spans.

    Do you have better advise to align these images?

    Thank very much for the help. It is greatly appreciated.

    Ty
     
    fAdEd247, Mar 14, 2010 IP
  6. fAdEd247

    fAdEd247 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    There's no way to edit previous threads?

    Update -

    I applied display:inline-block and this aligned my menu pretty well.

    Now if I could just get the submenu's to hover the image correctly... :confused:
     
    Last edited: Mar 14, 2010
    fAdEd247, Mar 14, 2010 IP