# Determining screen size and/or resolution?

**URL:** <https://www.ruby-forum.com/t/determining-screen-size-and-or-resolution/58234>\
**Category:** Rails\
**Created:** [April 19, 2006, 9:24pm UTC](https://www.ruby-forum.com/t/determining-screen-size-and-or-resolution/58234 "2006-04-19T21:24:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nathandelane](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@nathandelane](https://www.ruby-forum.com/u/nathandelane)\
**Post date:** [April 19, 2006, 9:24pm UTC](https://www.ruby-forum.com/t/determining-screen-size-and-or-resolution/58234/1 "2006-04-19T21:24:38Z")

</div>

What’s the easiest or best way to determine the screen size from within  
a controller or view in Rails? My “divs” look great at 1280x800, but  
not so hot on 800x600. I want to dynamically alter the layout based on  
the resolution. Any hints regarding screen size or alternate ways of  
handling this issue would be appreciated.

Thanks!

---

<div class="post-metadata">

**Author:** ![nathandelane](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@nathandelane](https://www.ruby-forum.com/u/nathandelane)\
**Post date:** [April 19, 2006, 10:00pm UTC](https://www.ruby-forum.com/t/determining-screen-size-and-or-resolution/58234/2 "2006-04-19T22:00:08Z")

</div>

I would suggest not trying to find out, but instead learning how to  
design your CSS stylesheets to be independant of screen size.

I’m not really good at layout design, but the book “Cascading Style  
Sheets (3rd ed)” by Hakon Wium Lie and Bert Bos was helpful to me.

Maybe try here:

> **[My Top Ten CSS Tricks Article — SitePoint](https://www.sitepoint.com/top-ten-css-tricks/)**
>
> Read My Top Ten CSS Tricks Article and learn with SitePoint. Our web development and design tutorials, courses, and books will teach you HTML, CSS, JavaScript, PHP, Python, and more.

Google may help find good tutorials.

Good Luck,

Sean

Nathan L. wrote:

> What’s the easiest or best way to determine the screen size from within  
> a controller or view in Rails? My “divs” look great at 1280x800, but  
> not so hot on 800x600. I want to dynamically alter the layout based on  
> the resolution. Any hints regarding screen size or alternate ways of  
> handling this issue would be appreciated.
> 
> Thanks!

---

<div class="post-metadata">

**Author:** ![nathandelane](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@nathandelane](https://www.ruby-forum.com/u/nathandelane)\
**Post date:** [April 19, 2006, 10:14pm UTC](https://www.ruby-forum.com/t/determining-screen-size-and-or-resolution/58234/3 "2006-04-19T22:14:03Z")

</div>

There isn’t a reliable way to do this. You’d do it with javascript to  
get  
the objects width and height, but just about every browser and browser  
revision has changed the way this is accomplished. Look into javascript  
and  
see what you can find.

Good luck with it

---

<div class="post-metadata">

**Author:** ![nathandelane](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@nathandelane](https://www.ruby-forum.com/u/nathandelane)\
**Post date:** [April 19, 2006, 10:26pm UTC](https://www.ruby-forum.com/t/determining-screen-size-and-or-resolution/58234/4 "2006-04-19T22:26:25Z")

</div>

I was thinking about this too. Sometimes you need to know the screen  
size so that your site can look its best at all resolutions.

I would recommend having one CSS file per screen size, and loading the  
appropriate one using JavaScript. Dave Shea mentions this approach near  
the end of this podcast: [http://www.thinkvitamin.com/interviews/css/](http://www.thinkvitamin.com/interviews/css/)  
dave-shea/. He mentions a JS library that does this for him, but I  
don’t have the link.

HTH.

On Wednesday, April 19, 2006, at 10:00 PM, sean lynch wrote:

> > Thanks!
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

Cheers!  
–Dave T.  
[http://devlists.com](http://devlists.com) - Email list management  
[http://palmsphere.com](http://palmsphere.com) - Apps for your hand-held
