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

246
Visualizações
Can I apply multiple CSS styles to Javascript `console.log` arguments?

Javascript's console.log allows me to apply CSS styles to the first argument like so:

console.log("%chey hey we're the monkees!", "font-weight: bold; color: fuchsia")

... which is awesome. But it doesn't play well with multiple log arguments. I'd like to do something like this:

console.log(`%c${timestamp}`, "color: #999", `%c${tags}`, "background-color: #bbb", message)
// doesn't work; second format code is not interpreted

Is there any way to apply multiple format codes to multiple console.log arguments?

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

0

You can indeed. You only need to add a second %c and then another console.log parameter in the same way as the first.

Example:

console.log(
  `%cMy first styles / %cMy second styles`,
  "font-size:24px",
  "font-size:12px;;"
);

So in your example, you should have the timestamp and tags in the same first parameter, and the next two parameters should be the independent styles, and finally your message:

console.log(`%c${timestamp} %c${tags}`, "background-color: #bbb","color: #999", message)
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