skip to Main Content

I have a WordPress-Website and want to edit the css of a specific site (generated from a plugin).
The problem is, I want to remove (display: none) a header (h2). But the h2 doesn’t have a class (and because it isn’t the only h2, I cannot display: none all the h2), so I cant select it with CSS. Is there a way to select something without a class?

2

Answers


  1. There is indeed! find an element above it in the DOM which you CAN select, like a container with a classname, and use a selector. For example, if you have:

    <div className="section12">
    <h2>Stuff</h2>
    </div>
    

    Then use something like:

    .section12 h2 { display: block; }
    

    However, if you are using something like Elementor on your site, then you can just remove the H2 in some other way, or even add a class name to it.

    Login or Signup to reply.
  2. Yes, you can do this with selectors like nth-child() …

    For example, suppose you want to make the second h2 tag red. This solution will be useful when there is no class name.

    h2:nth-child(2) {
      color: red;
    }
    <h2>hello</h2>
    <h2>hello</h2>
    <h2>hello</h2>
    <h2>hello</h2>
    <h2>hello</h2>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search