difference between css declarations

Discussion in 'HTML' started by ppcguy, Aug 20, 2005.

  1. ppcguy

    ppcguy Guest

    i've got

    * html #menu
    {
    }

    and

    #menu span
    {
    }


    <body>
    <span id="menu">
    </span>
    </body>

    is there a difference between the two css declarations.

    i would think they're the same...but if i move the contents
    from one to another i get different results.
     
    ppcguy, Aug 20, 2005
    #1
    1. Advertising

  2. ppcguy wrote:

    > i've got
    >
    > * html #menu
    > {
    > }
    >
    > and
    >
    > #menu span
    > {
    > }
    >
    >
    > <body>
    > <span id="menu">
    > </span>
    > </body>
    >
    > is there a difference between the two css declarations.
    >
    > i would think they're the same...but if i move the contents
    > from one to another i get different results.


    '#menu span' refers to a span inside an element with id="menu", e.g.
    <div id="menu"><span>..</span></div>

    What you probably want is 'span#menu'.
    Then both rules would match your <span> but with different priorities, so
    they are are not 'the same'.


    --
    Benjamin Niemann
    Email: pink at odahoda dot de
    WWW: http://www.odahoda.de/
     
    Benjamin Niemann, Aug 20, 2005
    #2
    1. Advertising

  3. Benjamin Niemann <> wrote:

    > ppcguy wrote:
    >
    >> i've got
    >>
    >> * html #menu
    >> {
    >> }
    >>
    >> and
    >>
    >> #menu span
    >> {
    >> }
    >>
    >>
    >> <body>
    >> <span id="menu">
    >> </span>
    >> </body>
    >>
    >> is there a difference between the two css declarations.


    [...]

    > What you probably want is 'span#menu'.
    > Then both rules would match your <span> but with different
    > priorities, so they are are not 'the same'.


    Except, of course, that "* html #menu" will never match anything
    (unless there is a buggy implementation).

    --
    David Håsäther
     
    David Håsäther, Aug 20, 2005
    #3
  4. ppcguy

    Safalra Guest

    ppcguy wrote:
    > * html #menu { }
    >
    > and
    >
    > #menu span { }
    >
    > [snip]
    >
    > is there a difference between the two css declarations.


    Yes. The first one shouldn't work - it matches an element with id
    'menu' that is a descendant of an element of type html that is a
    descendant of any element - the html element is never the descendant of
    another element.

    As ids have to be unique there is usually no point checking that the
    element with that id is a descendant of some other element. (The only
    time you'd want to do this is when applying the same stylesheet to
    several documents where the position of the element with that id should
    effect its display.)

    --
    Safalra (Stephen Morley)
    http://www.safalra.com/hypertext/
     
    Safalra, Aug 20, 2005
    #4
  5. David Håsäther wrote:

    > Benjamin Niemann <> wrote:
    >
    >> ppcguy wrote:
    >>
    >>> i've got
    >>>
    >>> * html #menu
    >>> {
    >>> }
    >>>
    >>> and
    >>>
    >>> #menu span
    >>> {
    >>> }
    >>>
    >>>
    >>> <body>
    >>> <span id="menu">
    >>> </span>
    >>> </body>
    >>>
    >>> is there a difference between the two css declarations.

    >
    > [...]
    >
    >> What you probably want is 'span#menu'.
    >> Then both rules would match your <span> but with different
    >> priorities, so they are are not 'the same'.

    >
    > Except, of course, that "* html #menu" will never match anything
    > (unless there is a buggy implementation).


    Oops. You are correct. My mind focused on the second rule..

    --
    Benjamin Niemann
    Email: pink at odahoda dot de
    WWW: http://www.odahoda.de/
     
    Benjamin Niemann, Aug 20, 2005
    #5
  6. ppcguy

    Pete Gray Guest

    In article <>,
    says...
    > ppcguy wrote:
    > > * html #menu { }
    > >
    > > and
    > >
    > > #menu span { }
    > >
    > > [snip]
    > >
    > > is there a difference between the two css declarations.

    >
    > Yes. The first one shouldn't work - it matches an element with id
    > 'menu' that is a descendant of an element of type html that is a
    > descendant of any element - the html element is never the descendant of
    > another element.
    >


    It shouldn't, but it will work in IE (only).
    <http://www.info.com.ph/~etan/w3pantheon/style/starhtmlbug.html>

    ....thus forming the basis for a number of CSS hacks to deal with IE's
    deficiencies.

    --
    Pete Gray

    Say No to ID Cards <http://www.no2id.net>
    <http://www.redbadge.co.uk/no2idcards/>
     
    Pete Gray, Aug 20, 2005
    #6
    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. jakk
    Replies:
    4
    Views:
    12,403
  2. Guybrush Threepwood
    Replies:
    7
    Views:
    522
    Nick Hounsome
    Feb 26, 2004
  3. pmatos
    Replies:
    11
    Views:
    669
    Rolf Magnus
    Mar 17, 2005
  4. Wade Yin
    Replies:
    30
    Views:
    780
    Wade Yin
    Apr 20, 2004
  5. Vasileios Zografos

    Any difference in these array declarations

    Vasileios Zografos, Jan 4, 2006, in forum: C++
    Replies:
    18
    Views:
    538
    Frinos
    Jan 5, 2006
Loading...

Share This Page