gpt4 book ai didi

html - 保持图像居中

转载 作者:太空宇宙 更新时间:2023-11-03 20:14:28 25 4
gpt4 key购买 nike

我有这个简单的 html:

<img src="http://i1.ytimg.com/vi/XWGszmviDpA/maxresdefault.jpg" class="bg">

到目前为止,只要窗口不小于图像,我就可以将图像正确居中。现在,当窗口较小时,我无法将脸保持在中间!我怎样才能解决这个问题?对我来说,图像高度保持在窗口的 100% 很重要。

我的CSS:

img.bg {  
width: auto;
height: 100%;
position: fixed;
left:0;
right:0;
margin:0 auto;

谢谢!

http://jsfiddle.net/67jDp/1/

最佳答案

尝试将其用作背景图像。CSS:

.bg {
background-image:url('http://i1.ytimg.com/vi/XWGszmviDpA/maxresdefault.jpg');
width: auto;
height: 100%;
position: fixed;
left:0;
right:0;
margin:0 auto;
width:70%; //Custom dimension
background-position:center;
background-size:cover;
}

演示:http://jsfiddle.net/lotusgodkk/67jDp/2/

关于html - 保持图像居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24246220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com