Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS IDS and Class

  • This topic is empty.
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #45559
    Junni
    Member

    how much tags and classes a tAG can absorb ????

    #138874
    posterity576
    Participant

    Html elements can take on as many id and class attribute values as you’d like, so long as they’re enclosed in quotes and are separated by spaces. Below are two examples of an element with five id’s assigned to it and an element with five classes assigned to it. But again, an element can have as many id or class attribute values as you’d like.

    Some text.
    Some more text
    #138875
    posterity576
    Participant

    Here’s the bit of code to which I was referring.

    `

    Some text.

    `

    `

    Some more text

    `

    EDIT: Apparently, I’m not able to wrap my text using the code function on this site…

    #138886
    Junni
    Member

    i got what i want which is

    we can add differnt classes as the method above as you told thanx alot

    #138889
    CodeGraphics
    Participant

    @posterity576, this is what you want to achieve.

    Text

    Text

    In order to get your code as you want it, hit your keyboard spacebar 4 times to give some indent, then write your codes.

    #138891
    Kitty Giraudel
    Participant

    That’s actually one of the main principles of CSS. Using multiple classes to style elements.

    #138899
    posterity576
    Participant

    @CodeGraphics It seems like it fixed itself (see two comments above yours). Thanks, though, and that’s what I was trying to achieve.

    #138901
    pixelgrid
    Participant

    Html doesnt allow for multiple Id’s on the same element but can be achieved using xml

    Quoted from http://www.w3.org/TR/CSS2/selector.html#id-selectors

    > If an element has multiple ID attributes, all of them must be treated as IDs for that element for the purposes of the ID selector. Such a situation could be reached using mixtures of xml:id [XMLID], DOM3 Core [DOM-LEVEL-3-CORE], XML DTDs [XML10] and namespace-specific knowledge.

    #138916
    CodeGraphics
    Participant

    Yes, it’s perfectly ok. Each id is unique. However, I wonder a situation that will require using more than one or two ids for a tag.

    #138918
    CrocoDillon
    Participant

    > Yes, it’s perfectly ok.

    Actually, it’s not as @pixelgrid already mentioned.

    > The value must not contain any space characters. – [spec](http://www.w3.org/TR/html5/dom.html#the-id-attribute)

    You can compare this definition to that of the [class attribute](http://www.w3.org/TR/html5/dom.html#classes), where it’s explicitly states it can contain a set of space separated classes.

    #138927
    Senff
    Participant

    @CodeGraphics: Even if it’s valid or whatnot, any element on a page should only have ONE id, and every id should only appear ONCE on a page.

    #138949
    posterity576
    Participant

    @CrocoDillon, @Senff,

    Firstly, @CrocoDillon would be right that an id cannot have space-separated values. That was a mistake on my end when I was typing up a response to @Junni. Secondly, the faux-id attribute values I gave to the div with the class attribute are actually quite valid and are an excellent candidate for allowing an element with a class attribute assigned to it to take on the naming conventions of an id. In CSS, it would be styled like so:

    .#id1{}

    .#id2{}

    .#id3{}

    .#id4{}

    .#id5{}

    Of course, I didn’t actually use the octothorpe as a styling hook when I assigned the five id’s to the div with a class attribute, and so the above is really tangential. Nevertheless, assigning id’s as class attribute values is an excellent way of avoiding the use of id’s entirely, unless you’re using them as hooks for JavaScript or as fragment identifiers.

    Cheers!

    #138958
    Kitty Giraudel
    Participant

    Hashed classes: troll topic enabled. See http://csswizardry.com/2013/05/hashed-classes-in-css/.

    #138960
    CrocoDillon
    Participant

    Nice read Hugo :) (especially the conclusion)

Viewing 14 posts - 1 through 14 (of 14 total)
  • The forum ‘CSS’ is closed to new topics and replies.