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

226
Visualizações
Why don't my images get styles assigned through their class or ID in my css file

Whenever I assign a className or id to my img tag in my javascript (using react.js) and then a style that references that id or class, the style does not get applied, however when I do the same for a div everything works fine.

<--javascript-->

import React from "react";
import TitleImage from './Images/TitleBG.png'
import TitleImage2 from './Images/TitleMG.png'
import TitleImage3 from './Images/TitleCG.png'
import './heade.css'; 

const TopHeading = () => {

    return(

        //Here is a div with the ID "TopHeading", this style gets applied.

        <div id="TopHeading">

            {/*This image with class "image1" does not get its style applied.*/}

            <img className="image1" alt="Dofus" src={TitleImage}/>
            <img width='auto' alt = "Memory Game" height='50px' src={TitleImage2}/>
            <img width='auto' alt = "Character" height='50px' src={TitleImage3}/>
            <div className="aDiv"></div>
        </div>
    );
};

<--css-->

#TopHeading{
    display: grid;
    align-items: center;
    justify-items: center;
  
    background-color: rgb(131, 192, 131);
    height: 300px;
};

.image1{
    border-style: solid;
    width: auto; 
    height:250px;
}

.aDiv{
    size: 50px;
    border-style: solid;

Here you can see the ID's style getting applied to the div.

This shows that the ID gets applied to the div

And here is the image with the class's style being ignored fro some reason:

img tag class ignored

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

0

The semicolon before your class rule in your CSS is making your selector invalid. Don't put a semicolon outside of a rule's curly brackets { }.

This doesn't work

;
div
{
  height: 50px;
  width: 50px;
  background: red;
}
<div></div>

While this does

div
{
  height: 50px;
  width: 50px;
  background: red;
}
<div></div>

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