Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 6 of 6
  1. #1
    Member
    Join Date
    Sep 2003
    Posts
    42
    Member #
    2955
    When you close a declaration, do you have to put the ; tag at the end of it?

    Example:

    selector {property:value;
    property:value;
    property:value;}

    OR

    selector {property:value;}

    Or can you just do this:

    selector {property:value;
    property:value;
    property:value}

    selector {property:value}

    I've seen it done both ways and confused why some have the ; before closing it and sometimes they dont.

  2.  

  3. #2
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    When I validated my CSS, it didn't care that I left it out. Typically, in programming, you'd use it (and also indent as such):
    Code:
    tag
    {
        attribute:value;
        attribute:value;
    }
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  4. #3
    Member
    Join Date
    Sep 2003
    Posts
    42
    Member #
    2955
    Ok so im thinking its a good pratice to put it in before closing? I was checking out w3schools and noticed that they didnt put the ; before closing so now confused as to which is the proper way.

  5. #4
    Senior Member james's Avatar
    Join Date
    May 2003
    Location
    Melbourne, AUSTRALIA
    Posts
    364
    Member #
    1352
    I think either way is equally valid in the official CSS definition, but I always put them in. It makes it easier when you're copying and pasting stuff around.
    James H
    Home Page · Mars Page · www.fihsf1.net (formerly www·fihs·net)

  6. #5
    Senior Member mossoi's Avatar
    Join Date
    Apr 2003
    Location
    Englandshire, United Kingdomsville y'all!
    Posts
    1,111
    Member #
    1206
    Liked
    1 times
    The ; is only to separate attributes so it is only strictly necessary when one attribute is followed by another. If it's the only, or last, attribute it isn't needed. IMO it is better practice to put the ; after every attribute, then everything is constant throughout your style sheet.

    Strictly speaking it's probably more correct to not have a trailing ; as the browser is reading a blank value after the list of attributes.

    eg.

    .main {
    color: #000;
    font-size: x-small;
    width: 500px;
    }

    Is seen by the browser as having the attributes:

    color = #000
    font-size = x-small
    width = 500px
    {blank} = {blank}

  7. #6
    Senior Member james's Avatar
    Join Date
    May 2003
    Location
    Melbourne, AUSTRALIA
    Posts
    364
    Member #
    1352
    I can see your logic there BlueOyster, but 'parsers', or things that read code, don't work like that. They read in 'tokens', which are strings of characters that are terminated by white-space or punctuation, and then interpret them.

    I don't know of any good tutorials on this stuff, but in the second example, it would successfully read in the width value, then read in the semi-colon, then be ready to read another attribute OR the character to terminate the attribute list, '}'.
    James H
    Home Page · Mars Page · www.fihsf1.net (formerly www·fihs·net)


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 06:08 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com