Can I use DIV class and ID together in CSS?

后端 未结 9 1357
名媛妹妹
名媛妹妹 2020-12-25 10:21

Can I use DIV Class and ID together in CSS? For example:

--
相关标签:
9条回答
  • 2020-12-25 10:48

    Yes you can.

    You just need to understand what they are for, the class is more general and can be used several times, the id (is like your id's) you can use it only once.

    This excellent tutorial helped me with that:

    The Difference Between ID and Class

    Though it's not an exact answer to your question I'm sure it will help you a lot!

    Good luck!

    EDIT: Reading your question, I just want to clarify that:

    <div class="x" id="y">
        --
    </div>
    

    And that if you want to "use them" in CSS for styling purposes you should do as David Says: #x.y { }

    0 讨论(0)
  • 2020-12-25 10:50

    That's HTML, but yes, you can bang pretty much any selectors you like together.

    #x.y { }
    

    (And the HTML is fine too)

    0 讨论(0)
  • 2020-12-25 10:50

    Yes, why not? Then CSS that applies to class "x" AND CSS that applies to ID "y" applies to the div.

    0 讨论(0)
提交回复
热议问题