Muffinresearch Labs by Stuart Colville

CSS2 text-decoration and child elements | Comments (2)

Posted in CSS on 9th March 2009, 12:40 am by Stuart

Take the following code; will the text in the span be underlined?

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>Span Underline Test</title>
	<style type="text/css" media="screen">
	   p{
	       text-decoration: underline;
	   }
	   p span {
	       text-decoration: none;
	       color: green;
	   }
	</style>
</head>
<body>
    <p class="test">This is underlined.<span> Is this underlined?</span></p>
</body>
</html>

Chances are you’ll be thinking (like I did) that the text within the span won’t be underlined but you’d be wrong. Really – try it for yourself.

Finding the behaviour odd I dug up the specs for text-decoration.

This property describes decorations that are added to the text of an element. If the property is specified for a block-level element, it affects all inline-level descendants of the element. If it is specified for (or affects) an inline-level element, it affects all boxes generated by the element. If the element has no content or no text content (e.g., the IMG element in HTML), user agents must ignore this property.

What it doesn’t say is whether inline elements can override the behaviour, though as the spec states this isn’t an inheritable value and it would seem this is why the rule for the span has no effect.

Perhaps unsurprisingly Firebug also mis-interprets the value of the span making the assumption that text-decoration can be overriden. (Update 03/04/09: Bug raised)

The good news is ie6/7, firefox, safari and opera are all consistent in their handling of this oddity.

Post Tools

Comments: Add yours

1. On March 9th, 2009 at 11:38 pm Andy Hume said:

Rare that I’ll link to something I write over five years ago, as I normally cringe in embarrassment. But in this case:

http://usabletype.com/css/text/decoration/

2. On March 9th, 2009 at 11:45 pm Stuart Colville said:

@Andy: hehe nice. Clearly I’m late to the party on this one.







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.576s.