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

151
Visualizações
Apply same HTML class to group of elements

In HTML I have this:

<a id="hdr20"></a>
<div class="hdr-bar">
  <a href="#" class="hdr-btn">Top</a>
  <a href="#hdr19" class="hdr-btn">ToS</a>
  <a href="#hdr2" class="hdr-btn">ToC</a>
  <a href="#hdr21" class="hdr-btn">Skip</a>
</div>

I would like to use DRY (Don't Repeat Yourself) method and use something like this:

<a id="hdr20"></a>
<div class="hdr-bar">
  <class="hdr-btn">
    <a href="#">Top</a>
    <a href="#hdr19">ToS</a>
    <a href="#hdr2">ToC</a>
    <a href="#hdr21">Skip</a>
  </class>
</div>

I've tried <span class="hdr-btn but that doesn't work.

I've tried changing the: <div class="hdr-bar" to: <div class="hdr-bar hdr-btn" but that doesn't work.


Existing CSS

The CSS works great:


.hdr-bar {
  display: block;
  position: relative;
  width: 100%;
  height: .5rem;            // Allow bit extra for button box height
  text-align: right;        // Don't use "float: right;" that breaks rendering order
  &:before {
    content: "";
    display: block;
  }
}

.hdr-btn {
  display: inline-block;
  position: relative;
  color: $header-bg-color;  // Cayman green
  padding: 5px 15px;        // vertical, horizontal padding around button text
  font-size:0.75em;         // 75% of normal font for button text
  margin-left: 10px;        // Now that right aligned, switch margin side
  // From: https://stackoverflow.com/questions/65297617
  background: linear-gradient(transparent,rgba(0, 0, 0, 0.4)) top/100% 800%;
  background-color: $honeydew; // Honeydew

  &:hover {
    background-position:bottom;
    color:#F0FFF0;
  }
}

Perhaps it's possible to assign the hdr-btn class to all elements within the hdr-bar class using JavaScript?

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

0

Probably the closest thing to what you want is the .hdr-bar > a CSS selector, which would select every <a> element under .hdr-bar.

<a id="hdr20"></a>
<div class="hdr-bar">
  <a href="#">Top</a>
  <a href="#hdr19">ToS</a>
  <a href="#hdr2">ToC</a>
  <a href="#hdr21">Skip</a>
</div>
.hdr-bar {
  display: block;
  position: relative;
  width: 100%;
  height: .5rem;            // Allow bit extra for button box height
  text-align: right;        // Don't use "float: right;" that breaks rendering order
  &:before {
    content: "";
    display: block;
  }
}

/* here! */
.hdr-bar > a {
  display: inline-block;
  position: relative;
  color: $header-bg-color;  // Cayman green
  padding: 5px 15px;        // vertical, horizontal padding around button text
  font-size:0.75em;         // 75% of normal font for button text
  margin-left: 10px;        // Now that right aligned, switch margin side
  // From: https://stackoverflow.com/questions/65297617
  background: linear-gradient(transparent,rgba(0, 0, 0, 0.4)) top/100% 800%;
  background-color: $honeydew; // Honeydew

  &:hover {
    background-position:bottom;
    color:#F0FFF0;
  }
}
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