Can you do Class="multiple classes"?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Giggle Girl

    Can you do Class="multiple classes"?

    I have inherited some CSS from a former employee that has code like
    this:

    onmouseover="th is.className='h ighlight_on standard_border '"

    where it appears to activate two different classes, "highlight_ on" and
    "standard_borde r".

    Is this valid CSS?

    If it is, is there a limit to how many classes you can apply? Any
    other comments on this, or things I should know relating to it?

    Thank you,
    Ann

  • Johannes Koch

    #2
    Re: Can you do Class="mul tiple classes"?

    Giggle Girl wrote:
    [color=blue]
    > I have inherited some CSS from a former employee that has code like
    > this:
    >
    > onmouseover="th is.className='h ighlight_on standard_border '"
    >
    > where it appears to activate two different classes, "highlight_ on" and
    > "standard_borde r".
    >
    > Is this valid CSS?[/color]

    See <http://www.w3.org/TR/html4/struct/global.html#ade f-class>:

    class = cdata-list [CS]
    This attribute assigns a class name or set of class names to an
    element. Any number of elements may be assigned the same class name or
    names. Multiple class names must be separated by white space characters.

    --
    Johannes Koch
    In te domine speravi; non confundar in aeternum.
    (Te Deum, 4th cent.)

    Comment

    • Jukka K. Korpela

      #3
      Re: Can you do Class=&quot;mul tiple classes&quot;?

      "Giggle Girl" <missgiggy@gmai l.com> wrote:
      [color=blue]
      > I have inherited some CSS from a former employee that has code like
      > this:
      >
      > onmouseover="th is.className='h ighlight_on standard_border '"[/color]

      The code is just as foolish as it looks like. This illustrates well why class
      names should describe the meaning (semantics) of elements rather than their
      casual appearance.

      The reason for using JavaScript here is probably the fact that IE does not
      support the :hover pseudoelement except for links. But that's not a reason
      for using foolish class names. Besides, _is_ this a non-link element? As
      usual, the URL etc. etc.
      [color=blue]
      > where it appears to activate two different classes, "highlight_ on" and
      > "standard_borde r".[/color]

      It activates nothing. It assigns two classes to the element.

      Most probably, things could have been written better by using a single class,
      say "hovered", and setting what you like to set for it. However, it's usually
      non-productive to try to fix sloppy code.
      [color=blue]
      > Is this valid CSS?[/color]

      Technically, it's not CSS. There is no CSS construct in the code snippet. But
      class="highligh t_on standard_border " would be valid (though foolish) HTML,
      and JavaScript lets you assign two classes that way, too.
      [color=blue]
      > If it is, is there a limit to how many classes you can apply?[/color]

      Hardly.
      [color=blue]
      > Any other comments on this, or things I should know relating to it?[/color]

      Let it be unless it causes real trouble. Don't imitate it.

      --
      Yucca, http://www.cs.tut.fi/~jkorpela/

      Comment

      • Giggle Girl

        #4
        Re: Can you do Class=&quot;mul tiple classes&quot;?

        Thank you Johannes and Yucca for your response.

        Very helpfull and informitive.

        Ann

        Comment

        Working...