Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS get height of screen resolution

Tags:

css

I'm having a hard time getting the height of lower screen resolution because my screen resolution is 1920x1080.

Does anyone know how to get height and width of the screen resolution?

I checked my work on a 1024x768 resolution and it is rendered all messed up.

like image 564
FishBowlGuy Avatar asked Jul 17 '12 05:07

FishBowlGuy


People also ask

How do I check my screen height in CSS?

It is not possible to get the height of the screen from CSS. However, using since CSS3 you can use media queries to control the display of the template as per the resolution. If you want to code on the basis of height using media queries, you can define style-sheet and call it like this.

How do I find device height?

Display display = getWindowManager(). getDefaultDisplay(); Point size = new Point(); display. getSize(size); int width = size. x; int height = size.

How do you measure screen width in CSS?

Use the CSS3 Viewport-percentage feature. Assuming you want the body width size to be a ratio of the browser's view port. I added a border so you can see the body resize as you change your browser width or height. I used a ratio of 90% of the view-port size.


2 Answers

You could use viewport-percentage lenghts.

See: http://stanhub.com/how-to-make-div-element-100-height-of-browser-window-using-css-only/

It works like this:

.element{     height: 100vh; /* For 100% screen height */     width:  100vw; /* For 100% screen width */ } 

More info also available through Mozilla Developer Network and W3C.

like image 95
Hendrik Eichler Avatar answered Oct 11 '22 02:10

Hendrik Eichler


Adding to @Hendrik Eichler Answer, the n vh uses n% of the viewport's initial containing block.

.element{     height: 50vh; /* Would mean 50% of Viewport height */     width:  75vw; /* Would mean 75% of Viewport width*/ } 

Also, the viewport height is for devices of any resolution, the view port height, width is one of the best ways (similar to css design using % values but basing it on the device's view port height and width)

vh
Equal to 1% of the height of the viewport's initial containing block.

vw
Equal to 1% of the width of the viewport's initial containing block.

vi
Equal to 1% of the size of the initial containing block, in the direction of the root element’s inline axis.

vb
Equal to 1% of the size of the initial containing block, in the direction of the root element’s block axis.

vmin
Equal to the smaller of vw and vh.

vmax
Equal to the larger of vw and vh.

Ref: https://developer.mozilla.org/en-US/docs/Web/CSS/length#Viewport-percentage_lengths

like image 23
Kailas Avatar answered Oct 11 '22 03:10

Kailas