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.

mobile css sheet not working

Featured Replies

Hello,

 

I have created a test page and two style sheets (body background is red for screen and blue for handheld)

 

This doesnt work on either my windows 7 phone or iphone (shows as red which is the background i set for non mobile devices)

 

http://www.treendsolutions.co.uk/test/testtwo.htm

 

These are the tags I used, please view source on the test pages for html

<link rel="stylesheet" type="text/css" href="screen.css" media="Screen"  />
<link rel="stylesheet" type="text/css" href="mobile.css" media="handheld"  />

 

Thank you for any help

 

Darren

Edited by Renaissance-Design
Please use the code button or tags to format your code.

  • Author

Modern mobile browsers don't respect the handheld media attribute because they're designed to display desktop sites. Use media queries to switch between styles instead.

 

 

Thank you, just reading up on Media Queries at the moment, just tried the following in my style though and still no luck:

 

http://www.treendsolutions.co.uk/test/testtwo.htm

(update to css below):

 

@media only screen and (max-width:500px)

{

background-color:green;

}

Wait, try this

 

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

Edited by brightonmike

  • Author

Wait, try this

 

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

 

 

Sorry, i cant see what the difference in your code and mine (other than the space between "width:" and "500px", which i have updated but still no luck : )

I just checked your code. You're not actually telling the CSS to apply the green to the body.

 

body
{
background-color:red;
}


@media only screen and (max-width: 500px)
{
background-color:green;
}

 

You just have "background-color:green".

 

You need to specify the body selector inside the media query.

  • Author

I just checked your code. You're not actually telling the CSS to apply the green to the body.

 

body
{
background-color:red;
}


@media only screen and (max-width: 500px)
{
background-color:green;
}

 

You just have "background-color:green".

 

You need to specify the body selector inside the media query.

 

 

lol, well spotted, i think i was looking at this for too long to realise that, however how do i set the body details within a media query (syntax please?)

 

thanks again

  • Author

Exactly the same as you do normally. All you do is put the CSS you want applied by the media query inside of the query, as in inside it's curly brackets.

 

 

Thank you, that worked when reducing the screen size, however, my mobile still shows a red background (its windows 7 using internet explorer, could that be why?) will check on my wifes iphone shortly (she is on it at the moment)

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.