SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard
    Join Date
    Jan 2005
    Location
    blahblahblah
    Posts
    1,447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    can a given field have a rule for an id and a rule for a class

    Hi,
    I am trying to know if it is correct for a tag to have both the id and class attributes if it accepts them of course.

    I would like to have for example an element with its unique id (id="iamunique" and the corresponding unique style) which would also receive the styles of a generic family (class="weallsharethesamestyle").

    For example, the unique id would say: this element has a bold type. But the class would say: "font must be red".

    Would that work correctly? can you have both an id and a class attribute for the same element and can all the rules be applied to the element in question?

    I hope I was clear.

    Here is a last example:

    Code:
    <span id="fontisbold" class="fontisred">yeah!</span>
    the word "yeah" would be both bold and red.

    thanks in advance

  2. #2
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,556
    Mentioned
    183 Post(s)
    Tagged
    6 Thread(s)
    Would that work correctly? can you have both an id and a class attribute for the same element and can all the rules be applied to the element in question?
    Yes you can have a class and an id and it is very useful in some situations. However it is fine where you are defining different properties for each but if you were to define the same property then the id would carry more weight and overrule the class.

    You could use multiple classes also by using a space separated list.

    Code:
    <p class="class1 class2 class3">Text styled by class1, class2 and class3</p>

  3. #3
    SitePoint Wizard
    Join Date
    Jan 2005
    Location
    blahblahblah
    Posts
    1,447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yep

    it was quite theoretical anyway.

    thanks a lot Paul


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
  •