Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Media query font-size not working

Tags:

html

css

media

I searched, but didn't find anything similar to my problem.

#navigation {
  position: fixed;
  top: 0;
  width: 100%;
  color: #ffffff;
  height: 35px;
  text-align: center;
  padding-top: 15px;
  -webkit-box-shadow: 0px 0px 8px 0px #000000;
  -moz-box-shadow: 0px 0px 8px 0px #000000;
  box-shadow: 0px 0px 8px 0px #000000;
  background: url(../images/bg.jpg) repeat top left;
  z-index: 9999;
}
#navigation a {
  font-size: 15px;
  padding-left: 15px;
  padding-right: 15px;
  color: #F2B704;
  text-decoration: none;
}
#navigation a:hover {
  color: #D78E02;
}
@media only screen and (max-device-width: 480px) {
  #navigation a {
    font-size: 10px;
  }
}
<div id="navigation">
  <a href="#galerija">GALERIJA</a>
  <a href="#festival">FESTIVAL</a>
  <a href="#kontakt">KONTAKT</a>
</div>

Media query doesn't result in changing my font-size on smaller screen width, it still stays at 15px. What did I do wrong?

like image 680
Igor Jevremovic Avatar asked Dec 20 '15 10:12

Igor Jevremovic


People also ask

How do I change the font size in media query?

In the media query, specify the font size of the text at any particular width and the font size will alter according to the device type. Another method of performing this task is to use the viewport width. This method simply requires you to assign a certain font size to the text in 'vw' unit.

Why is my CSS media query not working?

CSS declared inline This may be the reason why your media queries aren't working. That is to say, you may have declared CSS within your HTML document. So if this is the case, simply go through the HTML document and remove the CSS declared inline. Alternatively, you can override the inline CSS with !

How do I set width and height in media query?

Use a comma to specify two (or more) different rules: @media screen and (max-width: 995px), screen and (max-height: 700px) { ... } Commas are used to combine multiple media queries into a single rule. Each query in a comma-separated list is treated separately from the others.

Can media queries determine the size of a viewport?

Media queries can be used to check many things, such as: width and height of the viewport. width and height of the device. orientation (is the tablet/phone in landscape or portrait mode?)


2 Answers

You use max-device-width: 480px in your media query so you have to havemeta viewport to browser detect the width of devices.

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

There is not wrong with your code. You can change max-device-width: 480px to max-width: 480px to see your code works. You only need to add meta viewport in your head tag.

Jsffidle

like image 123
Alex Avatar answered Sep 21 '22 23:09

Alex


Try this:

@media  (max-width: 480px) {
#navigation a {
  font-size: 10px !important;
} 
}
like image 42
Ketan Savaliya Avatar answered Sep 21 '22 23:09

Ketan Savaliya