CSS 缩放背景图像

发布于 2024-11-03 04:54:04 字数 769 浏览 1 评论 0 原文

当图像是内容时,我可以缩放图像以填充窗口,如下所示: (没有任何 html5 或 div)

  <style type="text/css">
img {
width:100%;
height:100%;
margin:0px;
}
  </style>

失败

<img src="wacard.png" alt="original image" title="">

,但是

了(“html,body”和“body”)

  <style type="text/css">
body {
width:100%;
height:100%;
margin:0px;
}
  </style>

并且

<body
 style="background-image: url(wacard.png);">
</body>

从这里拾取: 调整 HTML5 画布大小以适合窗口,但据我了解,这肯定有一些比我知道的更奇特的代码,继续,。 ..或者我做错了什么...

我怎样才能缩放背景图像? (理想情况下,没有 JavaScript)

i can get images scaled to fill the window when they are the content, like so:
(without any html5 or div)

  <style type="text/css">
img {
width:100%;
height:100%;
margin:0px;
}
  </style>

and

<img src="wacard.png" alt="original image" title="">

but

this fails (both "html, body" and just "body")

  <style type="text/css">
body {
width:100%;
height:100%;
margin:0px;
}
  </style>

and

<body
 style="background-image: url(wacard.png);">
</body>

as picked up picked up from here: Resize HTML5 canvas to fit window but as far as i understand, that must have some more fancy code than i know of, going on, ... or i'm doing something wrong...

how can i get background images to scale?
(ideally, without javascript)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

余厌 2024-11-10 04:54:04

这是一个很棒的教程,其中包含多种解决方案:
http://css-tricks.com/perfect-full-page-background-图片/
完成演示和逐步编码过程。

提到的HTML5方式是:

html {
        background: url(images/bg.jpg) no-repeat center center fixed;
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
}

文章中提到了一个ie修复。

Here is a great tutorial with several solutions:
http://css-tricks.com/perfect-full-page-background-image/
Complete with demos and the step by step coding process.

The HTML5 way mentioned is:

html {
        background: url(images/bg.jpg) no-repeat center center fixed;
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
}

There is an ie fix mentioned in the article.

旧情勿念 2024-11-10 04:54:04

据我了解,您想要创建一个整页可调整大小的背景。如果是这样,请按照此处的说明操作 => http://css-tricks.com/perfect-full-page-background-图片/

As I understand you want to create a full page re-sizable background. If so, follow the instructions here => http://css-tricks.com/perfect-full-page-background-image/

娇俏 2024-11-10 04:54:04

还要考虑进一步的审查和选项,就像我的例子一样,设置选项的值

background-position:

...

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

以及

background-origin:

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

伴随backgroundbackground-image CSS样式设置。

Also consider for further review and options, as in my case, the value of the

background-position:

setting options...

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

and also

background-origin:

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

that accompany the backbackground-image CSS style setting.

那些过往 2024-11-10 04:54:04

afaict,添加了背景图像,

例如背景:url(back.jpg) 固定;

使其缩放所需的一切,就是

background-size: cover;

少即是多。 ;)

afaict, with a background image added

e.g. background: url(back.jpg) fixed;

all that's needed to make it scale, is

background-size: cover;

less is more. ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文