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

208
Vistas
Copying Text with Transparent Background

The easiest way to explain my issue is by using the Youtube site to replicate it. I am testing this on Mac OS, using Google Chrome 98:

Steps to Reproduce:

  1. Go to Youtube in Dark Mode (background is #181818) (it's easiest to see the effects in dark mode, but it should also work in light mode too but the background will be #f9f9f9)

  2. Open up Developer Tools and paste the following into the console:

const div = document.createElement("div");
div.style.position = "absolute";
div.style.left = "100px";
div.style.top = "300px";
div.innerText = "This is a test";
div.style.setProperty("background-color", "transparent", "important");
document.body.appendChild(div);
  1. Try copying the text and pasting into a Google Doc. A black background is seen.

My goal is to insert a div through JavaScript, such that when the text is copied and pasted, there is no black background. My suspicion is that since I'm setting the background to transparent, on copy, it is inheriting the page's background (since Youtube is setting the html { background: #181818 !important} within one of their script tags.

So instead of making the background transparent, if I try this: div.style.setProperty("background-color", "rgba(0,0,0,0.01)", "important");, the black background seemingly disappears (even though it is technically still there). Is there any way to make the text truly transparent on paste for an inserted div in this situation?

I do want to keep all other text formatting other than the background, so intercepting copy from JavaScript would not be ideal, and I'm looking for a CSS solution.

about 4 years ago · Juan Pablo Isaza
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