admin管理员组

文章数量:1423170

I want to make some of the fonts on my website larger, if a visitor is using a small screen. Ideally without jquery, as I want to do this early on in the page load, and I don't want to load jquery until later, for faster loading.

The best I have e up with, is to check for screen size. But this is far from perfect. An iphone4 has relatively large size, but small screen, while some old netbook might have a smaller resolution but a larger screen. I guess what I really want is some variant of screen "DPI".

If there is some css way of saying "on a small screen do this, else on a large screen do that" that would work too.

I want to make some of the fonts on my website larger, if a visitor is using a small screen. Ideally without jquery, as I want to do this early on in the page load, and I don't want to load jquery until later, for faster loading.

The best I have e up with, is to check for screen size. But this is far from perfect. An iphone4 has relatively large size, but small screen, while some old netbook might have a smaller resolution but a larger screen. I guess what I really want is some variant of screen "DPI".

If there is some css way of saying "on a small screen do this, else on a large screen do that" that would work too.

Share Improve this question asked Mar 20, 2011 at 8:58 bobbob 231 silver badge3 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

In CSS2 there's a media property and in CSS3 this can be used to do media queries. It's not supported on all browsers, but it may be okay to use since your small devices like iPhone etc do support it.

 @media screen and (min-width: 781px) and (max-width: 840px) {
    body {
      font-size: 13px;
    }
  }

This site doesn't care about IE, try it in FF or Safari, change the browser width and notice how the width changes using this property.

Media Queries are the key and are a lot of fun to use.

See http://jsfiddle/neebz/kn7y3/ and change the width/height of the 'Result' panel to see it working.

Example taken from : http://www.maxdesign..au/articles/css3-media-queries/media-sample/

本文标签: Detect small (mobile) screen in Javascript (or via css)Stack Overflow