html - 渲染背景图像像素化 css
问题描述
我有一个小问题,这是我的代码。
img {
image-rendering: pixelated;
}
div.fight {
background: url("https://i.imgur.com/yM1ts8x.png");
background-size: contain;
width: 600px;
height: 300px;
position: relative;
}
div.fight img.player {
position: absolute;
bottom: 2%;
left: 4%;
height: 64px;
width: 64px;
}
<div class="fight">
<img src="https://i.imgur.com/VJhdtWy.png" class="player">
</div>
您可以在此处查看实际代码http://jsfiddle.net/ctwgkodp/11/。(请原谅我丑陋的像素艺术)
正如您在 中看到的img
,我将应用程序中的所有图像都设置为像素化。问题是当我设置时background
,我不能强迫它被像素化。
有没有办法强制像素化渲染到background
of div.fight
?
谢谢你,祝你有美好的一天。:)
解决方案
您只是将 应用于image-rendering: pixelated
标签img
。您还需要将其应用于.fight
div:
img {
image-rendering: pixelated;
}
div.fight{
background: url("https://i.imgur.com/yM1ts8x.png");
background-size: contain;
width: 600px;
height: 300px;
position: relative;
image-rendering: pixelated;
}
div.fight img.player{
position: absolute;
bottom: 2%;
left: 4%;
height: 64px;
width: 64px;
}
<div class="fight">
<img src="https://i.imgur.com/VJhdtWy.png" class="player">
</div>
实际上,您可以完全从 中删除 ,image-rendering
因为img
它将继承自 parent div
。
div.fight{
background: url("https://i.imgur.com/yM1ts8x.png");
background-size: contain;
width: 600px;
height: 300px;
position: relative;
image-rendering: pixelated;
}
div.fight img.player{
position: absolute;
bottom: 2%;
left: 4%;
height: 64px;
width: 64px;
}
<div class="fight">
<img src="https://i.imgur.com/VJhdtWy.png" class="player">
</div>
推荐阅读
- python - python - 获取列中两个日期之间的差异时出错
- spring - 在 Spring Boot 消息中使用参数 1 而不使用参数 0
- angular - Angular 11 中的非模态对话框
- reactjs - 如何将纱线工作区与 React 应用程序一起使用
- reactjs - 如何在步进器结束时打开一个新的反应组件?
- ansible - 使用 jmespath 连接复杂数据结构中的多个数组
- php - 执行 json_encode 时 PHP 7.4 的日期时间问题(我使用的是 Carbon)
- node.js - 在 workbook.addImage 中的 excel.js 中下载 AWS S3
- javascript - Nextjs 动态页面路由:在页面变量中使用扩展运算符 [...example] 或 [[...example]] 的目的是什么?
- java - Java:cmd jdk和jre版本区别