• " />
    • " />
      • "/>
        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

        • How to store a date/time in sqlite (or something similar to a date)
        • How to use custom font during html to pdf conversion?
        • Storing the preferred font-size in localStorage
        • mp4 embedded videos within github pages website not loading
        • Scrimba tutorial was working, suddenly stopped even trying the default
        • Is there any way to glow this bulb image like a real light bulb
        • With non-graphical maps in Leaflet, zoomDelta doesn't work
        • What can I do to improve my coding on both html and css
        • Uncaught TypeError: google.maps.LatLng is not a constructor at init (script.js:7:13)
        • Bootstrap modal not showing at the desired position on a web page when the screen size is smaller
        • Displaying a Movie List on a Website Using Jinja2 and Bootstrap
        • How to redirect to thank you page after submitting a Google form embedded into a Google Site?
        • Storing selected language in localStorage
        • Fences (parenthesis, braces) in HTML and MathML
        • Understanding Scroll Anchoring Behavoir

        Related Questions in CSS

        • How to use custom font during html to pdf conversion?
        • Storing the preferred font-size in localStorage
        • mp4 embedded videos within github pages website not loading
        • Is there any way to glow this bulb image like a real light bulb
        • What can I do to improve my coding on both html and css
        • Uncaught TypeError: google.maps.LatLng is not a constructor at init (script.js:7:13)
        • Bootstrap modal not showing at the desired position on a web page when the screen size is smaller
        • How to increase quality of mathjax output?
        • Hover animation resetting( seemingly reverting back to original CSS and then again to hover)when moving mouse horizontaly accross a part of an element
        • Storing selected language in localStorage
        • How to clip grid cell and provide scroll as well?
        • KeyboardAvoidingView makes a messy the flexbox
        • Rotate an object around another object in javascript
        • Understanding Scroll Anchoring Behavoir
        • how to use only block layout in this css code?

        Related Questions in ROLLOVERS

        • Roll Over Images not Functioning in one Column
        • Rollover calling image from array
        • Rollover images when mouseover
        • Roll overs in interactive pdfs for iPad—nothing is working
        • Getting <div> to be displyed in the heading tag
        • Change images "src" on hover, inside a div
        • Duplicate JS Code Overrides Map Hover Effect
        • Targeting a g id in an SVG for rollovers
        • picture element srcset responsive image rollovers
        • Rollover very slow
        • Cannot position image rollovers on page
        • jQuery rollover and css :hover
        • Multiple Styles of Rollover Links
        • I am new to JQuery and I am trying to create a roll over effect, with the intention of doing this for links.
        • jquery rollover , show and hide

        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 node.js arrays c asp.net json

        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
        • Pricesm.com
        • Aftereffectstemplates