Mawg
Mawg

Reputation: 40185

Should I style a DIV or its enclosed contents?

<div class="panel" id="Panel1">
<fieldset style="position: absolute; top:8px; left: 136px; width: 136px; height: 64px;">
<legend> </legend>
<div class="Label" id="Label1" style="position: absolute; top:8px; left: 16px; width: 81px; height: 14px;">Hello world</div>  
<div class="tLabel" id="Label2" style="position: absolute; top:32px; left: 16px; width: 54px; height: 14px;">A second piece of text</div>  
</fieldset>  
</div>

I am a CSS newbie and have googled & seen a lot of confllicting info on this.

If I want positioning, where does the style go? On the enclosing DIV? On the enclosed fieldset? On what the fieldset encloses? Some permutation thereof?


Do I even need an enclosing DIV around a FIELDSET?

Upvotes: 0

Views: 117

Answers (1)

Josh
Josh

Reputation: 511

A rule-of-thumb while creating CSS styles is that, as much as possible, it should be re-usable.

In the above example, you'd place the DIV absolutely using a CSS class and then position all the elements within the DIV relatively. You should (1) set the positions of the DIV, (2) remove the position of FIELDSET, (3) remove position of the inner DIV (ID=Label1), and (4) add a margin or padding to the inner DIV (ID=Label2).

Upvotes: 1

Related Questions