Image link rollovers for dynamic (user-uploaded) graphics with Drupal and CSS

By Benjamin Melançon
on 01 Sep
0 comments

Key words and phrases

rollover with dynamic graphics jquery rollover drupal User-uploaded images for rollover links "css rollovers without background" drupal add css from a theme Drupal user-uploaded graphics for rollover user-provided rollover graphics rollover link for Drupal uploaded image files

Tags

Description

The goal: a CSS-only rollover graphic that can also be a link that is uploaded by users.

Eliminating other options:

This could be done with JavaScript, but we and the W3C and everyone's sanity would much prefer a pure CSS solution.

Can you have inline styles with pseudo classes (namely, :hover?)

No: http://www.frontpagewebmaster.com/m-351101/tm.htm

From http://www.christianmontoya.com/2006/02/01/pure-css-image-rollover/

a { display:block; height:50px; width:100px; overflow:hidden; }

a:hover { display:block; text-indent:-100px; }

drupal get image size
PHP get image size

http://us3.php.net/getimagesize

http://api.freestylesystems.co.uk/api/function/theme_imagecache/5

See below - update of this with code of final answer based on Christian Montoya's technique above (with warning about PNG in IE6).

Some bumps on the road to CSS-only rollovers

Sending style.css
Sending views-list-promo_badges_main.tpl.php

With junk test code-- doesn't work in ie6 (and the test code actually broke it in ie7)

a.promo-badge-hover {
  display:block;
  height: 120px;
  width: 480px;
  overflow:hidden;
  border: 1px solid black;
}

a.promo-badge-hover:hover {
  height: 120px;
  width: 480px;
  display:block;
  text-indent: -240px;
}

a.promo-badge-hover img {
  height: 120px;
  width: 480px;
  display: block;
  border: 2px solid red;
}

a { display:block; height:50px; width:100px; overflow:hidden; }

a:hover { display:block; text-indent:-100px; }

http://64.233.169.104/search?q=cache:nZqtXuHqFRkJ:www.christianmontoya.c...

Resolution

This is more or less the final touches on the Agaric Design's sidebar promotional graphics uploaded by the user views and cck and nodequeue technique.

/* begin Agaric era */

a.promo-badge-hover {
  display:block;
  height: 120px;
  width: 240px;
  overflow:hidden;
/*  border: 1px solid blue; */
}

a.promo-badge-hover:hover {
  height: 120px;
  width: 240px;
  display:block;
  text-indent: -240px;
}

 

Post new comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <small> <pre> <strike> <sub> <sup> <kbd> <s>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.