I personally like the <fieldset>
tag because of how it draws a box and puts the <legend>
at the top of it, over the border. Like this.
However, the fieldset
element was made to organize forms, and using it for general design is no better than using tables for general design. So, my question is... how can I achieve the same result using another tag? The border has to be erased under the <legend>
(or whatever other tag will be used), and since there could be a "complex" body background image, I can't afford to just set the background-color
of the legend to match the one of the element under.
I'd like it to work without JavaScript, but CSS3 and XML-based formats (such as SVG or XHTML) are fine.
.fieldset {
border: 1px solid #ddd;
margin-top: 1em;
width: 500px;
}
.fieldset h1 {
font-size: 12px;
text-align: center;
}
.fieldset h1 span {
display: inline;
border: 1px solid #ddd;
background: #fff;
padding: 5px 10px;
position: relative;
top: -1.3em;
}
<div class="fieldset">
<h1><span>Title</span></h1>
<p>Content</p>
</div>