html - 居中全屏 html 图像(不是 css 中的图像)

标签 html css fullscreen

我正在尝试使用下面的代码使用 css 来获得全屏图像,这很容易。

width:100%;
height:100%;
background: url('photo2.jpg'); 
background-repeat: no-repeat;
background-position: center center;
background-attachment: fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;

但是图像已经放置在 html div 中,请参见此处

<div class="fixed-background">
  <img src="photo2.jpg"/>
</div>

它需要准确地使用 css 版本,唯一的区别是图像在 html 中调用,而不是在样式表中调用。

最佳答案

试试这个

<style>
body {
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
}

.fixed-background {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    overflow: hidden;
}

.myimg {
    height: inherit;
}
</style>

<html>
<body>
    <div class="fixed-background">
        <img src="public/dbs/images/1.jpg" class="myimg" />
    </div>
</body>
</html>

关于html - 居中全屏 html 图像(不是 css 中的图像),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25249802/

相关文章:

全屏 HTML5 中的 javascript 打开(页面元素)在 Internet Explorer 中失败

jquery - 用css全屏显示可以吗?

html - 带标题的居中图形

java - Fusion Charts FusionTime 从 mySQL 制作时间序列图表

android - 像素密度如何对应于屏幕尺寸?

javascript - 为什么 Bootstrap 工具提示没有初始化两次?

html 表单和 css : cannot center items

javascript - 窗口在方向更改时调整内容大小之前的触发功能?

html - Bootstrap中嵌入的pdf不是全高

html - 选择文本时元素的叠加