[英]CSS @media problems
I'm trying to use the @media thingy in CSS and I ran into some problems.我正在尝试在 CSS 中使用@media thingy,但遇到了一些问题。
Here is my CSS code (I have a massive screen):这是我的 CSS 代码(我的屏幕很大):
#headerImage {
width: 1000px;
height: 1000px;
}
The 1000px header image is just right for me on my big screen. 1000px header 图像在我的大屏幕上正好适合我。 But since I'm making a website for a company, I have to consider about the viewer's screen size, so I researched on W3Schools and found out about the @media thing.但是由于我正在为一家公司制作网站,因此我必须考虑查看者的屏幕尺寸,因此我研究了W3Schools并发现了 @media 的事情。
So then, I put the @media thing into my CSS.然后,我将@media 东西放入我的 CSS 中。 Here's the @media:这是@media:
@media only screen and (max-height: 700px) {
#headerImage {
width: 500px;
height: 500px;
}
}
Good.好的。 I went back to the website, and reloaded it.我回到网站,重新加载它。 1000px
. 1000px
。 Good.好的。
Now, I resized the height of the browser to something less than 700px
.现在,我将浏览器的高度调整为小于700px
。 (I made the height small so it's definitely < 700px
) No. It's still 1000px
. (我把高度调小了,所以它绝对是 < 700px
)不,它仍然是1000px
。
Is there anything wrong?有什么问题吗?
Edit:编辑:
NOTE: I am using Chrome Version 96.0.4664.110 (Official Build) (x86_64)注意:我使用的是 Chrome 版本 96.0.4664.110(官方版本)(x86_64)
Here's a bit of my HTML:这是我的一点 HTML:
<img id="headerImage" src="logo.png">
And also, do you need <meta>
?而且,你需要<meta>
吗? I have it here:我这里有:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
try this once you can try in mobile too height:100vh is you want full screen image试试这个,一旦你可以在移动设备上尝试高度:100vh 你想要全屏图像吗
#headerImage {
width: 100%;
height:100vh;
}
@media only screen and (max-height: 700px) {
#headerImage {
width: 100%;
height: auto;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.