Is it same like to omit width/height CSS properties and to specify them as 100%?
+2
A:
On some elements the width acts like 100% (e.g. a <div>
, auto
acts very similar to 100%, depending on margin/padding)....but not height, so no, it's not the same as omitting them everywhere.
Here's a demonstration with <div>
width/height not set vs 100%.
Nick Craver
2010-08-29 11:56:43
100% width on a block element is not equivalent to the computed width which is used by default.
Matti Virkkunen
2010-08-29 12:06:43
@Matti - The behavior is the same for some elements, but yes, it's not *identical*, I'll clarify this a bit.
Nick Craver
2010-08-29 12:08:29
@Nick Craver: It's related to many more things besides the element itself.
Matti Virkkunen
2010-08-29 12:10:09
@Matti - *That* element's height isn't really, it scales according to the container in *either* situation, seems outside the scope of the question IMO. Since we're talking about percentages, this can be safely assumed to be affected by whatever container you're in...
Nick Craver
2010-08-29 12:11:25
@Nick Craver: The width is a much more complex case. Whether setting `width: 100%` is the same as `width: auto` depends on the properties of the element itself (both inherent styles and styles you set), as well as its ancestors.
Matti Virkkunen
2010-08-29 12:13:10
@Matti - That's an *entirely* different question about style inheritance, the answer specifically states how `auto` behaves on a `<div>` as just an example...if you set something else that cascaded then the style is *not* `auto` then is it? :)
Nick Craver
2010-08-29 12:17:37
A:
No, it's not the same. By default both of them are auto
which is quite different. See the CSS specs (for example, from here onwards) for more information on how width and height are calculated when unspecified.
Matti Virkkunen
2010-08-29 11:58:15