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

168
Vistas
Dark Mode Link Contrast HTML/CSS

I'm a false beginner with HTML, CSS, and Javascript (having done KhanAcademy stuff in the past but also having forgotten most of it). I'm working on trying to get a simple webpage with dark mode going (with as little Javascript as possible). The problem is, the links have low contrast in dark mode. I'm using this code to add a class of .dark-mode to the body element of my html and style it with CSS.

Javascript:

function myFunction() {
    var element = document.body;
    element.classList.toggle("dark-mode");
 }

CSS:

html, body {
    background-color: ivory;
    color: black;
}

.dark-mode {
  background-color: #142514;
  color: blanchedalmond;
}

button.right {
    float: right;
}

HTML:

<button class="right" onclick="myFunction()">Toggle Dark Mode</button>

I tried adding this to CSS, but I realize that the tag isn't getting class="dark-mode".

CSS:

a.dark-mode:link { color: lightskyblue; }
a.dark-mode:visited { color: #6d4b8d; }
a.dark-mode:hover { color: #ffffff; }
a.dark-mode:active { color: #ff4040; text-decoration:none; font-weight:normal; }

Could someone please help me figure out a method that is light on Javascript to either add the dark-mode class to the tag as well as to the body or specify that the tag should get these attributes when the body has the dark-mode class? Any help would be greatly appreciated.

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

0

The problem is that you are toggling a .dark-mode class on your <body/> element, but you are writing your CSS selectors as though they themselves would have a .dark-mode class.

This selector:

a.dark-mode {}

...would target an element that looks like this:

<a href="mysite.com" class="dark-mode">Link</a>

Because you want to target all anchors inside a <body/> with a class of .dark-mode you'll want to rewrite your selectors as:

.dark-mode a:link { color: lightskyblue; }
.dark-mode a:visited { color: #6d4b8d; }
.dark-mode a:hover { color: #ffffff; }
.dark-mode a:active { color: #ff4040; text-decoration:none; font-weight:normal; }

...which matches all anchors inside an element with class .dark-mode.

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