Results 1 to 7 of 7

Thread: Bad CSS practice?

  1. #1
    Join Date
    Nov 2007
    Location
    USA
    Posts
    170
    Thanks
    8
    Thanked 22 Times in 22 Posts

    Default Bad CSS practice?

    so i like the idea of using <div> elements with the id attribute in them to help design a good look to the layout. this is going to be hard to explain without a code example so look at these first:

    CSS:
    Code:
    #menu
    {
       margin-top: xx;
       margin-left: xx;
    }
    
    #content
    {
      margin-top: xx;
      margin-left: xx;
    }
    HTML:
    Code:
    <div id="menu">
    //some sort of menu items here (i.e. navigation)
    </div>
    
    <div id="content">
    //content of the site in this area
    </div>
    now what my question is, where i provide xx for the margins is it bad practice to place a negative number for this value?

    i just want to check before i start doing it, because i find it to come in handy, but i am still a noob so any responses will be cool. thanks

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Nope, not bad practice at all, it's quite common and there's nothing wrong with it.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Well, a negative number is bad practice. But a negative value is fine. The difference being that, a negative number like -2 would be invalid. But a negative value like -2px would be fine.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Nov 2007
    Location
    USA
    Posts
    170
    Thanks
    8
    Thanked 22 Times in 22 Posts

    Default

    ok cool thanks. i was hoping you guys would say it isnt because i find it very useful to set up pages that way...although one other question would be is, does the negative value work the same on all browsers etc.?

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Yep, it's supported by the spec and its implementation is pretty much universal.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    To the extent that margins work the same in all browsers, yes. It is usually the default margins on some elements that vary in some browsers. If you explicitly set all margins, differences should be minimal, if any.

    The only main exception being (there could be others), in IE the 'box model' is different so variations might emerge because of that. When that happens (or when specifying every margin explicitly isn't practical), conditional comments may be used to set specific styles for IE only.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Nov 2007
    Location
    USA
    Posts
    170
    Thanks
    8
    Thanked 22 Times in 22 Posts

    Default

    awesome. thanks again for the help

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
  •