基本使用方法:
主要使用的是%c字符,前用%c+需输出内容,后写css属性
console.log('%cHey there BP in your area 😎','padding: 0.3rem 1.5rem;color: white;background-color: #4158D0;background-image: linear-gradient(43deg, #4158D0 0%, #C850C0 46%, #FFCC70 100%);font-size:1.5em')
效果如图:
适用css属性:
支持大部分css属性如background、font、padding、color、border
友情提示:
在firefox浏览器中样式可能会乱掉、但firefox唯一比chromium多支持的属性是cursor属性
console.log('%cchrome中console.log的css样式不支持cursor属性 但firefox支持', 'padding: 0.3rem 1.5rem; font-family: Roboto; font-size: 1.2em; line-height: 1.4em; color: white; background: #003366; cursor: pointer;');