很多时候,当我设计时,我在思考这个问题:
应该用div包装哪些html元素?在哪些情况下?
(<img>,<input>,<textarea>,<form>, <ul>等等..)
option1没有div:
<input class="input-wrapper" type="text" />
Run Code Online (Sandbox Code Playgroud)
option2 with div around input:
<div class="input-wrapper"><input type="text" /></div>
Run Code Online (Sandbox Code Playgroud)
option1没有div:
<img class="image-wrapper" src="MyPic.jpg" alt="my pic" />
Run Code Online (Sandbox Code Playgroud)
option2 with div around input:
<div class="image-wrapper"><img src="MyPic.jpg" alt="my pic" /></div>
Run Code Online (Sandbox Code Playgroud)
我说的是作为设计师和程序员我们有时间利用位置做到最好的情况:相对绝对,浮动和没有<br/>等等.
谢谢
Lot of times, you use the div to wrap around other elements mostly for layout purposes. There is no rule which says you should not wrap div's around elements or not. Echoing wb's answer over here may be most of the time you can achieve the same result with applying the styles to the particular elements itself.
Me when started with css, used a lot of div's as a wrapper, although they where not useful. But it took some time to get used to get the proper layout with appropriate tags and styles.
Some links might be useful reads
http://www.apaddedcell.com/div-itis#
http://www.smashingmagazine.com/2009/04/08/from-table-hell-to-div-hell/