Detect small (mobile) screen in Javascript (or via css) - Stack Overflow

I want to make some of the fonts on my website larger, if a visitor is using a small screen. Ideally wi

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/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745388127a4625532.html

相关推荐

  • Detect small (mobile) screen in Javascript (or via css) - Stack Overflow

    I want to make some of the fonts on my website larger, if a visitor is using a small screen. Ideally wi

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信