开发者

Should I style a DIV or its enclosed contents?

开发者 https://www.devze.com 2023-01-17 01:29 出处:网络
<div class=\"panel\" id=\"Panel1\"> <fieldset style=\"position: absolute; top:8px; left: 136px; width: 136px; height: 64px;\">
<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="positi开发者_运维问答on: 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?


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消