SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Addict
    Join Date
    Jul 2009
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Does omitting the px matter?

    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.

  2. #2
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,564
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    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
    padding:6

    What's the value? em? &#37;? 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.
    Twitter-@Ryan_Reese09
    http://www.ryanreese.us -Always looking for web design/development work

  3. #3
    SitePoint Wizard bronze trophy Black Max's Avatar
    Join Date
    Apr 2007
    Posts
    4,029
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)
    As far as I know, it's necessary. I know it's standards-compliant.

    Quote Originally Posted by resting View Post
    Personally I'm lazy to type px all the time. Its 8 characters just for a padding of 4 sides.
    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.

  4. #4
    SitePoint Wizard bronze trophy Black Max's Avatar
    Join Date
    Apr 2007
    Posts
    4,029
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)
    Ryan, we're crossposting. Grandma sends cookies.

  5. #5
    Mazel tov! bronze trophy kohoutek's Avatar
    Join Date
    Aug 2004
    Location
    Hamburg, Germany
    Posts
    4,248
    Mentioned
    30 Post(s)
    Tagged
    0 Thread(s)
    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.
    Maleika E. A. | Rockatee | Twitter | Dribbble



  6. #6
    SitePoint Addict
    Join Date
    Jul 2009
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    glad i asked. ok...shall keep my codes up to standards then.

  7. #7
    Robert Wellock silver trophybronze trophy xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,316
    Mentioned
    60 Post(s)
    Tagged
    0 Thread(s)
    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.

  8. #8
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by resting View Post
    I could define a padding with padding: 5 10 2 8; in CSS.
    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.

    Quote Originally Posted by resting View Post
    And a width with <img ... width="100" /> in HTML.
    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.
    Birnam wood is come to Dunsinane

  9. #9
    Design Your Site Team bronze trophy Erik J's Avatar
    Join Date
    May 2007
    Location
    Countryside, Sweden
    Posts
    3,407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by xhtmlcoder
    ... can you explain how you know the "default unit" for WIDTH is pixels?
    ...
    The HTML 4.01 DTD specifies it, at least here.
    Happy ADD/ADHD with Asperger's

  10. #10
    Robert Wellock silver trophybronze trophy xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,316
    Mentioned
    60 Post(s)
    Tagged
    0 Thread(s)
    Like I said it doesn't say pixels but &#37;Length; and as it is replaced it cannot have a known default unit.

    Quote Originally Posted by http://www.w3.org/TR/html401/types.html#type-length
    Length: The value (%Length; in the DTD) may be either a %Pixel; or a percentage of the available horizontal or vertical space. Thus, the value "50%" means half of the available space.
    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'.

  11. #11
    Mazel tov! bronze trophy kohoutek's Avatar
    Join Date
    Aug 2004
    Location
    Hamburg, Germany
    Posts
    4,248
    Mentioned
    30 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by xhtmlcoder View Post
    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 (&#37 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.

    Hi XHTMLCoder.

    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.

    Quote Originally Posted by W3C
    WIDTH Optional suggested width for the image. By default, this is given in pixels. HEIGHT Optional suggested height for the image. By default, this is given in pixels.
    Maleika E. A. | Rockatee | Twitter | Dribbble



  12. #12
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    39,803
    Mentioned
    158 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by resting View Post
    I could define a padding with padding: 5 10 2 8; in CSS.
    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;

  13. #13
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,604
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Paul O'B View Post
    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;
    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
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  14. #14
    Robert Wellock silver trophybronze trophy xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,316
    Mentioned
    60 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kohoutek View Post
    Hi XHTMLCoder.

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

    http://www.w3.org/TR/REC-html32.html#img
    width &#37;Pixels #IMPLIED -- suggested width in pixels --

    http://www.w3.org/TR/1999/REC-html40...ts.html#h-13.2
    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.

    Thankee

  15. #15
    Follow: @AlexDawsonUK silver trophybronze trophy AlexDawson's Avatar
    Join Date
    Feb 2009
    Location
    England, UK
    Posts
    8,111
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •