I have a feeling that this is a subjective question, but perhaps there's something somewhere on the interwebs that has attempted to standardize this already and I'm just not aware of it (but someone else who will post here is).
Just a note: Please disregard any errors or omitted element attributes as I'm looking for suggestions solely regarding the authoring of the .css file itself. Both methods work. However, I personally prefer .css B as it seems more correct, but maintenance can be a pain if you're working with nested divs whos parents change class names.
Let's say I have a simple form on a page contained inside a div
container. The form has two three fields: two input text boxes and one textarea (from, subject and message).
Which would be the more "semantically correct" CSS to accompany the following form:
<div id="contact">
<form action="/index.php/forms/contact" method="POST">
<label for="txt_replyto">From:</label><input type="text" id="txt_replyto"></input>
<label for="txt_replyto">Subject:</label><input type="text" id="txt_subject"></input>
<label for="txt_replyto">Message:</label><textarea id="txt_msg"></textarea>
</form>
(.css A)
<style>
div#contact { width: 350px; }
div#contact form { width: 100%; }
div#contact label { float: left; width: 20%; text-align: right; }
div#contact input { margin-left: 1%; width: 79%; float: left; }
div#contact textarea { margin-left: 1%; width: 79%; float: left; }
</style>
or
(.css B)
<style>
div#contact { width: 350px; }
div#contact form { width: 100%; }
div#contact form label { float: left; width: 20%; text-align: right; }
div#contact form input { margin-left: 1%; width: 79%; float: left; }
div#contact form textarea { margin-left: 1%; width: 79%; float: left; }
</style>
Are there any pre-defined standards for this sort of thing (Google'ing it didn't yield much), or is it solely personal preference?
Edit: Thar. Updated based on Jack's reminder :)