Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to achieve a <fieldset>-like effect without using the <fieldset> tag?

Tags:

html

css

fieldset

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.

example image of what I'm trying to achieve

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.

like image 932
zneak Avatar asked Feb 06 '10 17:02

zneak


People also ask

What can I use instead of Fieldset?

WAI-ARIA provides a grouping role that functions similarly to fieldset and legend . In this example, the div element has role=group to indicate that the contained elements are members of a group and the aria-labelledby attribute references the id for text that will serve as the label for the group.

Can you use Fieldset without form?

You can use any form elements outside of an actual form, since most of them can be used with JavaScript utilities outside the form. The form is only needed if you plan on allowing the user to submit the data with it.

Can I use legend without Fieldset?

You should not use the <fieldset> and <legend> when: You have a single form field that asks for a single piece of information.

What is the Fieldset tag used to achieve?

The <fieldset> tag is used to group related elements in a form. The <fieldset> tag draws a box around the related elements.


1 Answers

Demo jsBin link

.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>
like image 113
Mathias Bynens Avatar answered Sep 16 '22 15:09

Mathias Bynens