Css媒体查询不起作用(字体大小增加)

huangapple go评论53阅读模式
英文:

Css media query not working (font size increase)

问题

我有一个使用“媒体查询”的问题。它对我从未起作用,我已经搜索了很多次,但找不到解决方法。
以下是代码,我试图在小设备(最大宽度为576px)中将字体大小从44px增加到70px。

CSS部分:

/*主标题样式*/

.title {
    font-size: 44px;
    font-weight: 700;
}

/*媒体查询标题样式*/
@media screen and (max-width: 576px) {
    .title {
        font-size: 70px!important;
    }
}

HTML部分:

<div class="container">
    <div class="row">
        <div class="content col-lg-6 col-sm-12">
            <h1 class="title mb-3">在不到5分钟内托管您的网站。</h1>
        </div>
    </div>
</div>

我尝试过使用“@media screen and (max-width: 576px)”和“@media (max-width: 576px)”两种方式。我还使用了从Bootstrap库中引入的类“fs-sm-1”,但对我来说字体太小了。

我期望在小型设备上,字体大小从44px增加到70px。

英文:

I have a problem using "media query". It never works for me and I searched many times and can't find the solution.
here is the code below and I am trying to increase the font size from 44px -->> 70px in small devices (576px max-width)

CSS👇🏾


/*main title style*/

.title {
    font-size: 44px;
    font-weight: 700;
}

/*media query title styling*/
@media screen and(max-width: 576px) {
    .title {
        font-size: 70px!important;
    }
}

Html 👇🏾

&lt;div class=&quot;container&quot;&gt;
                &lt;div class=&quot;row&quot;&gt;
                    &lt;div class=&quot;content col-lg-6 col-sm-12&quot;&gt;

                            &lt;h1 class=&quot;title mb-3&quot;&gt;Host your website in less than 5 minutes.&lt;/h1&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

I tried using both "@media screen and(max-width: 576px)" and "@media (max-width: 576px)"

I also used the class "fs-sm-1" brought from bootstrap library but it was too small for me.

I expect the font size to increase from 44px >> 70px in small devices

答案1

得分: 0

你只需在70px!important之间,以及and(max-width: 576px)之间加入一个空格。

英文:

you just need to put a space between 70px and !important. and also between and and (max-width: 576px).

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

/*main title style*/

.title {
    font-size: 44px;
    font-weight: 700;
}

/*media query title styling*/
@media screen and (max-width: 576px) {
    .title {
        font-size: 70px !important;
    }
}

<!-- language: lang-html -->

&lt;div class=&quot;container&quot;&gt;
                &lt;div class=&quot;row&quot;&gt;
                    &lt;div class=&quot;content col-lg-6 col-sm-12&quot;&gt;

                            &lt;h1 class=&quot;title mb-3&quot;&gt;Host your website in less than 5 minutes.&lt;/h1&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

答案2

得分: 0

我还注意到我没有添加正确的标签,以便"媒体查询"能够正常工作。

确保您添加以下代码,以使您的媒体查询正常工作:

&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
英文:

I also noticed that I did not add the proper <meta> tag so that "media queries" work.

make sure you add the
&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;

so your media queries work

huangapple
  • 本文由 发表于 2023年2月18日 02:41:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75488177.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定