I came across this problem many times, eventually, as a result of abandoning the legendary tag until recently, when I started using it again to add more semantic meaning to semantic markup.
Here is a fix I developed to control the appearance of the layout of a legend tag regarding its siblings:
Markup:
<div class="fieldset"> <fieldset> <legend>Form Section</legend> <div class="field_row"> <label for="first_name">First Name</label> <input id="first_name" name="first_name" type="text"> </div> <div class="field_row"> <label for="last_name">Last Name</label> <input id="last_name" name="last_name" type="text"> </div> </fieldset> </div>
Styles:
.fieldset { padding-top:48px; position:relative; } legend { height:18px; left:15px; position:absolute; top:15px; }
In the above example, to reach the bottom โfieldโ in the <legend tag you want, you simply apply the top padding to the set of fields equal to the sum of the top and bottom fields you want plus the explicit height of the legend tag. This appropriately discards "brothers" and "take."
If you did not specify the height of your legend, you can simply check it on the Metric tab of the Firebug or Chrome Developer tools, as the font size will affect its height.
But yes, a fairly simple solution, I just came across it a few days ago when I was working on a client project. Then I came across this question, since today I tried to do more research.
Edit: after posting this answer, I realized that in my original patch, I applied the add-on to the parent <div> in the <fieldset>, because for some reason Firefox runs the top: 15px; from the bottom of the top margins when the overlay is applied to the <fieldset>. Room top and position: relative; on the parent div allowed <legend> to position absolutely above the padding instead of being pushed back off. I edited the code above to reflect my findings. This solution, which started simply, is now less attractive to me, but it definitely works. Here is the page I created by testing two methods for positioning the legend tag>: Positioning Legend tags: http://dl.dropbox.com/u/37971131/css-testing/forms.html
CSSDevMonkey
source share