How to apply browser height to CSS class?

You can read your browser sizes with jQuerys $ document.height or with a simple JS in height: window.innerHeight || document.body.clientHeight.

But how to apply the value to the CSS class?

+3
source share
5 answers

You don’t need to complicate this too much - you don’t need to look for a way to apply height to the CSS class. Just give each class <div>a in HTML:

<div class="viewport_height">This is some content.</div>

then use jQuery code like this:

var document_height = $(document).height();
$('.viewport_height').css('height', document_height + 'px');

apply measured height to all elements of this class.

For a more reliable solution, attach the function to the event window onresizeto recalculate and apply the height when changing the height of the viewport.

0

JQuery

$('.targetClass').css('height',otherObject.height()+'px');
+1

/ / CSS ; // .

, , , .

0
source
$('#target').css('height',$(document.body).height()+'px')

(Jquery)

0
source

Find the rule object by browser ( http://www.javascriptkit.com/domref/cssrule.shtml )

Then you can edit the style object of the rule object and actually change the definition of the CSS class

0
source

Source: https://habr.com/ru/post/1745887/


All Articles