Welcome to WebmasterWorld Guest from 54.224.17.208

Forum Moderators: not2easy

Message Too Old, No Replies

CSS Pseudo-elements and the <label> tag

     
7:55 pm on Apr 10, 2003 (gmt 0)

10+ Year Member



I'm trying to use the first-letter Pseudo-element on the <label> tag to make the first letter of a form element's label bold and underlined, in order to corespond with the access key for that form element. I know that pseudo-elements aren't supported by all browsers, but I've been able to use the first-letter Pseudo-element in IE6, Mozilla and Opera 7, but can't get it to work when associated with the <label> tag. Here's some sample code:

label:first-letter {
font-weight : bold;
text-decoration : underline;
}

<form>
<label for="name" accesskey="n">name</label> <input type="text" id="name" tabindex="1">
</form>

If I set up the same pseudo-element for, say, a paragraph tag (P:first-letter), it works...

Any ideas on what I'm missing?

Thanks!

9:52 pm on Apr 10, 2003 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Works

*:first-letter {
color: #00f;
}

<form>
<label for="name" accesskey="n">name</label> <input type="text" id="name" tabindex="1">
</form>



Does not work

label:first-letter {
color: #00f;
}

<form>
<label for="name" accesskey="n">name</label> <input type="text" id="name" tabindex="1">
</form>



Works

.lbl:first-letter {
color: #00f;
}

<form>
<label class="lbl" for="name" accesskey="n">name</label> <input type="text" id="name" tabindex="1">
</form>

10:14 pm on Apr 10, 2003 (gmt 0)

10+ Year Member



Thanks for the tip, DrDoc.

I tried hanging a class on the label tag like you suggested, but with no luck. I think I've been looking at this so long, I might be overlooking an obvious mistake. Here's the code I've been working with:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled</title>
<style type="text/css">
.lbl:first-letter {
color: #00f;
}
</style>
</head>
<body>
<form>
<label class="lbl" for="name" accesskey="n">name</label> <input type="text" id="name" tabindex="1">
</form>
</body>
</html>

If you (or anyone else) sees a problem, I'd really apreciate the help.

Thanks again!

10:36 pm on Apr 10, 2003 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Seems like I was wrong in my earlier post. I can't possibly recreate what I did...

However, I should only work for block-level elements:

[w3.org...]

The :first-line pseudo-element can only be attached to a block-level element.
10:36 pm on Apr 10, 2003 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



label {
display: block;
float: left;
}
label:first-letter {
color: #00f;
}
10:38 pm on Apr 10, 2003 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



*:first-letter {
color: #00f;
}

...works no matter if label is block-level or not. (At least in IE)

2:42 pm on Apr 11, 2003 (gmt 0)

10+ Year Member



DrDoc,

Thanks! Setting the display for label to block did the trick.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month