CSS Missing Units

G

Gene Wirchenko

Dear HTMLers:

I am working from an older text which, apart from its age, is
pretty good. It does have some oddities with regard to CSS though.

What does this mean?
#para2 {margin-left: 50; ...
Note that there are no units specified for margin-left. It does not
seem to do anything on my system (IE 9 under Windows 7). When I use a
value such as
1cm
it works fine.

Some other properties also do not have units, but these seem to
work (i.e. do something) without units, such a border-left-width.

A pointer would be helpful.

Sincerely,

Gene Wirchenko
 
A

Adrienne Boswell

Gene Wirchenko said:
Dear HTMLers:

I am working from an older text which, apart from its age, is
pretty good. It does have some oddities with regard to CSS though.

What does this mean?
#para2 {margin-left: 50; ...
Note that there are no units specified for margin-left. It does not
seem to do anything on my system (IE 9 under Windows 7). When I use a
value such as
1cm
it works fine.

Some other properties also do not have units, but these seem to
work (i.e. do something) without units, such a border-left-width.

A pointer would be helpful.

Sincerely,

Gene Wirchenko

A URL for the relavent CSS file would be even more helpful.
 
G

Gene Wirchenko

A URL for the relavent CSS file would be even more helpful.

No URL. This is internal. The CSS is in-line. I am
experimenting with code.

Sincerely,

Gene Wirchenko
 
J

Jukka K. Korpela

What does this mean?
#para2 {margin-left: 50; ...
Note that there are no units specified for margin-left.

By CSS specifications, it is a syntax errors, and browsers are required
to ignore the erroneous part "margin-left: 50" but continue processing
the style sheet. Older browsers typically accept the construct, implying
the px unit after the number. In the old times, many authors relied on
this erroneous behavior, so browsers generally keep behaving that way
when in "quirks mode"; see
http://www.cs.tut.fi/~jkorpela/quirks-mode.html
It does not
seem to do anything on my system (IE 9 under Windows 7).

That's true in "standards mode". In "quirks mode", the value 50 is taken
as 50px.

As a rule of thumb, write new pages for "standards mode" and keep old
pages in "quirks mode" if the appear to use features like the omission
of units where a unit is required. This means that you should not change
or add the doctype declaration. In some cases, old pages can be
converted to work in "standards mode", but in general, it's complicated,
time-consuming, and generally unproductive.
When I use a
value such as
1cm
it works fine.

It works - fine for some values of "fine". Physical units should be
avoided in page (author) style sheets; they normally make sense in user
stylesheets only, or in specialized situations (e.g., when you are just
making a page for yourself).
Some other properties also do not have units, but these seem to
work (i.e. do something) without units, such a border-left-width.

That would be odd. It's the same thing with border width properties. But
maybe the pages you have checked have been processed by browsers in
different modes. Especially IE has strange logic in selecting the mode.

_Some_ properties take unitless numbers as values, e.g. line-height.
 
G

Gene Wirchenko

By CSS specifications, it is a syntax errors, and browsers are required
to ignore the erroneous part "margin-left: 50" but continue processing
the style sheet. Older browsers typically accept the construct, implying
the px unit after the number. In the old times, many authors relied on
this erroneous behavior, so browsers generally keep behaving that way
when in "quirks mode"; see
http://www.cs.tut.fi/~jkorpela/quirks-mode.html

Thank you.

The book I am using is an old book. I have no problem with being
picky about syntax, once I know it.

[snip]

Sincerely,

Gene Wirchenko
 
A

Adrienne Boswell

Gene Wirchenko said:
No URL. This is internal. The CSS is in-line. I am
experimenting with code.

Sincerely,

Gene Wirchenko

You could always provide snippets, copy and paste what you have. It
would just make things a little easier.
 
D

Denis McMahon

What does this mean?
#para2 {margin-left: 50; ...

The issue as you have identified is the lack of a unit specification.

If you look at the css 2.1 spec for margins:

http://www.w3.org/TR/CSS21/box.html#value-def-margin-width

you can click on "length" which takes you to:

http://www.w3.org/TR/CSS21/syndata.html#value-def-length

where it says, a couple of paras into the section:

The format of a length value (denoted by <length> in this specification)
is a <number> (with or without a decimal point) immediately followed by a
unit identifier (e.g., px, em, etc.). After a zero length, the unit
identifier is optional.

Hence, with a non-zero length value, a unit identifier is required. If
you don't include one, you're into the grey area of "how does each
browser handle this error"

Rgds

Denis McMahon
 
G

Gene Wirchenko

On Wed, 21 Dec 2011 01:14:03 +0000 (UTC), Adrienne Boswell

[snip]
You could always provide snippets, copy and paste what you have. It
would just make things a little easier.

That is what I did. Maybe, I snipped too much? Here is the
whole page with the exception of a 4.01 strict line at the top:

***** Start of CSS Example *****
<html>

<head>
<title>Formatting CS Block Properties</title>
<style type="text/css">

body { background-color: white; }
p
{
margin-left: 10;
border-left-width: 1;
border-style: solid;
background-color: cyan;
}
#para2
{
margin-left: 50;
padding-left: 10;
padding-top: 15;
padding-bottom: 0;
}

</style>
</head>

<body>
<p>This is a paragraph.</p>
<p id=para2>this is another pargraph.</p>
</body>

</html>
***** End of CSS Example *****

The above is slightly modified from the text. I format
differently. More notably, the text quotes many CSS property values
that should not be now according to my testing. In the above example,
"white", "solid", and "cyan" are quoted in the text.

Sincerely,

Gene Wirchenko
 
G

Gene Wirchenko

On 21 Dec 2011 18:12:18 GMT, Denis McMahon <[email protected]>
wrote:

[snip]
Hence, with a non-zero length value, a unit identifier is required. If
you don't include one, you're into the grey area of "how does each
browser handle this error"

Thank you. I prefer to stay out of grey areas. Even though what
I will be writing will run (at least at first) under only one browser,
I prefer not to get parochial in my coding.

Sincerely,

Gene Wirchenko
 
A

Adrienne Boswell

Gene Wirchenko said:
On Wed, 21 Dec 2011 01:14:03 +0000 (UTC), Adrienne Boswell

[snip]
You could always provide snippets, copy and paste what you have. It
would just make things a little easier.

That is what I did. Maybe, I snipped too much? Here is the
whole page with the exception of a 4.01 strict line at the top:

***** Start of CSS Example *****
<html>

<head>
<title>Formatting CS Block Properties</title>
<style type="text/css">

body { background-color: white; }
p
{
margin-left: 10;
border-left-width: 1;
border-style: solid;
background-color: cyan;
}

Here you need units. Margin and border-left-width both need a unit. I
prefer to go with the hex instead of a named color.
#para2
{
margin-left: 50;
padding-left: 10;
padding-top: 15;
padding-bottom: 0;
}

Some thing here, all these need units.
</style>
</head>

<body>
<p>This is a paragraph.</p>
<p id=para2>this is another pargraph.</p>

I find it better to quote attribute values. YMMV.
 
G

Gene Wirchenko

Gene Wirchenko said:
On Wed, 21 Dec 2011 01:14:03 +0000 (UTC), Adrienne Boswell

[snip]
You could always provide snippets, copy and paste what you have. It
would just make things a little easier.

That is what I did. Maybe, I snipped too much? Here is the
whole page with the exception of a 4.01 strict line at the top:

***** Start of CSS Example *****
<html>

<head>
<title>Formatting CS Block Properties</title>
<style type="text/css">

body { background-color: white; }
p
{
margin-left: 10;
border-left-width: 1;
border-style: solid;
background-color: cyan;
}

Here you need units. Margin and border-left-width both need a unit. I
prefer to go with the hex instead of a named color.

Confirmed.

I prefer the names, at least, for now.
Some thing here, all these need units.
Yup.


I find it better to quote attribute values. YMMV.

I prefer to avoid quotes where they are not actually needed to
avoid clutter. YMMV.

In the CSS, I can not use quotes unless the name is broken up (as
in "Times New Roman". If I quote the background-color value, nothing
happens. Since the default is white, this is not apparent, but
body { background-color: red; }
results in a red background, and
body { background-color: "red"; }
does not. The background stays white.

Sincerely,

Gene Wirchenko
 
D

dorayme

Gene Wirchenko said:
....

In the CSS, I can not use quotes unless the name is broken up (as
in "Times New Roman". If I quote the background-color value, nothing
happens.

....

red or #f00 is not an attribute value, id is an HTML attribute as
is class, as is background, cellpadding and many others. Here is
an article, not sure who the author is or whether you can trust
him, but at least he gives reasons for always quoting and
references the official rules in the HTML 4.0 specification that
requires all attribute values be delimited by either single or
double quotes, and not any old quotes either.

<http://www.cs.tut.fi/~jkorpela/qattr.html>

....

CSS property values are a different thing altogether, you mostly
*must not* quote property values - otherwise, as you found, it
does not work.
 
D

dorayme

dorayme said:
red or #f00 is not an attribute value, id is an HTML attribute as
is class, as is background, cellpadding and many others.

should really have read as something like

"id is an HTML attribute as is class, as is background,
cellpadding and many others. The values for such should be
quoted, as for example, in the deprecated HTML attribute of
color.

CSS property values like red or #f00 should not be quoted, as in
the example

p {color: red; ...} in a stylesheet

or inline:

<p style="color: red">This text will be red</p>

Note how the value of the CSS property is unquoted but the HTML
value of the attribute of style is.
 
G

Gene Wirchenko

[snip]

red or #f00 is not an attribute value, id is an HTML attribute as
is class, as is background, cellpadding and many others. Here is
an article, not sure who the author is or whether you can trust
him, but at least he gives reasons for always quoting and

I suspect that Jukka Korpela is the author. Based on postings of
his, I would trust him.

I tend to avoid clutter like always quoting or always putting in
block braces. Mind you, I am quite fanatical about indentation, so I
am less at risk than others might be.
references the official rules in the HTML 4.0 specification that
requires all attribute values be delimited by either single or
double quotes, and not any old quotes either.

<http://www.cs.tut.fi/~jkorpela/qattr.html>

An interesting article: thank you.

It did answer when I can omit the quoting. I have been being
quite careful. Now, I know exactly where the line is.

[snip]
CSS property values are a different thing altogether, you mostly
*must not* quote property values - otherwise, as you found, it
does not work.

But, my text does quote a number of them! Well, its copyright
date is 1999, so maybe, the rules have changed since then.

Sincerely,

Gene Wirchenko
 
D

dorayme

Gene Wirchenko said:
[snip]

red or #f00 is not an attribute value, id is an HTML attribute as
is class, as is background, cellpadding and many others. Here is
an article, not sure who the author is or whether you can trust
him, but at least he gives reasons for always quoting and

I suspect that Jukka Korpela is the author.


Yes, but you are relying on only that his name appears in the URL
and on the page itself plus that it is styled like his pages. Do
you think this is enough to go on?


You are more than welcome and I gave it you in the true
traditions of Xmas, something happens to that part of me that can
loosely be described as a heart.
 
G

Gene Wirchenko

Gene Wirchenko said:
[snip]

red or #f00 is not an attribute value, id is an HTML attribute as
is class, as is background, cellpadding and many others. Here is
an article, not sure who the author is or whether you can trust
him, but at least he gives reasons for always quoting and

I suspect that Jukka Korpela is the author.
Yes, but you are relying on only that his name appears in the URL
and on the page itself plus that it is styled like his pages. Do
you think this is enough to go on?

No, I am basing my opinion on the parting comment (under his
name) of help that the author got. It does not seem to fit otherwise.
I do not think that he would plagirise.
You are more than welcome and I gave it you in the true
traditions of Xmas, something happens to that part of me that can
loosely be described as a heart.

Sincerely,

Gene Wirchenko
 
D

dorayme

Gene Wirchenko said:
No, I am basing my opinion on the parting comment (under his
name) of help that the author got. It does not seem to fit otherwise.
I do not think that he would plagirise.

But the question is who is plagiarising whom? Perhaps J. Korpela
regularly plagiarises J. Korpela and, what is more, and this
makes it cunningly devious, it is vice versa too. Perhaps it is
an international charade transcending boundaries like usenet,
web-based forums, print medium. Perhaps it is one of the great
rivalries of all time, we know in advance, of course, that J.
Korpela will win, but we can never know which one.

You must take special care. Everything should be alright for you,
no great harm done *as long as* no money is involved. So,
perhaps do not worry greatly.
 
M

Mike S

But the question is who is plagiarising whom? Perhaps J. Korpela
regularly plagiarises J. Korpela and, what is more, and this
makes it cunningly devious, it is vice versa too. Perhaps it is
an international charade transcending boundaries like usenet,
web-based forums, print medium. Perhaps it is one of the great
rivalries of all time, we know in advance, of course, that J.
Korpela will win, but we can never know which one.

You must take special care. Everything should be alright for you,
no great harm done *as long as* no money is involved. So,
perhaps do not worry greatly.
<snip>
roflmao, just hilarious.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top