Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: Are view height (vh) and view width (vw) units widely supported?

I'm using 100vh to center a div vertically with line-height. This site puts support for vh and vw at around 70%, is that a fair assessment? Would you recommend using viewport units when building a site? I know this is a bit subjective, I'm just looking for opinions from more experienced web developers than I.

EDIT: Thanks for the input everyone, I do want it to look good on mobile, so I guess I'll have to forgo vh.

like image 863
Ber Avatar asked Feb 07 '14 09:02

Ber


People also ask

What is VH VW viewport height viewport width in CSS?

Viewport Height (vh). This unit is based on the height of the viewport. A value of 1vh is equal to 1% of the viewport height. Viewport Width (vw). This unit is based on the width of the viewport.

What is VH and VW CSS?

CSS Length Units vh and vw CSS3 introduced two units for representing size. vh , which stands for viewport height is relative to 1% of the viewport height. vw , which stands for viewport width is relative to 1% of the viewport width.

How do you use VH and VW CSS?

To use vh and vw values, just type “Nvh” or “Nvw” (where “N” represents the percentage of the viewport you'd like to cover) into any width or height field. So to cover 100% of the viewport, you'd set 100% for the width and 100vh for the height. To cover half of the viewport height, you'd set a height of 50vh.


1 Answers

use both CSS vh and jQuery, it's safer.
jQuery example:

var clientHeight = $( window ).height();   $('.element').css('height', clientHeight); 

and CSS:

.element {height: 100vh;} 
like image 122
user1473054 Avatar answered Oct 08 '22 21:10

user1473054