简体   繁体   English

媒体查询根本不起作用

[英]Media query doesn't work at all

After completing my whole website I was introduced to media queries as a way of making my website responsive.完成我的整个网站后,我被介绍了媒体查询,作为使我的网站响应的一种方式。 The thing is that even though I found many resources on Media queries and I know what to type they just don't work at all.问题是,即使我在媒体查询上找到了很多资源并且我知道要输入什么,但它们根本不起作用。

I first tried to test a media query in order to see how it works.我首先尝试测试媒体查询,以了解它是如何工作的。 This is the code:这是代码:

<style> 
@media screen and (min-width:600px){

#bigfont
{
    font-size: 80px;
    line-height: 79px;
    font-family: dosis, sans-serif;
    font-weight: 300;
}
}
 </style> 

"bigfont" is already a style in css. “bigfont”已经是css中的一种样式。 So when placing a media query it is supposed to bypass the original style and apply the new parameters.因此,在放置媒体查询时,它应该绕过原始样式并应用新参数。

Since my laptop screen's width was larger than 600px I was expecting it to work but it didn't.由于我的笔记本电脑屏幕的宽度大于 600 像素,我原以为它可以工作,但没有。 My goal is to use media queries in order to scale up my content when it comes to a really big screen.我的目标是使用媒体查询来扩展我的内容,当涉及到一个非常大的屏幕时。

I even changed min to max just in case with no result.我什至将 min 更改为 max 以防万一没有结果。

UPDATE :更新 :
I forgot to mention that I already have this:我忘了提到我已经有了这个:

<meta name="viewport" content="width=device-width, initial-scale=1">

You need to add a viewport meta element to the head of your HTML page(s) for media queries to take effect.您需要在 HTML 页面的head添加一个viewport元元素,媒体查询才能生效。 Eg例如

<meta name="viewport" content="width=device-width, initial-scale=1">

Have you tried with @media all and (min-width:600px){ ?您是否尝试过@media all and (min-width:600px){ That usually fixed it for me.这通常为我修复它。

If that does not work, try setting the values as !important (overwrites everything so far so you need to keep the !important part for larger screens, as you have min-width , and smaller if you have max-width ).如果这不起作用,请尝试将值设置为!important (覆盖所有内容,因此您需要为大屏幕保留!important部分,因为您有min-width ,如果您有max-width )。

    #bigfont
{
    font-size: 80px !important;
    line-height: 79px !important;
    font-family: dosis, sans-serif !important;
    font-weight: 300 !important;
}

Mine only worked after I put the media query block after the original code.我的只有在我将媒体查询块放在原始代码之后才起作用。

So like this:所以像这样:

Main code{
    .whatever{
    }
    #whatever{
    }
}
@mediaquery{
    .whatever{
     }
    #whatever {
    }
}

Put !important tag ie 'font-size: 80px !important;'放置 !important 标签,即 'font-size: 80px !important;' to apply the new parameters应用新参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM