Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Media Query not working

Featured Replies

Good evening,

 

I am tweaking my responsive website with some media queries. I am trying to capture pages that are 613px or less and have used the following code:-

 

@media screen and (max-width: 613px) {
#header-wrap {position:fixed; top:0; left:0; width:100%; z-index:9999; background-color:#0F9; background-repeat:repeat-x;}
#header{height:75px;}
#menu-wrap{height:50px; padding-top:23px;}
#telephone{height:30px; background-color:#06F; text-align:right; padding-top:20px;}
#logo{height:75px; padding-top:20px; ;}
}

However it doesn't seem to pick up the media query until 486px.... I am a bit confused, am I missing something?


/* Smartphones (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}

/* Smartphones (landscape) ----------- */
@media only screen
and (min-width : 321px) {
/* Styles */
}

/* Smartphones (portrait) ----------- */
@media only screen
and (max-width : 320px) {
/* Styles */
}

/* iPads (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* Styles */
}

/* iPads (landscape) ----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
/* Styles */
}

/* iPads (portrait) ----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : portrait) {
/* Styles */
}

/* Desktops and laptops ----------- */
@media only screen
and (min-width : 1224px) {
/* Styles */
}

/* Large screens ----------- */
@media only screen
and (min-width : 1824px) {
/* Styles */
}

/* iPhone 4 ----------- */
@media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
}

Thanks for your post, it doesn't solve my problem though

try using media only screen instead of media screen

 

and write max-device width

 

@media only screen and (max-device-width: 613px) {
#header-wrap {position:fixed; top:0; left:0; width:100%; z-index:9999; background-color:#0F9; background-repeat:repeat-x;}
#header{height:75px;}
#menu-wrap{height:50px; padding-top:23px;}
#telephone{height:30px; background-color:#06F; text-align:right; padding-top:20px;}
#logo{height:75px; padding-top:20px; ;}
}

also make sure u have

 

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

within ur <head></head>

Hey Charly,

If you would like me to take a quick look you could send me a link to your site :)

As it stands though I'm guessing that changing -

@media screen and (max-width: 613px) {

to

@media (max-width: 613px) {

would solve your problem unless you have a reason to only target a specific screen type :)

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.