tags:

views:

43

answers:

2

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
100% width on a block element is not equivalent to the computed width which is used by default.
Matti Virkkunen
@Matti - The behavior is the same for some elements, but yes, it's not *identical*, I'll clarify this a bit.
Nick Craver
@Nick Craver: It's related to many more things besides the element itself.
Matti Virkkunen
@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
@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
@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
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