Questions tagged [media-queries]

Media queries enable the conditional application of CSS styles based on media types, such as screen and print, and the conditions of media features, such as viewport and device height and width. They are part of the W3C CSS3 specification.

CSS Media Queries allow you to limit the scope of CSS rules based on, for example, screen size, device orientation, or display density. Introduced in the CSS3 specification, the use of media queries has become the de facto standard behind building websites that utilize .

Every media query usually consists of a media type and can optionally contain one or more expressions which resolve to either true or false. If the media type matches the device the page is being viewed on and all expressions resolve to true, the corresponding style sheet or style rules are applied to the document.

<!-- Media Query on a link element -->
<link rel="stylesheet" href="style.css" media="(max-width: 750px)" />

<!-- Media Query within a stylesheet -->
<style>
@media (max-width: 750px) {
  footer {
    display: none;
  }
}
</style>

NOTE: Stylesheets that have media queries attached to their <link> elements will still download even if their media queries would return false.

Media Query Types

There are a handful of different media types, but the most commonly used are all, screen, and print. Including a media type is not always required based on whether or not your expression, or your own conditions, require it.

Media Query Expressions

Media query expressions can be created using the logical operators and, not, and only. Additionally, comma separated expressions constitutes the "or" operator.

  • The and operator is used to combine multiple media features into a single query. Each feature must return true for the entire query to be evaluate as true.

  • The min-width means greater than or equal to. Similarly max-width means less than or equal to.

     @media (min-width: 650px) and (orientation: landscape) { ... }
    
  • The not operator must be used with an explicit media type and is used to reverse the logic of an entire media query.

     @media not all and (max-width: 650px) { ... }
    
  • The only operator must be used with an explicit media type and tells older browsers not to process the query.

     @media only print { ... }
    
  • Comma separated expressions evaluates each expression with an "or" operator between them.

     @media (max-width: 600px), (min-width: 800px) { ... }
    

Additional Information on CSS Media Queries

7959 questions
2
votes
3 answers

Jquery and media queries

Simple question - Is it possible to use jquery with media queries so the jquery only happens below a certain screen size. I have a navigation that uses hover on the desktop but I need to use click on mobile. I have few other actions I want to…
duckhill
  • 21
  • 1
2
votes
1 answer

media queries overridden by general declarations

My common css rule is like: #dayslist > div { height: 51px; } and media Query css rule: @media (max-width: 979px){ #dayslist > div { height: 44px; } } But when I shrink my browser to width less than 979px the media query rule…
bhavya_w
  • 9,186
  • 9
  • 29
  • 38
2
votes
2 answers

Responsive Design with media queries not switching

Good afternoon, I am trying to make a website of mine responsive but i can't get it to work. I have been googling for about an hour or 3 and i am almost sure i am not doing it wrong but yet it does not work. Here is my code: @media screen and…
Maantje
  • 104
  • 1
  • 1
  • 10
2
votes
1 answer

font-size gets smaller on orientation change

I'm trying about responsive design. http://quirktools.com/screenfly/#u=http%3A//rus-turk.com/newyln/en.html%23secondPage&w=320&h=480&a=33&s=1 font-size seeming OK if to push any link or reload page but getting smaller with orientation change. also…
svt
  • 21
  • 3
2
votes
3 answers

print media queries and stylesheets are being ignored

i'm having an issue with a @media print {...} in my css. i want the left navigation bar to not display when i print the page. when printing, i currently see the crude image on the right while i would like to see the crude image in the middle: …
2
votes
1 answer

How do I change the position of the buttons in responsive design?

I am trying to change the positions of the buttons which will scale down to mobile relative to the image div. I tried position/absolute; but it didn't take effect. Neither did the buttons stay relative inside the image div. I am not sure if the…
2
votes
5 answers

How to hide image when resizing using max-device-width?

Need to have the img disappear when i'm viewing on a mobile device
@media screen and (max-device-width:450px) {...}}
ranopano
  • 509
  • 2
  • 16
  • 32
2
votes
3 answers

How to make responsive AdSense unit change its size on browser resize

I am using responsive AdSense unit in advanced mode. It works well until I decide to resize my browser window. Ad does not resize as specified in media query.