Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

146
Visualizações
Style sibling if previous element has a child with an attribute on it

I just wanted to make sure that the following is not possible in CSS, and that I indeed have to use Js for this (I cannot think of any way of doing it in CSS). Let's say you have this markup:

<div id="first" class="first-container">
<label for="field-one">First Field</label>
<input type="text" id="field-one" required=""/>
</div>
<p id="second" class="subsquent-container">
</p>

What I want to do is style #second in a specific way only if #field-one has the required="" attribute on it.

The currently best way to do this I could think of is to scan through all of the .first-container of the page in javascript, check if their input child has the required="" attribute on it, and if so, add a class to the subsequent .subsequent-container.

Does anyone see a CSS - only solution? Would definitely be preferred. Note: This issue is due to the way a software generates constant markup; so changing the markup is not an option (I know, I know...).

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda