Bear in mind the example I'm providing isn't very user-friendly when it comes to forms due to the use of the universal selector, but if you're willing to redeclare the margins and padding on those elements you need to kill those properties on, it can be quite effective.
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>CSS Based Form Layout</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css" media="screen,projection">
* {
margin: 0;
padding: 0;
}
body {
background: #FFF;
color: #000;
font: normal 85%/140% "lucida console", tahoma, verdana, arial, helvetica, sans-serif;
letter-spacing: 1px;
padding: 0 1em;
}
h1 {
background: #FFF;
color: inherit;
font: bold 1.95em/2em georgia, garamond, "times new roman", times, serif;
}
#example-form {
padding: 0.5em 0;
}
#about {
float: left;
margin-right: 1em;
width: 30em;
}
#survey {
float: left;
width: 33em;
}
.fieldset {
background: #FFE;
border: 1px solid #000;
margin-bottom: 1.5em;
padding: 1em 0 0.5em 0.5em;
position: relative;
}
fieldset {
border: 0;
display: block;
}
legend span {
background: #CFC;
border: 1px solid #000;
color: #00C;
padding: 0 0.25em;
position: absolute;
top: -0.75em;
}
}
label {
margin: 0.25em 0;
vertical-align: middle;
}
#about label {
clear: left;
float: left;
padding-top: 0.1em;
width: 14em;
}
#survey label:hover {
background: #FFE;
color: #00F;
font-weight: bold;
}
input {
margin-bottom: 0.5em;
padding: 0 0.25em;
vertical-align: middle;
}
#about input {
background: #FCFBFA;
color: inherit;
width: 14em;
}
#survey input {
margin: 0 0.25em 0 0;
padding: 0;
width: auto;
}
select, textarea {
margin: 0.5em 0.25em;
}
select {
background: #FCFBFA;
color: inherit;
}
textarea {
background: #FCFBFA;
color: inherit;
padding: 0.5em;
}
textarea:active, textarea:focus, textarea:hover {
background: #FFF;
color: inherit;
}
.controls {
clear: left;
}
</style>
</head>
<body>
<h1>Semantic Forms with (X)HTML and CSS</h1>
<form action="#" id="example-form" method="post">
<div id="about">
<div class="fieldset">
<fieldset>
<legend><span>Basic Information</span></legend>
<label for="name">Your Name:</label> <input id="name" type="text" size="30" /><br />
<label for="email">Your Email Address:</label> <input id="email" type="text" size="30" />
</fieldset>
</div>
<div class="fieldset">
<fieldset>
<legend><span>What Is Your Favorite Color?</span></legend>
<select name="sections">
<option value="0">--select one--</option>
<option value="1">Black</option>
<option value="2">Blue</option>
<option value="3">Brown</option>
<option value="4">Green</option>
<option value="5">Grey</option>
<option value="5">Orange</option>
<option value="6">Purple</option>
<option value="7">Red</option>
<option value="8">White</option>
<option value="0">Yellow</option>
<option value="10">Other/No Preference</option>
</select>
</fieldset>
</div>
<div class="fieldset">
<fieldset>
<legend><span>Tell Us About Yourself</span></legend>
<div>
<textarea rows="10" cols="40"></textarea>
</div>
</fieldset>
</div>
</div>
<div id="survey">
<div class="fieldset">
<fieldset>
<legend><span>What browsers are installed on your computer?</span></legend>
<div>
<label for="msie"><input id="msie" type="checkbox" name="browser" value="Microsoft" /> Internet Explorer</label><br />
<label for="netscape"><input id="netscape" type="checkbox" name="browser" value="Netscape" /> Netscape Browser</label><br />
<label for="mozilla"><input id="mozilla" type="checkbox" name="browser" value="Mozilla" /> Mozilla FireFox</label><br />
<label for="opera"><input id="opera" type="checkbox" name="browser" value="Opera" /> Opera Web Browser</label><br />
<label for="konqueror"><input id="konqueror" type="checkbox" name="browser" value="Konqueror" /> Konqueror KDE</label><br />
<label for="safari"><input id="safari" type="checkbox" name="browser" value="Apple" /> Safari Web Browser</label><br />
<label for="another-browser"><input id="another-browser" type="checkbox" name="browser" value="Other" /> Something Else</label>
</div>
</fieldset>
</div>
<div class="fieldset">
<fieldset>
<legend><span>What do you use to build your Web sites?</span></legend>
<div>
<label for="golive"><input id="golive" name="editor" type="radio" value="Adobe GoLive" /> Adobe GoLive</label><br />
<label for="dreamweaver"><input id="dreamweaver" name="editor" type="radio" value="Macromedia Dreamweaver" /> Macromedia Dreamweaver</label><br />
<label for="frontpage"><input id="frontpage" name="editor" type="radio" value="Microsoft FrontPage" /> Microsoft FrontPage</label><br />
<label for="hand"><input id="hand" name="editor" type="radio" value="A Text Editor" /> Text Editor</label><br />
<label for="other"><input id="other" name="editor" type="radio" value="Other" /> Something Else</label>
</div>
</fieldset>
</div>
</div>
<div class="controls">
<input class="submit" type="submit" value="Submit Form" /> <input class="reset" type="reset" value="Clear Form" />
</div>
</form>
<div>
Copyright © 2006-2007, The Monster Under the Bed. All Rights To Scare
Unsuspecting Children Reserved.
</div>
</body>
</html>
Bookmarks