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

222
Visualizações
Need to put the image and text on same line

This is how it's looking

i need to make the icon and the text on the same line and close to each other, i tried usingdisplay: inline-block; but it didn't work, here's my code.

HTML:

<div className="Comment_Icon">
            <img src={StudentIcon} alt="StudentIcon" class="Student_Icon"></img>
            <div className="Comments">5 Class Comments</div>
    </div>

CSS:

.Student_Icon {
      height: 1vw;
      width: 1vw;
    
      display: inline-block;
    }
    
    .IconText {
          padding-top: 0.8vw;
          font-size: 1.5vw;
        }
    
    .Comments {
        font-size: 2.5vw;
        display: inline-block;
      }
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Use flex in this case as shown below

.IconText {
  padding-top: 0.8vw;
  font-size: 1.5vw;
}

.Comments {
  font-size: 2.5vw;
  display: inline-block;
}

.Comment_Icon {
  display: flex;
  flex-direction: row;
  align-items: center;
}

.Student_Icon {
  margin-right: 3px;
}
<div class="Comment_Icon">
  <img src={StudentIcon} alt="StudentIcon" class="Student_Icon"></img>
  <div class="Comments">5 Class Comments</div>
</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

You can achieve this with flexbox styling. Note that I am changing your React structure a bit and also adding a fake image. And did you mean to use 1vw? that means 1% of the viewport width and is pretty small - esp on small screens.

Using and referencing REM units is more reliable ( REM is set in the root element and is usually 16px but can be changed. But the advantage of using rems is that it is a common size that all elements can access.

.Comment_Icon {
  display: flex;
  align-items: center;
}

.Student_Icon {
  height: 1.5rem;
  width: 1.5rem;
}


.Comments {
    font-size: 1rem;
    margin-left: 8px;
  }
<div class="Comment_Icon">
  <img src="https://hipsiti.com/uploads/default-profile.png" alt="StudentIcon" class="Student_Icon"/>
  <span class="Comments">5 Class Comments</span>
</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

.Student_Icon {
      float: left;
      padding-right: 10px;
    }
    
    .IconText {
          padding-top: 0.8vw;
          font-size: 1.5vw;
        }
    
    .Comments {
        font-size: 2.5vw;
        display: inline-block;
      }
<div className="Comment_Icon">
    <img src=https://via.placeholder.com/20 class="Student_Icon"></img>
    <div className="Comments">5 Class Comments</div>
</div>

I made use of float: left; So the icon/image comes left and the text next to it.

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