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

305
Visualizações
Add a tick selected css

.showcase-components-colorlist color {
  border: 2px solid transparent;
  margin: 1px;
  padding: 2px;
  border-radius: 50%;
  cursor: pointer;
}
<div class="showcase-components-colorlist color showcase-components-colorlist color-- active">
  <svg width="40" height="40">
    <circle cx="20" cy="20" r="19" fill="#c5145d" stroke="#fff" stroke-width="1"></circle>
  </svg>
</div>
<div class="showcase-components-colorlist color">
  <svg width="40" height="40">
    <circle cx="20" cy="20" r="19" fill="#db2586" stroke="#fff" stroke-width="1"></circle>
  </svg>
</div>

How to add a check mark to one of the circles as generated by the code above.

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

0

One way to do this is through pseudo content. You need to give the element which you'll set the pseudo content a relative container. Then, you create your pseudo content (in this case, a check mark). The positioning will be relative to the parent element's dimensions.

.showcase-components-colorlist {
  border: 2px solid transparent;
  margin: 1px;
  padding: 2px;
  border-radius: 50%;
  cursor: pointer;
  position: relative;
}

.showcase-components-colorlist.selected::before {
  content: '✅';
  position: absolute;
  left: 11px;
  top: 9px;
}
<div class="showcase-components-colorlist color showcase-components-colorlist color-- active">
  <svg width="40" height="40"><circle cx="20" cy="20" r="19" fill="#c5145d" stroke="#fff" stroke-width="1">
    </circle>
  </svg>
</div>
<div class="showcase-components-colorlist selected">
  <svg width="40" height="40">
    <circle cx="20" cy="20" r="19" fill="#db2586" stroke="#fff" stroke-width="1"></circle>
  </svg>
</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

Create your own <svg-option> Native JavaScript Web Component.

<svg-option></svg-option>
<svg-option fill="red" selected></svg-option>
<svg-option fill="rebeccapurple" selected-fill="yellow" selected></svg-option>

creates:

<script>
customElements.define("svg-option",class extends HTMLElement{
  connectedCallback(){
    this.style.display = "inline-block";
    this.innerHTML=`<svg viewBox="0 0 50 50">
                      <circle cx="50%" cy="50%" r="49%" fill="${this.getAttribute("fill") || "green"}"/>
                      <circle cx="50%" cy="50%" r="30%" fill="${this.getAttribute("selected-fill") || "beige"}" visibility="hidden"/>
                    </svg>`;
    this.select();
    this.onclick = (evt) => this.toggle();
  }
  select(state = this.hasAttribute("selected")) {
    this.querySelector("circle:nth-child(2)").setAttribute("visibility" , state ? "visible" :"hidden");
  }
  toggle(){
    this.select( this.toggleAttribute("selected") );
  }
})
</script>

<style>
  svg-option {
    --svg-option-size:180px;
    width: var(--svg-option-size);
    height: var(--svg-option-size);
    cursor: pointer;
  }
  svg-option[selected]{
    background:lightgreen;
  }
  svg-option:not([selected]){
    background:pink;
  }
</style>

<svg-option></svg-option>
<svg-option fill="red" selected></svg-option>
<svg-option fill="rebeccapurple" selected-fill="yellow" selected></svg-option>

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