::active + CSS is not working

Asked

Viewed 180 times

0

div.duvidas2 > div > div::active + 
div.duvidas2 > div > article {
		display: block;
}
div.duvidas2 > div > article {
		display: none;
}
<div class=duvidas2>
  <div>
    <div>
      <span>Titulo 1</span>
      <label>+</label>  
    </div>
    <article>Artigo 1.</article>
  </div>
  <div>
    <div>
      <span>Titulo 2</span>
      <label>+</label>  
    </div>
    <article>Artigo 2.</article>
  </div>
</div>

My goal is to click on div.duvidas2 > div and open the article But only the article of div.duvidas2 > div that is active must be with display:block

Where am I going wrong?

1 answer

2


Man it’s all wrong...

Active doesn’t have two-points, it’s not like that ::active, that’s how it is :active

No use putting :active in a div, pq :active is not a property of that type of element, :active is to use in links and some elements of form, but not in a div

The tb rule is wrong...

div.duvidas2 > div > div::active + 
div.duvidas2 > div > article

First you’re using the + who would take a div with class div.duvidas2 that comes after the first div with div.duvidas2, only you only have one div.duvidas2 then the rule no longer matches...

That’s where you’re wrong

Now from what I understand you want, an option would be using a tag <a> and the pseudo class :focus, so when you click on will make the Focus and show the <article> with a type CSS rule a:focus + article {display:block}

div.duvidas2 > div > a + article {
    display: none;
}
div.duvidas2 > div > a:focus + article {
    display: block;
}
<div class=duvidas2>

  <div>
    <a href="#">
      <span>Titulo 1</span>
      <label>+</label>  
    </a>
    <article>Artigo 1.</article>
  </div>

  <div>
    <a href="#">
      <span>Titulo 2</span>
      <label>+</label>  
    </a>
    <article>Artigo 2.</article>
  </div>

</div>

  • About :: is CSS3 rule. : it was only in CSS2. But in the case of hugocsl, is there a way, by clicking the same link, to close it too? Type: opened, clicked again and closed. This with CSS? Or in this case only with JS? But I understood your explanation. But the link shows an example with input type text https://jsfiddle.net/zsderorm/1/

  • @Carlosrocha not young, does not exist ::active nowhere, here you can check a reliable documentation and will see that there is no mention to ::active, the :: are for pseudo-elements, not for pseudo-classes see https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes this example of the link you posted uses :focus like the example I left there in the answer. The way you want to do it, but the technique is different, is using checkbox and label. Or you can do as in this question https://answall.com/questions/360001/como-customizar-a-seta-padr%C3%a3o-da-tag-Details

  • got it! In that case, doing it with Javascript or Jquery will get better! But thank you very much. I will accept the answer as it was fully compatible with the question!

  • @Carlosrocha haha because you asked where you were going wrong right rss. But to solve there are several techniques, some yes with JS/jQuery, but you can also do with html/css, look for "Collapse Component" in Google you will find some things. This other question may interest you there are some tips there https://answall.com/questions/182123/como-fazer-collapse-e-expand-de-um-texto-usando-apenas-html5

Browser other questions tagged

You are not signed in. Login or sign up in order to post.