我有一些使用Base64背景图像的CSS类。它在本地主机上运行良好
thead th .both {
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAQAAADYWf5HAAAAkElEQVQoz7X QMQ5AQBCF4dWQSJxC5wwax1Cq1e7BAdxD5SL+Tq/QCM1oNiJidwox0355mXnG/DrEtIQ6azioNZQxI0ykPhTQIwhCR+BmBYtlK7kLJYwWCcJA9M4qdrZrd8pPjZWPtOqdRQy320YSV17OatFC4euts6z39GYMKRPCTKY9UnPQ6P+GtMRfGtPnBCiqhAeJPmkqAAAAAElFTkSuQmCC");
background-repeat: no-repeat;
}
但是当我将项目部署到服务器时,网址被解析为相对路径:
thead th .both {
background-image: url("/file/relativePath/toCssFile/data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAQAAADYWf5HAAAAkElEQVQoz7X QMQ5AQBCF4dWQSJxC5wwax1Cq1e7BAdxD5SL+Tq/QCM1oNiJidwox0355mXnG/DrEtIQ6azioNZQxI0ykPhTQIwhCR+BmBYtlK7kLJYwWCcJA9M4qdrZrd8pPjZWPtOqdRQy320YSV17OatFC4euts6z39GYMKRPCTKY9UnPQ6P+GtMRfGtPnBCiqhAeJPmkqAAAAAElFTkSuQmCC");
background-repeat: no-repeat;
}
您可以在jsFiddle中看到示例:HERE
问:有没有办法阻止浏览器将网址解析为相对路径或使相对路径与Base64图像一起使用?
答案 0 :(得分:0)
您的baseUrl仅适用于localhost,因为该URL存在于物理驱动器中。
/ file / relativePath / toCssFile /而不是提到你是主机端口和路径 背景图片: URL( “http://www.some.com/data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAQAAADYWf5HAAAAkElEQVQoz7X QMQ5AQBCF4dWQSJxC5wwax1Cq1e7BAdxD5SL + Tq的/ QCM1oNiJidwox0355mXnG / DrEtIQ6azioNZQxI0ykPhTQIwhCR + BmBYtlK7kLJYwWCcJA9M4qdrZrd8pPjZWPtOqdRQy320YSV17OatFC4euts6z39GYMKRPCTKY9UnPQ6P + GtMRfGtPnBCiqhAeJPmkqAAAAAElFTkSuQmCC”);