gpt4 book ai didi

javascript - 响应式设计,以图像为中心

转载 作者:行者123 更新时间:2023-11-28 11:19:36 25 4
gpt4 key购买 nike

<code>
<main>
<div id="inner-wrapper">
<img src="img/my-image.png" alt="" height="" width=""/>
<header>
<h1>..</h1>
<nav>
</nav>
</header>
</div>
</main>
</code>

大家好

我正在尝试将我的大学元素网站转换为响应式网站。我很难使用我的背景图像与该图像上的其余内容一起缩放到 768 像素,之后删除背景图像并定义不同的图案。我需要图像与页面上的其余内容一起居中。

最佳答案

我会使用 CSS 背景图片而不是包含图片标签。

#inner-wrapper {
background: url(img/my-image.png) no-repeat center top;
background-size: cover; /* this fills the container with the background image */
}

注意 background-size: cover;在 IE 8 及以下版本中不受支持,如果这些对您很重要。

以 768px 换出背景:

@media screen and (max-width 768px) {
#inner-wrapper {
background: url(img/my-pattern.png) repeat left top;
background-size: auto;
}
}

关于javascript - 响应式设计,以图像为中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21602111/

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