resting — 2010-03-30T11:38:33-04:00 — #1
I could define a padding with padding: 5 10 2 8; in CSS.
And a width with <img ... width="100" /> in HTML.
But is this acceptable as a standard? Or do I have to end all values with px?
Personally I'm lazy to type px all the time. Its 8 characters just for a padding of 4 sides.
ryanreese — 2010-03-30T11:44:25-04:00 — #2
THe image width="100" in the HTML doesn't matter since it can be accepted as a value.
Ommiting the px is foolish and invalid. First of all, if you do this
What's the value? em? %? px? elephant? computer? It c ould be anything in the world..just looking outside..ladder..grass..plant
It can be anything. The width="100" is valid, though not your padding example.
black_max — 2010-03-30T11:45:47-04:00 — #3
As far as I know, it's necessary. I know it's standards-compliant.
That's the flip side. It's just 8 characters to make sure your site displays properly in all browsers. Not a lot to ask.
black_max — 2010-03-30T11:46:39-04:00 — #4
:lol: Ryan, we're crossposting. Grandma sends cookies.
kohoutek — 2010-03-30T11:47:02-04:00 — #5
Omitting units for paddings and margins in CSS is not permitted unless the value is 0.
You can omit the unit in your img element, however. It'll then fall back to the default unit which is pixels.
resting — 2010-03-31T08:37:42-04:00 — #6
glad i asked. ok...shall keep my codes up to standards then.
xhtmlcoder — 2010-03-31T08:46:10-04:00 — #7
kohoutek, can you explain how you know the "default unit" for WIDTH is pixels?
Let's say for example you have as follows: <img src="..." alt="..." /> the IMG is an empty 'replaced element' thus would not have a "default unit" for a "width".
If anything it would be a percentage (%) width if I understand it correctly and not actually pixel units.
I assume you meant if the IMG had a WIDTH attribute omitted and no CSS was involved that you believe it would be replaced by "pixel units", which I cannot see is the case.
Or do you actually mean the actual image SRC file let's say 'sample.png' would "default override" and force the issue.
Otherwise I cannot see how it has a default unit in the absence of either CSS or an explicit 'width' value, i.e. ="100" or "100%" .
If I 'misunderstood/misread' your answer; then that's fine.
autisticcuckoo — 2010-03-31T09:28:40-04:00 — #8
No, that is not valid CSS. You have to specify a unit for all non-zero values.
For values that are zero, it's optional to specify a unit. I personally recommend omitting them.
In this case it is an error to add a 'px' unit. Length values in HTML attributes are automatically in pixels, unless you add a '%' character at the end.
erik_j — 2010-03-31T09:33:35-04:00 — #9
The HTML 4.01 DTD specifies it, at least here.
xhtmlcoder — 2010-03-31T10:07:58-04:00 — #10
Like I said it doesn't say pixels but %Length; and as it is replaced it cannot have a known default unit.
What I originally meant it can be either; 'pixel' or 'percentage' just in case I wasn't clear. Most likely I just misread her answer to mean; "only" pixel would be 'default'.
kohoutek — 2010-03-31T11:01:47-04:00 — #11
Yes, that is what I mean. If no unit is specified via CSS then the HTML element's value (width="100") will be automatically in pixels.
paulob — 2010-03-31T16:22:36-04:00 — #12
I'm not sure anyone actually said but in a strict doctype values without a unit will be treated as zero so the above will be rendered as padding:0 0 0 0;
felgall — 2010-03-31T16:53:01-04:00 — #13
Are you sure that they actually get treated as zero or is it just that the default unit is attometres and so the distances are sub-microscopic but still there and just get rounded to zero. I guess if you specified sizes like 1000000000000000000000000 we could find out since that many attometres would actually round up to be a pixel:):):)
xhtmlcoder — 2010-04-01T08:13:42-04:00 — #14
Thanks, I suspected as such - I misread the answer - I have a damn head-cold at the moment; and that combined with word-blindness means my reading ability diminishes considerably.
Ah, I see they actually changed the values slightly from 3.2 to 4.01:
width %Pixels #IMPLIED -- suggested width in pixels --
width %Length; #IMPLIED -- override width --
That explains why you said that; you were referring to an earlier version where it got treated differently - previously pixels only - interesting nonetheless.
alexdawson — 2010-04-02T04:04:58-04:00 — #15
I really don't see there being much to contend about, it's almost like saying "how long is a piece of string", providing unit numbers without the implied unit value is pretty crazy. Especially as the unit values have a very big difference between how the design would be affected as a result. Why play guessing games with the rendering engines, there's enough "loose" interpretations of the spec's without designers confusing the browsers to boot with generic number values.