Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: CSS Image Gallery Hover Always

  1. #1
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default CSS Image Gallery Hover Always

    1) Script Title: CSS Image Gallery

    2) Script URL (on DD): http://www.dynamicdrive.com/style/cs...gallery/#thumb

    3) Describe problem: The hover state stays on, when the mouse is above the image (anywhere above it) I think it is from the padding top I added because its reading the padding as part of the image for some reason something like this

    | |

    | Padding |

    | |
    | image| <---mouse off anywhere below here has the overlay go away
    | Overlay |

    http://www.esefdenim.com/gal.php
    Last edited by bluewalrus; 12-24-2008 at 05:23 AM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    In FF's developer tools at least, changing to:

    Code:
    .thumbnail span{ /*CSS for enlarged image*/
    margin-top:15%;
    position: absolute;
    left: -1000px;
    height:55%;
    width:55%;
    visibility: hidden;
    color: black;
    text-decoration: none;
    }
    Takes care of the problem. However, if that won't work in other browsers (I'm leaving it to you to test that, or to provide a demo with the change hard coded into it for me to test), it might be better to abandon both padding and margin, and to set a pixel or em top property, for example:

    Code:
    .thumbnail span{ /*CSS for enlarged image*/
    position: absolute; /* Comment: margin and/or padding removed */
    left: -1000px;
    height:55%;
    width:55%;
    visibility: hidden;
    color: black;
    text-decoration: none;
    }
    and then (the exact number and/or units used may vary as per your preference):

    Code:
    .thumbnail:hover span{ /*CSS for enlarged image*/
    visibility: visible;
    top: 170px;
    left: 230px; /*position where enlarged image should offset horizontally */
    z-index: 50;
    }
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    bluewalrus (12-20-2008)

  4. #3
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Yup you got it. Although in sarfai its displaying off by like 15 pixels for some reason ff, flock, and oprea its fine though, those are all the browsers i can test on, I'm a mac(er).

  5. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Percentage margins and/or padding are sometimes unreliable cross browser because each browser determines for itself what the percentage is a percent of, and it may also depend upon how much room there is in the region that the browser decides to take the percentage from. This can vary due to browser peculiarities, and also from the size of the browser window. If the exact placement isn't critical, this can often be a viable strategy though. On the other hand, if you must have pixel perfect symmetry across as many browsers as possible, my second suggestion would probably be more effective. The distance from the top of the window of the enlarged image visa vis the position of the thumbnails will however always depend to a certain extent upon how far the thumbnails are from the top of the window in that browser.

    Edit: Since the distance of the thumbnails from the top appears to vary with the size of the browser window, you will either have to be more specific about the thumbnail's location, or accept some variation in where the larger images appear in relation to the thumbnails
    Last edited by jscheuer1; 12-20-2008 at 09:56 PM. Reason: add info
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. The Following User Says Thank You to jscheuer1 For This Useful Post:

    bluewalrus (12-21-2008)

  7. #5
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Oh Oh okay thanks

  8. #6
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    It was working fine but I just uploaded this other image and it is being stretched horizontally. I have the height and width set to 55% which i thought would keep the images original proportions the same. Is this incorrect as well, or is there a more standard way of sizing images when you do not know all of the images sizes? Thanks again for any other suggestions you can offer.

  9. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    There are other ways of scaling images (with the browser*), but it can get quite complicated. For something like this, the easiest method would probably be best. That is to set only one dimension, either the width or the height. In a case like that, the browser will almost always scale the other dimension. You must make sure that no other style or attribute interferes though.


    *scaling (down images) with the browser is inefficient, and depending upon the situation (like if the full size image is never shown) can waste disk space, and always increases page load time when a scaled down larger image is standing in for a thumbnail version. Browser scaled images can lack resolution compared to those scaled to size in an image program. However, even with all that, if care is taken to do things in the most logical (from the point of view of minimizing load times as much as possible) manner it can be a form of preloading, and work out fairly well.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. The Following User Says Thank You to jscheuer1 For This Useful Post:

    bluewalrus (12-22-2008)

  11. #8
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    You've solved it again. Thanks is there a way to set the position to be where the mouse is? Right now the margin-top is not working on the second row and if i set it too it won't work for the first. I want the image to be centered from where the mouse is on the image. I know the margin top and the left absoulte are setting this off right now but didn't know if there was anyway to have it center on the image like 15 pixels below so some of it would also still be visible. Thanks again.

  12. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Well, the idea is to arrange things so that the larger images don't overlap the thumbnails. The way you have it now, there's not room enough for that. Another strategy might be to forget about the gallery container, make the .thumbnail class position relative, so that the larger images will be absolutely positioned relative to the thumbnail link. There are many possibilities. But there is no way with this setup to follow the mouse, css style just won't allow for that. A javascript could be used, in fact my new Expando (just adopted to the Dynamic Drive Library) could be used. It will not follow the mouse, but if each image is absolutely positioned inside its own relatively positioned division of limited size, the effect can be quite nice, because the images wouldn't push each other around the way that they do on the demo page. But it would no longer have the advantage of this viewer, which is not requiring javascript.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  13. The Following User Says Thank You to jscheuer1 For This Useful Post:

    bluewalrus (12-22-2008)

  14. #10
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Okay, I like the expando script and look. I've put it in pulled out the css image gallery. The page already uses javascript else where so adding another one won't be a problem. Is the script written so that it expands till it reaches the original size and if so is that changeable (can css's height and width be used in place of the img tag height and width or does it read that tag)?

    So I should make each thumbnail in it's own div with relative positioning (I pulled out the.thumbnail class) for the expand to just go over the others?

Bookmarks

Posting Permissions

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