簡體   English   中英

如何在 console.log 中設置文本背景顏色的樣式?

[英]How can I style the text background color in a console.log?

我正在嘗試設置console.log()消息的樣式,使其看起來更好(背景顏色、文本顏色等......)。

我正在使用以下代碼:

console.log('%c Created by' + '%c www.google.com', 'background: #13212E; color: #FFF; padding: 5px 10px;', 'background: #05E5C8; color: #13212E; padding: 5px 10px;');

Chrome 控制台中的輸出如下:

Console.log() 輸出

正如您所看到的,它幾乎是完美的,但color樣式並未應用於鏈接(“www.google.com”),我還想刪除白色背景。

有沒有辦法為console.log()消息中的鏈接設置這些屬性的樣式?

const colors = {
 Reset: "\x1b[0m",
 Bright: "\x1b[1m",
 Dim: "\x1b[2m",
 Underscore: "\x1b[4m",
 Blink: "\x1b[5m",
 Reverse: "\x1b[7m",
 Hidden: "\x1b[8m",
 fg: {
  Black: "\x1b[30m",
  Red: "\x1b[31m",
  Green: "\x1b[32m",
  Yellow: "\x1b[33m",
  Blue: "\x1b[34m",
  Magenta: "\x1b[35m",
  Cyan: "\x1b[36m",
  White: "\x1b[37m",
  Crimson: "\x1b[38m"
 },
 bg: {
  Black: "\x1b[40m",
  Red: "\x1b[41m",
  Green: "\x1b[42m",
  Yellow: "\x1b[43m",
  Blue: "\x1b[44m",
  Magenta: "\x1b[45m",
  Cyan: "\x1b[46m",
  White: "\x1b[47m",
  Crimson: "\x1b[48m"
 }
};

console.log(colors.bg.Blue, colors.fg.White , "'%c Created by' + '%c www.google.com'", colors.Reset);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM