Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

113
Vistas
How can i edit a background based on the h3 content inside a div?

.package {
  border: var(--border);
  border-radius: var(--border-radius);
  background: var(--color-bg-900);
  padding: var(--spacing-grid) 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
}

.package h3 {
  font-size: 1rem;
  padding: 0 0 var(--spacing-xs) var(--spacing-grid);
}
<div class="package">
  <div class="package__info">
    <h3>Bl4ck🎁Gift</h3>
    <div class="package__tags">
      <span class="tag tag--left tag--700">10.00 EUR</span>
    </div>
  </div>
  # another content here
</div>

I need to change the background CSS flag, if the <h3> tag has Bl4ck🎁Gift as specific content inside the <div class="package__info> class. And my question is, how can I change the background for the package class if the <h3> tag has specific content? I know how I can change backgrounds, but because it's my first time I work with CSS, I have no clue how I can find the specific package with the Bl4ck🎁Gift content inside the <h3> tag. What would be the best way to change the background for this specific package? I don't know how I can do it with javascript either. I'd like a solution for this, to learn from it.

I'm not very sure how I can describe this problem, not even in my mother language. I hope you guys still understand what I mean and what I need. Feel free to edit the post, if you can explain it better.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You could use JavaScript to check the content of the h3 element, and then set the background accordingly.

const package = document.querySelector(".package");
const h3 = document.querySelector(".package__info h3");

if (h3.innerText === "Bl4ck🎁Gift") {
  package.style.background = "red";
}
.package {
  border: var(--border);
  border-radius: var(--border-radius);
  background: var(--color-bg-900);
  padding: var(--spacing-grid) 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
}

.package h3 {
  font-size: 1rem;
  padding: 0 0 var(--spacing-xs) var(--spacing-grid);
}
<div class="package">
  <div class="package__info">
    <h3>Bl4ck🎁Gift</h3>
    <div class="package__tags">
      <span class="tag tag--left tag--700">10.00 EUR</span>
    </div>
  </div>
  ...other content here
</div>.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda