I've got a form that I'm trying to layout semantically and format with CSS. As it's produced dynamically (from ASP.NET MVC) some elements may be rendered as text rather than input tags as they may be read-only for that screen. I am trying to add a width to the label tags to neaten up the form and align the values/value boxes, but it seems I can only do this if I float them (is that correct?). That works OK for when I have rendered values after the label tag, but if the value is blank the left float seems to stack against the previous label, even though both are contained within p tags (these should be block level, yes?). What, if anything, am I doing wrong?
<!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">
<head><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" /><title>
Edit
</title>
<!-- Next Style Section Is Just To Set Up Classes, it will be moved to .CSS file -->
<style type="text/css">
div.FieldGroup {background-color: Blue; }
p.Field { display: block; }
span.NoteHeader { font-style: italic;}
label { float: left; width: 150px;}
</style>
</head>
<body>
<div id="main">
<h2>Edit</h2>
<form action="" method="post">
<div id="MainSection" class="FieldGroup">
<fieldset>
<legend>Person Identification</legend>
<p class="Field">
<label>Name:</label>
Name
</p>
<p class="Field">
<label for="Colour">ChildStatus:</label>
<select id="Colour" name="Colour">
<option value="10">Red</option>
<option value="20">Yellow</option>
<option selected="selected" value="30">Orange</option>
</select>
</p>
<p class="Field">
<label for="Age">Age:</label>
<input id="Age" name="Age" type="text" value="" />
</p>
<p class="Field">
<label>Birthplace:</label>
</p>
<p class="Field">
<label for="Reference">Reference:</label>
<input id="Reference" name="Reference" type="text" value="" />
</p>
</fieldset>
</div>
</form>
</div>
</body>
</html>
Cheers
MH
(P.S. - I can't add in readonly textboxes to contain these blanks as they want plain text if they can't change the value)