CSS Missing Units

Discussion in 'HTML' started by Gene Wirchenko, Dec 20, 2011.

  1. 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
     
    Gene Wirchenko, Dec 20, 2011
    #1
    1. Advertising

  2. Gene Wirchenko <> 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
     
    Adrienne Boswell, Dec 20, 2011
    #2
    1. Advertising

  3. On Tue, 20 Dec 2011 21:44:30 +0000 (UTC), Adrienne Boswell
    <> wrote:

    >Gene Wirchenko <> 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
     
    Gene Wirchenko, Dec 20, 2011
    #3
  4. 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/
     
    Jukka K. Korpela, Dec 20, 2011
    #4
  5. On Wed, 21 Dec 2011 00:33:24 +0200, "Jukka K. Korpela"
    <> 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
     
    Gene Wirchenko, Dec 20, 2011
    #5
  6. Gene Wirchenko <> wrote

    > On Tue, 20 Dec 2011 21:44:30 +0000 (UTC), Adrienne Boswell
    > <> wrote:
    >
    >>Gene Wirchenko <> 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
     
    Adrienne Boswell, Dec 21, 2011
    #6
  7. 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#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
     
    Denis McMahon, Dec 21, 2011
    #7
  8. On Wed, 21 Dec 2011 01:14:03 +0000 (UTC), Adrienne Boswell
    <> 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
     
    Gene Wirchenko, Dec 21, 2011
    #8
  9. On 21 Dec 2011 18:12:18 GMT, Denis McMahon <>
    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
     
    Gene Wirchenko, Dec 21, 2011
    #9
  10. Gene Wirchenko <> wrote

    > On Wed, 21 Dec 2011 01:14:03 +0000 (UTC), Adrienne Boswell
    > <> 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
     
    Adrienne Boswell, Dec 22, 2011
    #10
  11. On Thu, 22 Dec 2011 07:11:42 +0000 (UTC), Adrienne Boswell
    <> wrote:

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


    Confirmed.

    I prefer the names, at least, for now.

    >> #para2
    >> {
    >> margin-left: 50;
    >> padding-left: 10;
    >> padding-top: 15;
    >> padding-bottom: 0;
    >> }


    >Some thing here, all these need units.


    Yup.

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


    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.

    >> </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
     
    Gene Wirchenko, Dec 22, 2011
    #11
  12. Gene Wirchenko

    dorayme Guest

    In article <>,
    Gene Wirchenko <> wrote:

    > On Thu, 22 Dec 2011 07:11:42 +0000 (UTC), Adrienne Boswell
    > <> wrote:
    >
    > >Gene Wirchenko <> wrote
    > >
    > >> On Wed, 21 Dec 2011 01:14:03 +0000 (UTC), Adrienne Boswell
    > >> <> wrote:

    ....
    > >> <p id=para2>this is another pargraph.</p>

    > >
    > >I find it better to quote attribute values. 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.


    ....

    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>

    ....

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

    >


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

    --
    dorayme
     
    dorayme, Dec 22, 2011
    #12
  13. Gene Wirchenko

    dorayme Guest

    In article <>,
    dorayme <> wrote:

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

    --
    dorayme
     
    dorayme, Dec 22, 2011
    #13
  14. Gene Wirchenko wrote:

    > Adrienne Boswell wrote:
    >>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.


    Here is a page with color codes, one of the better ones I think, if you
    wish a reference:

    <http://www.somacon.com/p142.php>

    --
    -bts
    -This space for rent, but the price is high
     
    Beauregard T. Shagnasty, Dec 22, 2011
    #14
  15. On Fri, 23 Dec 2011 08:04:28 +1100, dorayme <>
    wrote:

    >In article <>,
    > Gene Wirchenko <> wrote:


    [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
     
    Gene Wirchenko, Dec 22, 2011
    #15
  16. On Thu, 22 Dec 2011 21:32:22 +0000 (UTC), "Beauregard T. Shagnasty"
    <> wrote:

    >Gene Wirchenko wrote:
    >
    >> Adrienne Boswell wrote:
    >>>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.

    >
    >Here is a page with color codes, one of the better ones I think, if you
    >wish a reference:
    >
    ><http://www.somacon.com/p142.php>


    Thank you.

    Sincerely,

    Gene Wirchenko
     
    Gene Wirchenko, Dec 22, 2011
    #16
  17. Gene Wirchenko

    dorayme Guest

    In article <>,
    Gene Wirchenko <> wrote:

    > On Fri, 23 Dec 2011 08:04:28 +1100, dorayme <>
    > wrote:
    >
    > >In article <>,
    > > Gene Wirchenko <> wrote:

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


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

    >


    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.

    --
    dorayme
     
    dorayme, Dec 23, 2011
    #17
  18. On Fri, 23 Dec 2011 11:24:34 +1100, dorayme <>
    wrote:

    >In article <>,
    > Gene Wirchenko <> wrote:
    >
    >> On Fri, 23 Dec 2011 08:04:28 +1100, dorayme <>
    >> wrote:
    >>
    >> >In article <>,
    >> > Gene Wirchenko <> wrote:

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

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


    >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
     
    Gene Wirchenko, Dec 23, 2011
    #18
  19. Gene Wirchenko

    dorayme Guest

    In article <>,
    Gene Wirchenko <> wrote:

    > On Fri, 23 Dec 2011 11:24:34 +1100, dorayme <>
    > wrote:
    >
    > >In article <>,
    > > Gene Wirchenko <> wrote:

    ....
    > >> 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.
    >
    > >> ><http://www.cs.tut.fi/~jkorpela/qattr.html>

    >


    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.

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

    >


    --
    dorayme
     
    dorayme, Dec 23, 2011
    #19
  20. Gene Wirchenko

    Mike S Guest

    On 12/22/2011 6:37 PM, dorayme wrote:
    > In article<>,
    > Gene Wirchenko<> wrote:
    >
    >> On Fri, 23 Dec 2011 11:24:34 +1100, dorayme<>
    >> wrote:
    >>
    >>> In article<>,
    >>> Gene Wirchenko<> wrote:

    > ...
    >>>> 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.
    >>
    >>>>> <http://www.cs.tut.fi/~jkorpela/qattr.html>

    >>

    > 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.
     
    Mike S, Dec 24, 2011
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas
    Replies:
    0
    Views:
    511
    Andreas
    Dec 2, 2003
  2. Daniel Koethe

    initialize memory units

    Daniel Koethe, Nov 8, 2004, in forum: VHDL
    Replies:
    1
    Views:
    807
    mike_treseler
    Nov 8, 2004
  3. Adrian Gibbons

    Getting the units of a number

    Adrian Gibbons, Oct 23, 2003, in forum: C++
    Replies:
    4
    Views:
    299
    David Rubin
    Oct 23, 2003
  4. John Carson
    Replies:
    2
    Views:
    347
    John Carson
    Jan 23, 2004
  5. dorayme
    Replies:
    3
    Views:
    653
    Neredbojias
    Aug 27, 2006
Loading...

Share This Page