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.
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.
Display display = getWindowManager(). getDefaultDisplay(); Point size = new Point(); display. getSize(size); int width = size. x; int height = size.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With