Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8

Thread: Syntax

  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Syntax

    This is something I feel I should know, but I don't.

    When using CSS styles, we can define them like this:

    .customClass {}

    and if the same style should be applied to more than one class, we separate them with commas, yeah?

    .customClass1, .customClass2 {}

    However, what about parents and children? CSS2 supports this syntax:

    .parentClass>.childClass {}

    However as we know, not all browsers support that yet. So, I have always thought that dot or space syntax is the idea (this is where the problem comes in).

    I started off thinking that something like this:

    .parentClass.childClass {}

    was correct notation. However, that caused me some problems in either IE or Mozilla. In the end I changed it by adding a space in between, like this:

    .parentClass .childClass {}

    Now it strikes me that custom classes start with dots, yeah? So surely standard HTML tags should work without the space, e.g.

    p.a {}

    But I believe I found problems with that, too.

    Applying the same logic to the custom classes:

    .parentClass..childClass {}

    didn't get me anywhere, and seems odd, too. But I had to try.

    What I want to know, is, what is the proper method of defining children? Without using the ">" CSS2 syntax? Because I have seen a few places that use p.a syntax however that doesn't always work for me especially when using custom classes.

    Oh and before anyone says about it, yes I looked at the W3C (my first point of call as always) and it didn't help much. I want to know what will work, and work now, in IE6 and Mozilla, but also as far back as possible (does IE6 support ">"? I don't think so...?)

    Cheers anyone!

    ::] krycek [::
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    There are two ways of selecting children:

    myselector anotherselector {
    }

    This is the most inefficient way, as it selects all descendants (that match anotherselector) of whatever myselector matches.

    However, IE5+ and Gecko support it.

    myselector > anotherselector {
    }

    selects immediate descendants, which is typically what you want, and is more efficient.

    Opera 6+, Mozilla, Konqueror all support it.

    You can also selector some children via pseudo-classes:

    myselector:first-child {}
    and
    myselector:last-child {}

    I don't believe IE supports those however.

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ...so...

    are you saying there is supposed to be a space, or not? That's basically what my post was on about. Although, from your example, I would assume that my current method of coding with a space is correct.

    ::] krycek [::
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."

  • #4
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts
    um hello? Space or no space?

    ::] krycek [::
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."

  • #5
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    You need the space to tell it to select descendants.

  • #6
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts
    cool that's what I worked out

    so, why do some places script their styles without using a space? e.g. p.b - that seems a bit silly don't you think!


    Merry Christmas Everyone!

    ::] krycek [::
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."

  • #7
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    selector.classname

    specifies rules for only for elements with classname that match selector.

  • #8
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts
    eh?

    Just when I thought I had it worked out!

    Can you just explain the difference between using a space and not using a space...? They both seem the same to me? When would I use a space and when would I not?


    Merry Christmas Everyone!

    ::] krycek [::
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."


  •  

    Posting Permissions

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