How to apply different CSS styles to 2 elements with the same class name?

前端 未结 5 1062
暖寄归人
暖寄归人 2020-12-10 04:34

I created a website that has different navigation menus. In 2 menus, I use the same HTML class element.

I have a .css file that styles that class element in 1 menu.

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-10 05:24

    I'll just add that typically when there are multiple menus you might have them wrapped in a different structure. Take for instance:

    
    
    
    Some different code

    You can easily target these:

    .mainnav>.classone {}
    .wrapper>.classone {}
    

    Or if the parent html has a class:

    Some code
    Some code
    .ancestor1 .classname {} .ancestor2 .classname {}

    Obviously this depends on where in the html they might be.

提交回复
热议问题