search

Home  >  Q&A  >  body text

CSS - Which is better: using "main a" or creating a new class?

I am a complete beginner.

I'm making the CSS for the page. I have links in the main menu and I created a class for them.

I then went to configure the main text link and noticed that the changes I made to the a tag also affected my menu.

I thought of two ways to solve this problem:

I can create a new class and put all the links in the body, or I can specify that I only want the "a" tag in "main", which way is considered good practice?

main a{
css;
}

or

.links-main{
css;
}

Both solutions are valid and I would like advice from experienced colleagues on what would be a standard approach.

P粉340264283P粉340264283497 days ago646

reply all(1)I'll reply

  • P粉793532469

    P粉7935324692023-09-08 10:38:57

    When I use CSS I usually try to create a class for these types of things unless I'm almost 100% sure I won't need it in the future. If you don't think there will be more than one applicable class in .main then it should be fine. However, a common approach I've seen is just taking a new class. As Alloch said, a lot depends on your own wishes.

    When referencing a class, also make sure to execute .main and not just main.

    reply
    0
  • Cancelreply