深山工作室

深山工作室 >

css背景使用base64编码或者将base64编码放在img图片标签中

css背景使用base64编码或者将base64编码放在img图片标签中


将图片转为base64编码然后放在css的background背景中使用或者放在前台 img 图片标签中直接使用
减少HTTP请求,加快小图像或者小图标的加载时间。

// Base64 在CSS中背景图使用
.diymenu {
  background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAYAAACOEfKtAAAGi0lEQVR4Xu2baYgcRRTH/28mmeoeE9GgguKnoCh+8UOiqNF47MxsjBfq9oriRUBFjOIFIiJGCUHR4BlRUcQTMcaQy2S7J7dGo8ZICCHEJd63yRp3Z3p6NjtPerKG2WN2uqpm1mW26mu/36uqH6+6q6drCKZpGSAt2sAwAjWLwAg0AjUNaOKmAo1ATQOauKlAI1DTgCZuKtAI1DSgiZsKNAI1DWjipgKNQE0Dg3CrIzEPcWojYCoY+wF8S4Qn8qlg5XA9mQqssGJnxXIwLhtOFJf40UJrcd7ga0ZgvxHbE+sBXFCtnhn4p0R8djFV3FUZYwQCqCWvQtjzfjq4ywisXLY1Km9ARTI6/UxwshEYcdkOWc5EXX6qMMUIlFu2lb62+elg+rgXKHHPG1CERJibTwWLxrVAZXngN/Pp4k3jehujKg/AEj8VOCDwuBWoLI+x1P87cNCOvnH7JmJ7Yh2ACxVe+pb5RwcOpqO3Gtv0G2nbE1kALdLyGCv8g4GD2QhGYptaYNIVLhPS0vKAVf4RgYNz4Ndim1aglRWriTGrloDB15mxusCBg1bkorBNKdDyxCoCZkcRUBnDQEfBDhyci+6obNMJtD2xAsClUQX8F0cMT1DgdKVxQIZtKoG2J5YBuFxGQH/s2oQVOAfOQ5cs2zQC7az4EIwrZQUAWD+BEk53qnufAtscx9tsT3wA4GoFARvjYqLTM7PnTwW2jNSswEmbJh3LueLxuYuLO1Q7aSRne+J9AI5CH5tjNMHJpXK/K7CHkaoCk66YzcQPA3RWf/TPABb76eAenQ7rydqe9R7A1yjk/IRE3MnPzP+qwA5AhhVouWIVUdVtwAY/H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BhkZ8VmADMU+pZDCH/1V94GObCx0XoCw7FtgW3nrI0An9G4odJ+LiGsvLDix1TTFwjgyDWY0jtBrAPj9HrPjoEDIGorpArhKasx1+oiMJxV0k2ewOhbC8KpdZxld4nRFmQCt44565qqbgIPPZmtqcTsIfyfmX7LxQhtuVSwRj9V4zLUVWA4zEQ2cVq8RB0gnKgxbJ/iaMtfFHykkWNU0LoLLC/njonTOBYLJ3+cwiwCIrRV+3ekQr6GIg0RGI7Ydu0ZiJVWgnGUxAx6+ytvuQTzv4Y2TGD5nuhaLUQcntezI8yyD8yOnykujRA7ZkIaKrC8nD1xCQPhub34CLNmgB0/XRzxRMSYsVYxkIYLLC/njkQbYjQfwClDJDCHPwg842eKi8eioFpjGhWB4SAmr5h8zEGrGH5lm1be5jA6QdjudwVz0I6eWgMdq9dHTeBYFaA7LiNQ06ARaARqGtDETQUagZoGNHFTgUagpgFN3FSgEahpQBM3FWgEahrQxE0FGoGaBjTxfwEuZSVvUpE5IwAAAABJRU5ErkJggg==" />


经过Base64 编码后的文件体积一般比源文件大 30% 左右。
*请上传小于300KB的.jpg/.jpeg/.gif/.bmp/.png/.ico格式图片,不建议将大图转换。

前一页:利用css3中的-webkit-font-smoothing把网页文字的毛边去掉
后一页:利用background-color:#000000a8在背景颜色16进制代码之后加字母加上数字让背景色透明
相关阅读
RSA加密解密插件
微信公众号生成带参数的二维码asp源码下载
css背景使用base64编码或者将base64编码放在img图片标签中
ASP链接地址栏参数的加密
更多>>DIV+CSS相关信息
jquery设置或获取修改classname
利用css3.0写出一个音乐播放的唱片碟盘的效果
利用css中的scale()实现放大缩小效果
利用background-color:#000000a8在背景颜色16进制代码之后加字母加上数字让背景色透明
css背景使用base64编码或者将base64编码放在img图片标签中
更多>>最新添加
dw里面查找替换使用正则删除sqlserver里面的CONSTRAINT
Android移动端自动化测试:使用UIAutomatorViewer与Selenium定位元素
抖音直播音挂载小雪花 懂车帝小程序
javascript获取浏览器指纹可以用来做投票
火狐Mozilla Firefox出现:无法载入您的Firefox配置文件 它可能已经丢失 或是无法访问 问题解决集合处理办法