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

121
Visualizações
Update pseudo-element property of a class dynamically

I'm adding a ribbon to a card and I want to display dynamically the content and the color based on props. I successfully did it with attr() for the content, but it seems I'm stucked to update the background-color, how can I do it?

HTML:

<span class="ribbon zindex-2" :data-content="content" />

SCSS:

.ribbon {
  position: absolute;
  width: 100px;
  height: 100px;
  top: 0px;
  left: 15px;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

.ribbon::before {
  content: attr(data-content);
  position: absolute;
  width: 150%;
  height: 28px;
  background: red; /* value to update dynamically but I don't know how */
  transform: rotate(-45deg) translateY(-20px);
  display: flex;
  justify-content: center;
  align-items: center;
  text-transform: uppercase;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.1em;
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
}

The content variable is coming from a Vue Prop. For example, I want to set this background to gold if the content variable is "1", gray if it's "2" and so on...

Thanks

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You could use attribute selectors in css:

.ribbon[data-content="1"]::before {
  background: gold;
}

.ribbon[data-content="2"]::before {
  background: gray;
}
about 4 years ago · Juan Pablo Isaza Relatório
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