Say I have a div
. If I give it a height and width of 500*500px in HTML code, like this: <div width="500px" height="500px">test</div>
it will not have dimensions of 500*500px unless it's filled with enough code/text to push it to those dimensions. However, if I set the exact same width and height with CSS (either inline CSS or external document) like this: <div style="width:500px; height:500px;">test</div>
the dimensions are always what I set.
Why is there a difference?
div
标签没有属性width
和height
。
Doing this isn't valid syntax. You cant add width & height attributes to a DIV the same as you can to a table or an image tag.
<div width="500px" height="500px">test</div>
This is valid syntax:
<div style="width:500px; height:500px;">test</div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.