Cheetah
Cheetah

Reputation: 14379

Target browser size with CSS only

Is there a CSS selector for the size of the browser. So I can style elements if the browser is greater than 500px for instances.

My target browser is IE9 & IE10 in standards mode only; so I am only concerned about these two browsers.

Upvotes: 0

Views: 315

Answers (3)

cereallarceny
cereallarceny

Reputation: 4983

There isn't a selector in CSS for judging the size of one's screen. But I also wouldn't go the Javascript route if you don't have to. Perhaps you should look more into CSS media queries.

CSS 3 enhances support for media-dependent style sheets by letting style sheets be more precisely labeled. A media query consists of a media type and at least one expression that limits the style sheets' scope by using media features, such as width, height, and color. Media queries let the presentation of content be tailored to a specific range of output devices without having to change the content itself.

References:

https://developer.mozilla.org/en/CSS/Media_queries/

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

http://css-tricks.com/css-media-queries/

Upvotes: 0

Henrik Janbell
Henrik Janbell

Reputation: 1922

Sure, you can use media queries, like so:

@media screen and (min-width: 500px) { your css goes here }

Upvotes: 4

stephenmurdoch
stephenmurdoch

Reputation: 34613

can't you just use css media queries for this?

Upvotes: 1

Related Questions