• " />
    • " />
      • "/>
        DEVHIDE
        • Home (current)
        • About
        • Contact
        • Cookie
        • Home (current)
        • About
        • Contact
        • Cookie
        • Disclaimer
        • Privacy
        • TOS
        Login Or Sign up

        CSS Image Rollovers

        542 Views Asked by dcolumbus At 17 June 2010 at 01:16 2025-12-05T16:44:12.263000
        <div id="navigation>
            <ul class="navlist">
                <li><img src="images/btn1.gif"/></li>
                <li><img src="images/btn2.gif"/></li>
                <li><img src="images/btn3.gif"/></li>
            </ul>
        </div>
        

        How would I be able to give these "buttons" within the list rollover states without using JS? I'm totally drawing a blank...

        These links must be images.

        html css rollovers
        Original Q&A
        3

        There are 3 best solutions below

        2
        wsanville wsanville On 17 June 2010 at 01:28 BEST ANSWER

        If you're supporting newer browsers (browsers that support the :hover selector on all elements, which is basically everything except IE6, see here) you can do this with CSS provided you change your HTML. You will need to remove the img tags, and instead use background images.

        CSS (this is the simple example with 2 images, you'll need to set the height + width. If you have many different images, you'll need a css class for each of them):

        <style type="text/css">
            .navlist li { width: 32px; height: 32px; background-repeat: no-repeat; background-image: url('images/image1.gif'); }
            .navlist li:hover { background-image: url('images/image2.gif'); }
        </style>
        

        HTML:

        <div id="navigation">
            <ul class="navlist">
                <li></li>
                <li></li>
                <li></li>
            </ul>
        </div>
        
        2
        Peter Ajtai Peter Ajtai On 17 June 2010 at 01:22

        There's a lot of ways to do this. Basically, move one image off the screen when you hover. Or you could change the z-index of two images on top of each other when you hover, or you could do it with background images, or with the display option.

        I prefer using the display option, since the CSS is quite simpple.

        Since it's done with classes you can just add as many buttons as you want.

        Here's the code for a page that contains the HTML and CSS together. The DOCTYPE declaration is necessary to make it work in IE

        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/\xhtml1/DTD/xhtml1-strict.dtd">
            <head>
                <style type="text/css">
                    a img {
                        border:none;
                    }
                    ul {
                        list-style-type: none;
                    }
                    img.defaultSt {
                        display: inline;
                    }
                    img.hoverSt {
                        display: none;
                    }
                    li:hover img.defaultSt {
                        display: none;
                    }
                    li:hover img.hoverSt {
                        display: inline;
                    }
                </style>
            </head>
            <body>
                <div id="navigation">
                    <ul class="navlist">
                        <li>
                            <img class="defaultSt" src="http://mrg.bz/vh60HV" />
                            <img class="hoverSt" src="http://mrg.bz/CcDOmL" />
                        </li>
                    </ul>
                </div>
            </body>
        </html>
        
        0
        Joel Etherton Joel Etherton On 17 June 2010 at 01:23

        You could try using a transparent image as the link primary and then use css to alter the background

        <style type="text/css">
            a.img1, a.img1:link { background-image: url(images/btn1.gif); }
            a.img1:hover { background-image: url(images/btn1_over.gif); }
        
            a.img2, a.img2:link { background-image: url(images/btn2.gif); }
            a.img2:hover { background-image: url(images/btn2_over.gif); }
        
            a.img3, a.img3:link { background-image: url(images/btn3.gif); }
            a.img3:hover { background-image: url(images/btn3_over.gif); }
        </style>
        
        <div id="navigation>
            <ul class="navlist">
                <li><a class="img1" href=""><img src="images/transparent_image.gif" width="x" height="y"/></a></li>
                <li><a class="img2" href=""><img src="images/transparent_image.gif" width="x" height="y"/></a></li>
                <li><a class="img3" href=""><img src="images/transparent_image.gif" width="x" height="y"/></a></li>
            </ul>
        </div>
        

        You just have to keep in mind the size of the images in question.

        Related Questions in HTML

        • Delay in loading Html Page(WebView) from assets folder in real android device
        • Why does a function show up as not defined
        • CSS Class is not applying to element (border width,color,and style attributes)
        • How to sort these using Javascript or Jquery Most effectively
        • how to fill out the table with next values in array with one button
        • Automatically closing tags in form input?
        • Positioning child at bottom of parent with scroll
        • Remove added set of rows
        • Website zoomed out on Android default browser
        • Twitter Bootstrap horizontal form elements on a line
        • http://sigmajs.org/ les mis tutorial - why are my canvases 0 height?
        • My navbar is not expanding after collapse
        • when a checkbox is checked how to display a different hidden element using javascript
        • Gaps Vertically Using Dividers
        • Svg containers not positioning properly

        Related Questions in CSS

        • CSS Class is not applying to element (border width,color,and style attributes)
        • How do I find the fonts that are not loading in a CORS situation ( MoovWeb )?
        • Positioning child at bottom of parent with scroll
        • Play multiple audio files in a slider
        • How to set text over image?
        • Website zoomed out on Android default browser
        • Writing/Overwriting to specific XML file from ASP.NET code behind
        • My navbar is not expanding after collapse
        • when a checkbox is checked how to display a different hidden element using javascript
        • Gaps Vertically Using Dividers
        • CSS: Preventing a property to affect on element until the end of transition
        • Polygon Button with pure CSS
        • transform-origin doesnt apply in safari
        • show/hide multiple div tags at once and change the size of the remaining div tag
        • Mask the image/maps/div (circle) using css and jquery

        Related Questions in ROLLOVERS

        • Change images "src" on hover, inside a div
        • Getting <div> to be displyed in the heading tag
        • Lightbox opens but image doesn't show up
        • Link Inside <li> No Working
        • Multiple Styles of Rollover Links
        • Rollover very slow
        • How do I make this mouseover effect? with hopefully jquery
        • JQuery, how to apply the same mouseover effect to multiple divs with the same classes? help please?
        • jQuery rollover with some php
        • JSON as HTML data in Flex - Hyperlink Rollovers
        • Roll over/in on only one element in jQuery
        • Roll Over Images not Functioning in one Column
        • bg block colour rollover
        • Link a JS rollover image
        • Still having troube with jquery Image rollovers

        Trending Questions

        • UIImageView Frame Doesn't Reflect Constraints
        • Is it possible to use adb commands to click on a view by finding its ID?
        • How to create a new web character symbol recognizable by html/javascript?
        • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
        • Heap Gives Page Fault
        • Connect ffmpeg to Visual Studio 2008
        • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
        • How to avoid default initialization of objects in std::vector?
        • second argument of the command line arguments in a format other than char** argv or char* argv[]
        • How to improve efficiency of algorithm which generates next lexicographic permutation?
        • Navigating to the another actvity app getting crash in android
        • How to read the particular message format in android and store in sqlite database?
        • Resetting inventory status after order is cancelled
        • Efficiently compute powers of X in SSE/AVX
        • Insert into an external database using ajax and php : POST 500 (Internal Server Error)

        Popular # Hahtags

        javascript python java c# php android html jquery c++ css ios sql mysql r reactjs

        Popular Questions

        • How do I undo the most recent local commits in Git?
        • How can I remove a specific item from an array in JavaScript?
        • How do I delete a Git branch locally and remotely?
        • Find all files containing a specific text (string) on Linux?
        • How do I revert a Git repository to a previous commit?
        • How do I create an HTML button that acts like a link?
        • How do I check out a remote Git branch?
        • How do I force "git pull" to overwrite local files?
        • How do I list all files of a directory?
        • How to check whether a string contains a substring in JavaScript?
        • How do I redirect to another webpage?
        • How can I iterate over rows in a Pandas DataFrame?
        • How do I convert a String to an int in Java?
        • Does Python have a string 'contains' substring method?
        • How do I check if a string contains a specific word?
        .

        Copyright © 2021 Jogjafile Inc.

        • Disclaimer
        • Privacy
        • TOS
        • Homegardensmart
        • Math
        • Aftereffectstemplates