gpt4 book ai didi

CSS 图像背景 - 将高度拉伸(stretch)到 100% 但保持图像在页面上水平居中

转载 作者:行者123 更新时间:2023-11-28 18:58:02 24 4
gpt4 key购买 nike

任何帮助将不胜感激!!

我正在处理的页面在这里 http://www.iknowpost.com/

我试图做的是将背景图像拉伸(stretch)到 100% 高度,而不管查看者的屏幕大小如何,同时始终使图像在页面上水平居中。到目前为止,我已经弄清楚了 100% 的高度,但我一直在尝试弄清楚如何将它水平居中,但没有成功——目前它是固定的 left: 0px;我认为这应该很简单。我的代码在下面,也许这不是解决这个问题的正确方法。谢谢!

<style type="text/css">
#background {
width: 100%;
height: 100%;
position: fixed;
left: 0px;
top: 0px;
z-index: -1;
}

.stretch {
height:100%;
}
</style>

</head>

<body>
<div id="background">
<img src="logo.jpg" class="stretch" alt="" />
</div>
</body>
</html>

最佳答案

也许这会有所帮助

<html>
<head>
<style type="text/css">
#background {
width: 700px;
height: 100%;
margin: 0 auto;
z-index: -1;
}

.stretch{
height:100%;
}
</style>
</head>
<body>
<div id="background">
<img src="logo.jpg" class="stretch" alt="" />
</div>
</body>

关于CSS 图像背景 - 将高度拉伸(stretch)到 100% 但保持图像在页面上水平居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7153053/

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