Skip to main content
Hosun
Inspiring
May 21, 2019
Answered

Media Query doesn't work?

  • May 21, 2019
  • 1 reply
  • 871 views

Hi,

I am just doing a simple exercise.

Can you tell me why media query doesn't work?

Hosun Kang

Link

EmRem

Tittle was edited by Moderator.

This topic has been closed for replies.
Correct answer osgood_

Hosun  wrote

Hi,

Thank you very much for your rely.


I want to see "px" is responsive under Media Query.

Seems to work here in Chrome, the text gets the 5px sizing when the window width is 800px or less.

The idea of working with em is you set the default font size in em on the html tag:

html {

    font-size: 2em;

}

Then change to what font-size you need for mobile.

@media (max-width: 800px) {

    html {

        font-size: 1em;

    }

}

The other em size declarations should adjust themselves in proportion and look better suited to smaller window sizes:

.col__em h1 {

    font-size: 2.5em;

}

.col__em p {

    font-size: 1em;

}

if you use px:

.col__em h1 {

    font-size: 25px;

}

.col__em p {

    font-size: 16px;

}

You have to adjust ALL sizes set in px:

@media (max-width: 800px) {

.col__em h1 {

    font-size: 20px;

}

.col__em p {

    font-size: 14px;

}

.col__em h2 {

    font-size: 15px;

}

.col__em h3 {

    font-size: 12px;

}

}

which for some can get a bit tedious. Personally I use px because its more specific.

1 reply

Legend
May 21, 2019

Add the 'viewport' meta tag to your <head></head> section:

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

Edited.

What is it you are testing - I see you are using em and rem - what is it you think should be happening?

Maybe this explanation might help:

Confused About REM and EM? | Jeremy Church

Hosun
HosunAuthor
Inspiring
May 21, 2019

Hi,

Thank you very much for your rely.

I added your tag.

It works on Edge, NOT Chrome.

As you see, I am learning EM and REM.

I want to see "px" is responsive under Media Query.

Hosun Kang

osgood_Correct answer
Legend
May 21, 2019

Hosun  wrote

Hi,

Thank you very much for your rely.


I want to see "px" is responsive under Media Query.

Seems to work here in Chrome, the text gets the 5px sizing when the window width is 800px or less.

The idea of working with em is you set the default font size in em on the html tag:

html {

    font-size: 2em;

}

Then change to what font-size you need for mobile.

@media (max-width: 800px) {

    html {

        font-size: 1em;

    }

}

The other em size declarations should adjust themselves in proportion and look better suited to smaller window sizes:

.col__em h1 {

    font-size: 2.5em;

}

.col__em p {

    font-size: 1em;

}

if you use px:

.col__em h1 {

    font-size: 25px;

}

.col__em p {

    font-size: 16px;

}

You have to adjust ALL sizes set in px:

@media (max-width: 800px) {

.col__em h1 {

    font-size: 20px;

}

.col__em p {

    font-size: 14px;

}

.col__em h2 {

    font-size: 15px;

}

.col__em h3 {

    font-size: 12px;

}

}

which for some can get a bit tedious. Personally I use px because its more specific.