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

118
Vistas
Load additional CSS file w/ a toggle switch when switched

I have a additional css file I would like to load, once enabled through a toggle switch. & inversely allow it to be unset and revert back to the default .css file when un-switched.

I seem to be having a bit a troubles in successfully adding this, as writing java-script is a bit tricky for me sometimes. So I call on the community to offer their input & how they would go about adding this ability. Thanks to everyone in advance for you're time & reading!

Here is the URL for the site: (https://phpstack-726541-2423367.cloudwaysapps.com/) You can see the toggle switch in the top right corner

It would be greatly appreciated for the simplest solution possible to this :)

????
Bootstrap toggle switch, so no custom or additonal css to include. 
The path for the intended css file is 'assets/css/dark-theme.css'
<div class="custom-control custom-switch" style = "display: inline-block; padding: 0px 10px 0px 10px;">
<input type="checkbox" class="custom-control-input" id="customSwitch1">
<label class="custom-control-label" for="customSwitch1"></label>
</div>

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

0

TL;DR. Switch CSS classes to control color themes

You might want to review this answer: https://stackoverflow.com/a/63087710/7216508

I understand you are using Bootstrap, and thus the code snippet below might not be ready-to-use by simple copy-paste. But hope it'd give you a general understanding of how this could be achieved.

In a nut-shell, you could assign theme colors in CSS variables and override their values depending on the user selection. In your case you might want to merge the two CSS files and refactor the structure a bit.

document.querySelector('.switch').addEventListener('click', () => {
  document.body.classList.toggle('dark');
});
:root {
  --bg-nav: #333;
  --bg-body: #f0f0f0;
  --text-nav: #fff;
  --text-body: #202020;
}

body {
  margin: 0;
  min-height: 100vh;
  position: relative;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-body);
  color: var(--text-body);
}

body.dark {
  --bg-nav: #112200;
  --bg-body: #333;
  --text-nav: #fff;
  --text-body: #fff;
}
main {
  flex: 1;
  padding: 15px;
}

header, footer {
  background-color: var(--bg-nav);
  color: var(--text-nav);
  padding: 10px;
}
<header>Header Nav</header>
<main>
  <h1>Test Page</h1>
  <p>Here is a sample page</p>
  <button class="switch">Switch theme</button>
</main>
<footer>Footer Nav</footer>

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