gpt4 book ai didi

html - 如何使用 @media 查询使背景图像变大?

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

当我将视口(viewport)大小增加到 @media only screen/* Tablet */and (min-width: 768px) {} 时,我只是希望我的背景图像变大。

我试过背景大小:;但是那没有用。

然后我尝试使用不同的图像文件来应用背景大小:;也是,但仍然没有。

我该怎么做?

HTML:

    <advert class="bg-righttoleft">
<div class="title-shift">
<h1 class="title text-style">bla bla bla</h1>
<h3 class="title-shift-h3 text-style">bla bla bla</h3>
<p class="title-shift-p">bla bla bla</p>
</div>
<div class="channel">
<h3 class="chan-text">Review of the week</h3>
<a href="https://www.youtube.com/channel/UC-6OW5aJYBFM33zXQlBKPNA">
<img class="chan-img" src="./engadget.jpg" alt="Engadget logo"></a>
</div>
</advert>

CSS:

.container  {
display: grid;
grid-template-columns: 1fr;
grid-template-rows: 50px 340px 1fr 50px;
grid-template-areas:
"header"
"advert"
"main"
"footer";
text-align: center;
}

advert {
grid-area: advert;
background: url(./mi-vr-5.jpg);
background-position-x: 50%;
background-position-y: 75%;
background-size: 1000px;
}

@media only screen /* Tablet */
and (min-width: 768px) {
.container {
grid-template-columns: 1fr;
grid-template-rows: 50px 340px 1fr 50px;
grid-template-areas:
"header"
"advert"
"main"
"footer";
}

advert {
background: url(./mi-vr-5-tablet.jpg);
background-size: 2000px;
background-repeat: no-repeat;
font-size: 0.9em;
}
}

最佳答案

为了放大你的背景图片,你可以使用:

背景尺寸:宽度高度;

例如:

背景大小:200% 自动;

Temani Afif also meant that the closing tag "}" of @media only screen /* Tablet */ and (min-width: 768px) is missing

这是我的示例代码:

<div class="background"></div>

.background{
height: 200px;
width: 600px;
background-image: url('https://images.pexels.com/photos/1735092/pexels-photo-1735092.jpeg?auto=compress&cs=tinysrgb&dpr=2&w=500');
background-position: center center;
background-size: 1000px auto;
background-repeat: no-repeat;
}

关于html - 如何使用 @media 查询使背景图像变大?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54024484/

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