Note that there are some explanatory texts on larger screens.

plurals
  1. POImage Rollover, no Javascript, no Link, pure CSS, code validate and Broswer compatible
    primarykey
    data
    text
    <p>Image Rollover, no JavaScript, no Link, pure CSS, code validate and Browser compatible.</p> <p>Hello all, I have been working 24hours strait to come up with this fairly easy solution. I want to know if everything is all right and if there are ways to improve. It's quite elegant, here we go:</p> <p>I have only one image "Logo" but it will show as 2 different logo each with a rollover effect. I use a sprite (only 1 image containing my 4 logos) and I just change it's position.</p> <p>Here I insert my image in a div with</p> <pre><code>&lt;div id="logo-rollover-1" class="logo-rollover"&gt; &lt;img title="whatever" alt="whatever" src="path-to-your-image"&gt; &lt;/div&gt; </code></pre> <p>Then I insert in another div the same image but with a different id</p> <pre><code>&lt;div id="logo-rollover-2" class="logo-rollover"&gt; &lt;img title="whatever" alt="whatever" src="path-to-your-image"&gt; &lt;/div&gt; </code></pre> <p>Now my CSS:</p> <pre><code>.logo-rollover { background: #ffd42a url('path-to-your-image'); width: 230px; float: left; height: 130px; overflow: hidden; position: relative; } .logo-rollover img { width: 460px; height: 260px; } .logo-rollover :hover { opacity: 0; filter:alpha(opacity=0); } #logo-rollover-1 { background-position: 0px -130px; } #logo-rollover-2 { background-position: -230px -130px; } #logo-rollover-2 img { right: 230px; position: relative; display: block; } </code></pre> <p>Explanations: when someone hover an image it becomes transparent and show the background witch is the same image but with a different position. opacity: 0 for Firefox, Google and filter:alpha(opacity=0) for Explorer. position: relative on the .logo-rollover class is for compatibility of hidden overflow with IE6 &amp; IE7. display:block; is added to the id img for the Opera browser.</p> <p><strong>No Hack:</strong> When there is no link, there is no need for href="#" or "javascript:void(0)"</p> <p>Advantages: instead of requesting 4 (or more) images, there is only 1 image (the total size of 1 image sprite is smaller then the total size of 4). the rollover is instant as the image is already downloaded. No hack, no false link, code validate. Add a title to the image. The only browser not rolling over is IE6 but the site is not broken, the logo show correctly. There is a hack for activating hover for IE6 but I didn't bother as IE6 is dead.</p> <p>Tip: use the same path for your image everywhere. I mean the "path-to-your-image" needs to be the same for all call. Because of browser caching.</p> <p>Is this the best elegant way? Can this code be improve? I hope it will help someone because it was a real pain to develop thank to others user here I found some tricks here and there and came up with this.</p> <p>Comment appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload