Check users resolution in css?

纵饮孤独 提交于 2019-12-04 19:27:42

Not with CSS, no. But with JS, sure.

if (window.screen.width <= 800 && window.screen.height <= 600) {
    //do something();
}

css3 media queries will allow you to apply stylesheets or @media rules according to the size of the client, among other properties.

They don't fallback in non comforming browsers, so they are not ripe for general use, but if you are young it may be worth learning how it is done.

http://www.w3.org/TR/css3-mediaqueries/

To apply a style sheet to a document when displayed on a screen greater than 800 pixels wide:

<link rel="stylesheet" media="screen and (min-device-width: 800px)" >

To apply a style sheet to a document when displayed on any device less than 400 pixels wide:

<link rel="stylesheet" media="all and (max-device-width: 400px)" >

This media query expresses rules for screen and handheld devices if the width of the viewport is greater than 20em.

@media handheld and (min-width: 20em), screen and (min-width: 20em) { ... }

The ‘em’ value is relative to the font size of the root element.

You can't check the resolution with CSS. But you can make up fluid designs.

Take a look at Little boxes for some great starters.

Grz, Kris.

You can't do that in standard CSS. Maybe it'll be OK in (only) IE browsers.

Or you can use JavaScript.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!