Thanks! I have had that problem with a few projects, but didn't know how to solve it so invariably I would have to scrap using a background colour. Now at least I know how to get it to work right.
[…] Matt Heerema has some useful tips for the “problem†that occurs when you are building a form with a fieldset tag and a legend tag, and then style the fieldset with a background color which ends up spilling outside of the fieldset. What to know how to fix it for IE? Head over and see what to do. […]
Hi, thanks for the great fix!!! I was wondering if you could give some additional advice. I'm nesting Fieldset and Legend and when I do so the Fieldset text overlaps when I implement this fix unless I do a line break in the XHTML. It's probably a simple margin fix, but I can't seem to figure it out. I don't want to use the because it creates too much room in FIrefox/Mozilla, etc.
[…] The main problem with events like CSS Reboot, et al, are that they serve as sort of a Total Perspective Vortex for me. It reminds me how far I have to go, and how much I have to learn. What keeps me from giving up is that I feel I have something to contribute to the noise. I just have to find my niche (solutions to strange CSS problems perhaps?) and write about it, constantly. […]
Another fix for this problem is to have a background image for the fieldset, 1 pixel wide and much taller than the fieldset will be. Does mean you have to change the image to change the colour though…
Actually the method does work in IE7. The Holly Hack however doesn't. The method works fine if you put the above in a seperate stylesheet and load it with a conditional comment.
OK. Solution is great but I have to insert 3 fieldsets one under one and now I have big trouble how to apply more or less the same margin between fieldsets in IE and Firefox.
[…] I was working on some CSS for a form and realized that applying a background to the fieldset didn’t really have the desired effect. The background flows out at the top of the fieldset in IE (what a surprise!). Luckily, I found a solution to the problem on Matt Heerema’s blog. Works like a charm! […]
[…] As most of you know, I have some kind of shoulder problem. I started seeing a physio November last year about it and have been having treatment since. A few weeks ago I hurt it at Kung Fu, and have been going easy since. Little did I know I had re-wrecked it. Its again out of commission for a month, so no swinging punches. Which is basically what Choy Lay Fut is all about. So ill have to think of something. Lucky for me, Bando has the thumbs up, due to its striking being very tight quick movements. So today, we did sparring. And I seem to be having trouble walking. Now its not every day I get hammered…. actually… I seem to get hurt a lot now I think about it… Hmmm… where was i going with this again…. oh yeah, I tend to not bruise very easily at all. If I do usually get them, they aer usually a few days later and kind of light. However… I got home no more than 3 hours ago and my shins are already getting darker. Good times. I seem to have a slight one appearing on my upper thigh after getting knocked on my ass by Mr Kroll. My only rehab at the moment is after any training, I have to ice the shoulder for ~10 mins. And it gets cold…. DAMN cold…. Anyway, on a less violent note, im starting to prepare for IE7. Not really getting excited, more reading up on how I will have to have the bastard to display CSS properly.. I have been doing a few more Accessible forms as of late and had just found a fix for fieldset background spillage in IE. From what I have read so far in preliminary preports and whatnot all hacks should work, and CSS should render better than before. Of course, this poses a problem. Do we change doing CSS to incorporate the fixes in this version, or would you still allow for IE6 users, making any updates completely irrelevant? Hmmm… I shalll ponder the conundrum over a bottle of water… Also, the Jets are on tomorrow at the Inglewood. Im quite tempted to go… Actually, im quite sure I will. […]
For the person asking about multiple fields. I ran into the same trouble. Messing with the margins wasn't getting me anywhere. I noticed someone said a br tag worked, but created too much space in FF/Opera. Well, if you use conditional comments it works beautifully.
Hopefully this comes through correctly (remove the spaces).
[…] mattheerema.com – Yet another interesting Blog entry I stumbled onto when researching HTML I think. This entry covers some interesting issues and behaviors of using the legend command in html on Internet Explorer. […]
[…] Zitat von Despairing 2. In meinem Gästebuch wird im Internet Explorer-Browser jedes Fieldset fehlerhaft dargestellt. Die Hintergrundfarbe des Fieldsets wird ein paar Pixel über der Fieldsetbox dargestellt, was nicht so sein sollte. Wie kann ich das unterbinden? Hatte ich letzhin gerade auch. Lösung siehe Getting Fieldset Backgrounds and Legends to Behave in IE – Matt Heerema : Web Design __________________ The only thing to do with good advice is pass it on. It is never any use to oneself. – Oscar Wilde – #me { position: absolute; } […]
Thanks for a brilliant solution. Me too found that this method applied "as it is" doesn't bring the desired result in IE7. However there seem to be another way around the problem – to put the above css rules (by Matt Heerema)into an IE condition comment.
<!–[if IE]>–>
fieldset { position:relative }
legend {
position:relative;
top:-0.7em; margin-bottom:-0.7em;
}
Usually I have such CSS pocket to store all the IE specific hacks in one place. Why not to drop there the discussed rules?
Found one problem with this method. In Safari, it draws the border all the way around the fieldset. Legend text is placed above the border, but still a bit of a problem.
[…] Test auch wirklich sehr gut funktioniert. Ich muss es nur noch auf mein Beispiel anwenden. Im Blog von Matt Heerema lässt sich dieses finden. Gru soyo __________________ Aktuelle Zertifizierung: MCP 70-270 In […]
With this kind of CSS PNG background, IE decides to crop the legend at the top of the fieldset. If you change the background to a normal background:#f00; type declaration, the legend displays as normal.
Regarding the comment by Giles, this problem also occurs when using a transparent PNG sans the MS filter hack. So, even if you support IE 7 only, you are screwed by IE once again.
That said, I cannot get any of the posted methods to work in IE 6 or 7. I still get a few pixels of bleed out the top. I stripped the styles down to nothing first to be sure the css applied to real browsers in my first style sheet were not causing issue. I'm glad others have had success, but I can no longer waste time on IE and have decided to display it plain and ugly. Sad, because that's what most users of my app use( corporate customers ). They'll never see the great design I had…
[…] Getting Fieldset Backgrounds and Legends to Behave in IE I’m sure someone has posted on this issue before I just haven’t found an answer I’m looking […]
[…] Getting Fieldset Backgrounds and Legends to Behave in IE I’m sure someone has posted on this issue before I just haven’t found an answer I’m looking […]
[…] For IE7, the background color doesn’t appear at all, which might actually be better than to have it appear incorrectly. So the appearance definitely won’t be as sharp for your IE users as for any other browser user. (Yet another reason to encourage your clients, friends, associates, neighbors and strangers on the street to avoid Internet Explorer. We can eliminate it in our lifetimes.) (UPDATE: there are, of course, work-arounds. Here are a few suggestions from Sitepoint and CommunityMX and Matt Heerema.) […]
The fundemental problem with fieldset legends is that they can’t be rendered using CSS to style them.
The way legends appear for fieldsets requires displaying partial transparencies just not supported by any CSS standard (they have to be transparent, but not to borders).
Thus each browser manufacturer has created their own solution to how to display fieldsets with legends.
The method here generally works but fails when certain borders are specified because IE still leaks a borders width above the top border.
The way to fix that problem is to not give the fieldset a top border and use a x repeating background image in it’s stead.
Thanks a lot for both tricks!
As mentionned by Fentex, after have applied the first trick, another problem was still there : the top-border of the fieldset that overflows to the right.
I simply deleted the top border and thanks to the background applied to my fieldset i don’t need to add any other trick!!
This is just perfect!
Thanks so much x)
[…] decided to test it out on the infamous fieldset – legend IE bug. The display issue came to my attention not by IE, which had been fixed using the usual […]
Leave a Reply