有没有办法从 html 调整背景图像的大小

Posted

技术标签:

【中文标题】有没有办法从 html 调整背景图像的大小【英文标题】:is there a way to resize background images FROM html 【发布时间】:2021-01-30 21:31:40 【问题描述】:

所以,在 html 中获取背景的正常方法是这样的:

<style>

body 
  background-image: url('https://media.giphy.com/media/itTRilS6MUfqMCQbgZ/giphy.gif');


</style>

但是现在让我们假设我需要更大的背景,GIPHY 不允许的这么大,你不能使用width=''height='',所以现在有没有办法我可以做到直接来自html?

【问题讨论】:

或者,更有用的是,你能把它放在屏幕上吗? 【参考方案1】:

您可以在 CSS 中使用 background-sizebackground-position

https://developer.mozilla.org/en-US/docs/Web/CSS/background-size https://developer.mozilla.org/en-US/docs/Web/CSS/background-position

【讨论】:

以上是关于有没有办法从 html 调整背景图像的大小的主要内容,如果未能解决你的问题,请参考以下文章