CSS模板制作书签
制作CSS模板书签的方法
在浏览器中使用CSS模板书签可以快速修改网页样式。以下是制作步骤:
创建书签 打开浏览器书签管理器,新建一个书签。在URL字段填入以下JavaScript代码:
javascript:(function(){var css=prompt('输入CSS代码:','body{background:#f00 !important;}');if(css){var style=document.createElement('style');style.type='text/css';style.innerHTML=css;document.head.appendChild(style);}})();
使用书签 点击该书签会弹出对话框,输入CSS代码后即可应用到当前页面。例如输入以下代码改变背景色:
body {
background: #f0f0f0 !important;
color: #333 !important;
}
常用CSS模板示例
暗色模式模板

html, body {
background: #222 !important;
color: #eee !important;
}
a {
color: #7bf !important;
}
阅读模式模板
body {
max-width: 800px;
margin: 0 auto;
line-height: 1.6;
font-size: 18px;
padding: 20px;
}
高对比度模板
* {
background: #000 !important;
color: #0f0 !important;
border-color: #0f0 !important;
}
高级用法
持久化样式 使用localStorage保存CSS,刷新后仍然有效:

javascript:(function(){var css=prompt('CSS:',localStorage.getItem('customCSS')||'');if(css){localStorage.setItem('customCSS',css);var style=document.getElementById('customStyle')||document.createElement('style');style.id='customStyle';style.innerHTML=css;document.head.appendChild(style);}})();
切换样式 创建两个书签分别用于启用和禁用样式:
启用书签:
javascript:(function(){var style=document.getElementById('customStyle')||document.createElement('style');style.id='customStyle';style.innerHTML=localStorage.getItem('customCSS')||'';document.head.appendChild(style);})();
禁用书签:
javascript:(function(){var style=document.getElementById('customStyle');if(style)style.remove();})();






