Muffinresearch Labs by Stuart Colville

Partial Image Replacement | Comments (5)

Posted in CSS on 29th January 2006, 1:41 am by Stuart

Recently Tim was looking for opinions on the most semantic way to mark up the title and strapline of an author’s website that he is working on. The text looked something like this; Stuart Colville, Author of "I’m a big fat monkey" (Note: this is a fictitious title).

Now the question was, how should the strapline (Author of “I’m a big fat monkey”) be marked up in a meaningful way? After a while of talking it through I suggested that the best way would be to including the strapline in with the heading as they have a relationship to one another. To move the strapline out of the h element would destroy the relationship. So the mark-up ended up looking like this:

<h1>Stuart Colville, <span>Author of "I'm a big fat monkey"</span></h1>

The Experiment

Now I was then interested to know if you could use image replacement to replace the h1 whilst leaving the span on screen as text. I tried a little experiment and came up with the following CSS:


  #content h1
  {
    text-indent: -3000px;
    overflow: hidden;
    background: url(scolville.gif) no-repeat;
    height: 100px;
    position: relative; /* optional: remove this if you need to position the span relative to the page rather than relative to the h1 */
  }

  #content h1 span
  {
    text-indent: 0;
    position: absolute;
    top: 75px;
    left: 50px;
    font-style: italic;
    font-size: 80%;
  }

Using the original Phark method I replaced the text within the h1 with a ‘tasty’ logo and then to counter the text-indent I used absolute positioning on the span thus moving back into view. Now this looked to be the answer first of all but this didn’t work at all in IE. After a little futher experimentation I ended up zeroing the text-indent first and used absolute positioning to move the span into position.

Example

The results can be viewed here in this example and works in IE6, Opera, Firefox and Safari.

Update: Tim made a useful suggestion to add "position:relative" to the h1 so that the span is relative to that rather than to the page. I have updated the code to reflect this change.

Post Tools

Comments: Add yours

1. On January 29th, 2006 at 2:06 am Xaprb said:

Very interesting technique. You left the .com out of the link to your example though.

2. On January 29th, 2006 at 2:20 am Stuart Colville said:

@Xaprb: Well spotted : ) the url’s fixed now.

3. On January 29th, 2006 at 11:39 am Marcel Fahle said:

Very nice! Bookmarked :)

4. On February 9th, 2006 at 8:27 am Tim said:

We have a lot of these discussions, don’t we Stu?

Further to this particular one, I’ve been using the Phark-Muff method and have discovered a slight glitch:

It’s actually incredibally benefitial to place "position: relative;" on the h1 tag to allow the strap-line to be positioned relative to that, rather than the containing element.

Just a thought – up to you whether you want to add this to your post. :)

5. On February 9th, 2006 at 9:18 am Stuart said:

@Tim: Good idea Timbo, I agree with you that positioning the span relative to the h1 is likely to be more useful 99% of the time so I have updated the code.







XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>



Using Loggerhead with mod_wsgi|(0)

Here’s a post I wrote over on the Project Fondue Blog about our use of Loggerhead with mod_wsgi under Apache. Loggerhead is the rather nice branch viewer for bazaar branches as used on Launchpad.net.

If you’re not already subscribed to the Project Fondue blog feed then I can recommend it, as there should be some interesting posts coming out of there in the coming months (yes I’m unashamedly biased!).

Ubuntu: Turn off changing workspace with mouse wheel|(1)

I found the changing with the workspace with the mouse wheel really annoying. To disable it go to System => Preferences => CompizConfig (available if the compizconfig-settings-manager package is installed) and uncheck “Viewport Switcher” which is under the “Desktop” heading.

Photos on Flickr

© Copyright 2004-10 Stuart Colville, all rights reserved. May contain traces of Muffin. Powered by WordPress. Hosting by Slicehost.com This page was baked in 0.824s.