CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2001
    Location
    Las Vegas
    Posts
    539

    How 2 clip an area of an image on the fly ?

    Dear all.

    I've created a custom style for list items that uses an image:
    http://Yovav.com/Temp/ListItemImages.gif

    The problem is that when the list item is higher than 16 pixels the next image shows up (while it should be white)

    See the problem in this example:
    http://Yovav.com/Temp/ListItemImageProblem.gif


    I would like to be able to clip just the area I need for the image

    How can I do that ?



    This is the style I'm using:

    .CustomUL LI
    {
    background:url("../Images/Controls/ListItem/ListItemImages.gif") no-repeat 0px0px;
    list-style-type:none; /* circle */
    line-height:16px;
    margin-top:7px;
    margin-bottom:7px;
    padding-left:22px;
    }


    .CustomUL LI.SignVGray {background-position:0px-80px;}
    .CustomUL LI.SignVBlack {background-position:0px-96px;}
    .CustomUL LI.SignVRed {background-position:0px-112px;}
    .CustomUL LI.SignVGreen {background-position:0px-128px;}
    .CustomUL LI.SignVBlue {background-position:0px-144px;}


    And in the HTML:

    <ul class="CustomUL">
    <li class="SignArrowBlack">Test1</li>
    <li class="SignArrowBlack">Test1</li>
    <li class="SignArrowBlack">Test1</li>
    </ul>
    Last edited by Yovav; October 10th, 2008 at 12:03 AM.
    Best Regards - Yovav

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: How 2 clip an area of an image on the fly ?

    You can set the bounds and then hide the overflow.

    Code:
    display: block;
    height: 16px;
    overflow: hidden;
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Apr 2001
    Location
    Las Vegas
    Posts
    539

    Re: How 2 clip an area of an image on the fly ?

    Thanks for your help,

    When I'm limiting the height it also limits the text of the List Item element
    so for example - if it has 3 lines it will only show the first line (16 pixels high)

    I'm trying to limit the list item image while showing more that one line of text on the list...
    Best Regards - Yovav

  4. #4
    Join Date
    Jun 2005
    Posts
    1,255

    Smile Re: How 2 clip an area of an image on the fly ?

    I have searched, and I have found no solutions. There are not many options about background pictures. So, you could have several pictures instead of only one, or you could have a lot of spaces between each picture in your ListItemImage.gif file.

  5. #5
    Join Date
    Apr 2001
    Location
    Las Vegas
    Posts
    539

    Re: How 2 clip an area of an image on the fly ?

    Thanks for the reply,

    I also thought about this option,

    But I still wonder as I saw people using a one big image that includes all kind of images...
    Best Regards - Yovav

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: How 2 clip an area of an image on the fly ?

    Quote Originally Posted by Yovav
    I'm trying to limit the list item image while showing more that one line of text on the list...
    So, you can apply my same method to just the image itself.

    Code:
    <div style="display: block; height: 16px; overflow: hidden;"><img src="image1.png" alt="" /></div>
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  7. #7
    Join Date
    Aug 2005
    Location
    Imperial College London, England
    Posts
    490

    Re: How 2 clip an area of an image on the fly ?

    How about something along the lines of positioning the image in a sub element?
    HTML Code:
    <div style="width: 16px; height: 16px; overflow: hidden;">
      <div style="position: absolute; top: -100px; left: -100px; background-image: url('');">&nbsp;</div>
    </div>
    That should show pixels (101, 101)-(117, 117).
    Help from me is always guaranteed!*
    VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
    Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.

    *Guarantee may not be honoured.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured