Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > CSS Missing Units

Reply
Thread Tools

CSS Missing Units

 
 
Gene Wirchenko
Guest
Posts: n/a
 
      12-20-2011
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
 
Reply With Quote
 
 
 
 
Adrienne Boswell
Guest
Posts: n/a
 
      12-20-2011
Gene Wirchenko <(E-Mail Removed)> wrote

> 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.

--
Adrienne Boswell
Arbpen Web Site Design Services - http://www.cavalcade-of-coding.info/
The Good Plate - Fresh Gourmet Recipes - http://the-good-plate.com/
Please respond to the group so others can share
 
Reply With Quote
 
 
 
 
Gene Wirchenko
Guest
Posts: n/a
 
      12-20-2011
On Tue, 20 Dec 2011 21:44:30 +0000 (UTC), Adrienne Boswell
<(E-Mail Removed)> wrote:

>Gene Wirchenko <(E-Mail Removed)> wrote


>> 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.


>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
 
Reply With Quote
 
Jukka K. Korpela
Guest
Posts: n/a
 
      12-20-2011
2011-12-20 23:26, Gene Wirchenko wrote:

> 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.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      12-20-2011
On Wed, 21 Dec 2011 00:33:24 +0200, "Jukka K. Korpela"
<(E-Mail Removed)> wrote:

>2011-12-20 23:26, Gene Wirchenko wrote:
>
>> 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


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
 
Reply With Quote
 
Adrienne Boswell
Guest
Posts: n/a
 
      12-21-2011
Gene Wirchenko <(E-Mail Removed)> wrote

> On Tue, 20 Dec 2011 21:44:30 +0000 (UTC), Adrienne Boswell
> <(E-Mail Removed)> wrote:
>
>>Gene Wirchenko <(E-Mail Removed)> wrote

>
>>> 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.

>
>>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


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

--
Adrienne Boswell
Arbpen Web Site Design Services - http://www.cavalcade-of-coding.info/
The Good Plate - Fresh Gourmet Recipes - http://the-good-plate.com/
Please respond to the group so others can share
 
Reply With Quote
 
Denis McMahon
Guest
Posts: n/a
 
      12-21-2011
On Tue, 20 Dec 2011 13:26:32 -0800, Gene Wirchenko wrote:

> 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#...f-margin-width

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

http://www.w3.org/TR/CSS21/syndata.h...lue-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
 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      12-21-2011
On Wed, 21 Dec 2011 01:14:03 +0000 (UTC), Adrienne Boswell
<(E-Mail Removed)> wrote:

[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
 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      12-21-2011
On 21 Dec 2011 18:12:18 GMT, Denis McMahon <(E-Mail Removed)>
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
 
Reply With Quote
 
Adrienne Boswell
Guest
Posts: n/a
 
      12-22-2011
Gene Wirchenko <(E-Mail Removed)> wrote

> On Wed, 21 Dec 2011 01:14:03 +0000 (UTC), Adrienne Boswell
> <(E-Mail Removed)> wrote:
>
> [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.

> </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




--
Adrienne Boswell
Arbpen Web Site Design Services - http://www.cavalcade-of-coding.info/
The Good Plate - Fresh Gourmet Recipes - http://the-good-plate.com/
Please respond to the group so others can share
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mixed units in a single css declaration dorayme HTML 3 08-27-2006 12:48 AM
initialize memory units Daniel Koethe VHDL 1 11-08-2004 08:36 PM
Share folders btn 2 units =?Utf-8?B?S2V2aW4=?= Wireless Networking 2 09-16-2004 04:37 AM
ADSL units for US individuals Eric LEMAITRE Cisco 5 06-24-2004 04:43 PM
Map n algorithms to m functional units Andreas VHDL 0 12-02-2003 02:34 PM



Advertisments