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>



OSX Mysql app: Sequel Pro|(1)

Generally these days I’m tending to access mysql from the CLI but when writing a data importer script I needed to be able to see what tables I was accessing from two different dbs. Initially I was looking for an ERD tool but I stumbled across the successor to CocoaMysql, Sequel Pro. It’s both well executed and free which makes it my kind of app!

Inline Code Finder|(0)

Robert Nyman has released a new and improved version of his inline js finder which now also locates inline styling as well as JavaScript. Inline code finder is a great way of identifying the kind of code that should always be avoided. More details can be found at Robert’s site. Plugins are available as standalone Firefox and Firebug extensions.

Photos on Flickr

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