Forum Moderators: open
Googling this question, some people seem to think it's legal.
Does anyone here know for sure? Can we get an official/definitive answer?
Now as to intend, that's harder to determine, it feels to me to be intended to be used in forms only. I don't know why it got the far wider scope.
Also note that -despite the CSS standard not stating it should- a fieldset creates a new stacking context (logical if you think about it and the default way it's rendered, but not mentioned in the standard AFAIK).
IMHO extensive use of it outside forms and/or reliance on the new stacking context are dangerous if you want future proof code.
Note this is one of those cases where legacy IE versions completely miss the ball (and probably a reason so few know how it should work).
Block formatting context is how the standard describes it:
[w3.org...]
[w3.org...]
[w3.org...]
If you ever wondered why a normal border goes under a float while a fieldset's border doesn't, this is why.
I'd use them like a div because the formatting is pretty cool and requires much
less code than grouping them w/ a div and having the label appear over and in
middle of the top line using css.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css"><title></title>
<style type="text/css">
#fieldset {
width:400px;
border:3px double #999;
padding:20px;
margin:50px auto;
font-size:1em;
}
#fieldset span{
position:relative;
padding:4px 8px;;
border:1px solid #999;
top:-30px;
left:20px;
background-color:#fff;
font-size:0.9em;
color:#300;
}
#fieldset p {
margin:-10px 0 0;
}
</style></head>
<body><div id="fieldset">
<span >Lorem ipsum</span>
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin massa. Nam vehicula.
Morbi velit nisi, mollis id, ultrices luctus, adipiscing sit amet, lectus. Nunc rhoncus
nisl ac enim. Maecenas vestibulum dolor ut velit. Maecenas condimentum pulvinar purus.
Pellentesque ac ipsum. Curabitur sodales, elit vel molestie hendrerit, elit odio rhoncus tellus,
nec gravida enim urna id velit. Donec nec tellus. Vestibulum nulla. Curabitur enim arcu,
ornare id, placerat eget, nonummy vitae, mauris. Nulla rutrum semper odio. Duis vulputate
ornare mauris. Praesent eget nibh sed ante ultricies scelerisque. Duis eget felis ut arcu porta
bibendum. Mauris rutrum. Vivamus consectetuer purus sit amet mi. Suspendisse eu augue.
</p></div>
</body>
</html>
No problem, you're very welcome. ;)
And then obviously use absolute positioning on the span inside.
Added bonuses would be to not have the space originally reserved for the span to be empty and the ability to have the span anywhere in the parent, no need to have it at the top).