admin管理员组文章数量:1296310
The output of console.log
can be styled and the basics are covered at the StackOverflow question Colors in JavaScript console.
Basic Styling
console.log('%c Oh my heavens! ', 'background: #222; color: #bada55');
Advanced Styling
What about advanced styles? How far can console.log
be styled?
How about images? Using background-image
doesn't seem to work.
How about display: block
? It seems that setting display: block
has no effect.
How about custom fonts? font-family
seems to work but how to use custom fonts?
For my use case, I only need Chrome support.
Edit
I managed to implement images. The trick is to use a padding to set the size of the image. For example:
var style = [
'background-image: url(".gif")',
'background-size: contain',
'background-repeat: no-repeat',
'color: #000',
'padding: 20px 20px',
'line-height: 0px'
].join(';');
console.log('%c ', style);
Edit 2
Firefox blocks external images in console styles, but supports dataURIs: . Also, Firefox let's you simply display: block
entries, see the list of properties supported by Firefox.
The output of console.log
can be styled and the basics are covered at the StackOverflow question Colors in JavaScript console.
Basic Styling
console.log('%c Oh my heavens! ', 'background: #222; color: #bada55');
Advanced Styling
What about advanced styles? How far can console.log
be styled?
How about images? Using background-image
doesn't seem to work.
How about display: block
? It seems that setting display: block
has no effect.
How about custom fonts? font-family
seems to work but how to use custom fonts?
For my use case, I only need Chrome support.
Edit
I managed to implement images. The trick is to use a padding to set the size of the image. For example:
var style = [
'background-image: url("https://media.giphy./media/3o85xoi6nNqJQJ95Qc/giphy.gif")',
'background-size: contain',
'background-repeat: no-repeat',
'color: #000',
'padding: 20px 20px',
'line-height: 0px'
].join(';');
console.log('%c ', style);
Edit 2
Firefox blocks external images in console styles, but supports dataURIs: https://bugzil.la/1134512. Also, Firefox let's you simply display: block
entries, see the list of properties supported by Firefox.
- developers.google./web/tools/chrome-devtools/console/… – Arthur Rubens Commented Jul 8, 2020 at 11:27
- @ArthurRubens I know about this but it is, unfortunately, nowhere close to a full spec. – brillout Commented Jul 8, 2020 at 11:41
- 2 You can inspect the source code of devtools frontend, it's in JS. – woxxom Commented Jul 8, 2020 at 11:43
- 1 You can do both. For the second thing see How do you inspect the web inspector in Chrome? – woxxom Commented Jul 8, 2020 at 11:49
-
1
Note (to self): Firefox blocks external images in console styles, but supports dataURIs. bugzil.la/1134512 (Also, Firefox let's you simple
display:block
entries.) – myf Commented Jul 10, 2020 at 11:51
1 Answer
Reset to default 13 +50Chrome / Chromium seems to allow CSS properties beginning with any of the following prefixes:
background
border
color
font
line
margin
padding
text
-webkit-background
-webkit-border
-webkit-font
-webkit-margin
-webkit-padding
-webkit-text
For pleteness' sake, @myf has already linked to the properties supported by Firefox. They are:
background
and its longhand equivalents.border-radius
border
and its longhand equivalentsbox-decoration-break
box-shadow
clear
and floatcolor
cursor
display
font
and its longhand equivalentsline-height
margin
outline
and its longhand equivalentspadding
text-*
properties such as text-transformwhite-space
word-spacing
and word-breakwriting-mode
本文标签: javascriptAdvanced styling of browser consolelogStack Overflow
版权声明:本文标题:javascript - Advanced styling of browser console.log - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741632229a2389434.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论