Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

173
Vistas
CSS not changing style of a button

I am trying to change the background color of a button in css. The CSS link is working fine, the button changes color when I try to apply bootstrap or use DOM to change the color, but not when I use CSS.

Here's the code:

// let sexybutton= document.querySelector('.sexy');

// sexybutton.style.backgroundColor="red";

// console.log(sexybutton.style);

//Currently commented it out because I do not want to do it this way. Put this here to inform that the button style changes using this method. 
.body{
    background-color:#CCD6A6
};

.sexy{
    background-color: red
};
HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://kit.fontawesome.com/fdee82af88.js" crossorigin="anonymous"></script>

  <link rel="canonical" href="https://getbootstrap.com/docs/4.0/examples/album/">
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Permanent+Marker&display=swap" rel="stylesheet">

  <!-- Bootstrap core CSS -->
  <link href="https://getbootstrap.com/docs/4.0/dist/css/bootstrap.min.css" rel="stylesheet">

  <!-- Custom styles for this template -->
  
  <link rel="stylesheet" href="style.css">
</head>
<body class="body" >
    <button class="sexy" type="submit">Click this</button>
</body>

<script src="index.js"></script>
</html>

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Your CSS syntax is wrong. The semi-colon ; must be placed after each CSS property, not after each CSS rule.

.body{
    background-color:#CCD6A6;
}

.sexy{
    background-color: red;
}
<!-- Bootstrap core CSS -->
<link href="https://getbootstrap.com/docs/4.0/dist/css/bootstrap.min.css" rel="stylesheet">

<body class="body" >
    <button class="sexy" type="submit">Click this</button>
</body>

about 4 years ago · Juan Pablo Isaza Denunciar

0

CSS isn't a C/C++ or anything else that requires semicolon. You can't type a semi-colon to end of the style.

You wrote;

.body{
    background-color:#CCD6A6
};

.sexy{
    background-color: red
};

but this is correct one;

.body{
    background-color:#CCD6A6;
}

.sexy{
    background-color: red;
}

You must to write semicolon to end of the line. As you can see, line ending with : red;. Not like };

about 4 years ago · Juan Pablo Isaza Denunciar

0

it's unreadable, your semi-colon placement is not correct

.body{
background-color:#CCD6A6
};

.sexy{
background-color: red
};

correct

.body{
background-color:#CCD6A6;
}

.sexy{
background-color: red;
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda