tags:

views:

131

answers:

6

In CSS we can define:

margin-top: 10px;
margin-right: 1px;
margin-bottom: 1px;
margin-left: 1px;

or just short:

margin: 10 1 1 1;

we also can define:

border-left -right -bottom -top ...

or short:

border:1px solid black;

for defining the dimensions of an element we need:

width: 150px;
height: 200px;

why isn't there something like:

dimension: 150px 200px;

or does something similar exist and i just dont know it?

(the reason why i ask: i always misstype 'dth' -> 'dht' and 'ght' -> 'gth' and want to blame someone)

A: 

No, nothing like that exists although I agree it would be convenient. As for why, you'd have to ask the fellas over at W3C.

Rob
A: 

I am not sure why would you like to define image size in CSS (except maybe for backgrounds), when:

  1. you don't need to define image size and browser will just do OK
  2. you can use inline attributes/styling, if you want to declare it

Moreover, your question is subjective. Spec is spec, so get live with it (Or send an email to W3C with your proposal, so they could add in CSS 4+ in next 20 years)

dusoft
images aren't the only elements that take height and width
Rob
he is talking about the "pictures" only
dusoft
the example was about a picture didn't mean to address only picture elements
Chris
he was not clear about that, either
dusoft
he is me and i'm sorry. i replaced 'picture' with 'element'
Chris
that makes more sense :-)
dusoft
+5  A: 

If the naming convention was followed you'd need to define something like:

dimension-width: 150px;
dimension-height: 200px;

to be able to use

dimension: 150px 200px;

I'm not sure this would improve anything.

Edit:

Also need to consider min-height / max-height (+ width). Where would these fit with a 'dimension' property?

codeinthehole
'Where would these fit ...' smth like min-dimension / max-dimension
Chris
+1  A: 

AFAIK something like that doesn't exists. I guess the reason why there a "long" and "short" forms for e.g. margin (margin-top/bottom/...) is that it feels natural to have them. As they start with the same word. margin.

But for width and height there is no common-prefix and something like dimension, dimension-width, dimension-height sounds strange now. But might not sound that strange had they chosen to specify it like this in the css standard.

Now you might consider the same question on doctype.com where someone maybe has more insight into how css was specified and if this discussion ever came up.

jitter
A: 

Probably for a number of reasons:

  1. They didn't think about it at the time ;-)
  2. It's not worth the extra complication (however slight) in spec, processing, documentation, etc when you can only group two values - most of the others are 4 at least.
  3. I don't think 'dimension' is the correct name to use. I'd prefer size - but then that could imply file size.
  4. To now add it to the spec, you'd have to favour 'dimension-width' rather than 'width' to keep the naming the same as margin-xxx.
Lee Atkinson
+6  A: 

Given we work in a 2 dimensional space then there will only ever be 2 attributes, namely Width and Height. Compare this with margin that has four possible parameters.

You save very little typing using your proposed dimension attribute, but run the risk of adding in mistakes. For instance, you could easily make the mistake of getting height and width mixed up - in dimension: 150px 200px; then is 150px the height or width? How would the browser interpret dimension:200px would it mean just 200 width, or would it mean 200 x 200px ? Or something else?

Dan Diplo
well, people got used to the sequence of the margin attribute (top,right,bottom,left like a clock) with dimensions it would be dimension: width height; dimension:200px; would be the same as dimension:200px 200px; and dimension:200px *; would be the same as width: 200px; anyway, i got what you mean and you have a point.
Chris
dimension:200px *; could also be written as dimension:200px auto;
Chris
I like the auto idea, especially if you could use dimension:auto and the browser somehow worked out the actual dimension of the image.
Dan Diplo