T
T
the_stucky2018-05-24 23:00:44
Web development
the_stucky, 2018-05-24 23:00:44

How valid is js for content alignment?

Good evening everyone.
I study the web, I look at different ways to organize the content of the site. Including the problem of the footer sticking to the screen base. One of the most publicized ways is to use the display:table property with an impressive wrapper layer that assigns display:table-row and table-cell.
It works, but it looks cumbersome and not visual enough, so I tried to make an alternative. How it works - we introduce a wrapper div for the main content, then we create a script that hangs a handler on loading and changing the page size that requests the height of the screen, header and footer, and based on them calculates the height of the block for the content.

Actually, the script code

function adjustHeight()
{
var hHead = parseInt(getComputedStyle(document.querySelector('header')).height);
var hFoot = parseInt(getComputedStyle(document.querySelector('footer')).height);
var HX = (window.outerHeight - hHead - hFoot) + 'px';
var root = document.querySelector('.mainWrapper');
var contentNode = root.firstChild;
var noElements = true;
while(contentNode){
if(contentNode.nodeType == Node.ELEMENT_NODE){
contentNode.style.minHeight = HX;
noElements = false;
}
contentNode = contentNode.nextSibling;
}
root.style.minHeight = noElements ? HX : 'auto';
}
window.onload = window.onresize = adjustHeight;

And now the question is - how acceptable is such a solution, since it is not supported by ancient browsers + it will not work for people who have disabled js ?
PS
I'm sorry, the indentation in the formatting of the script fell apart

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-05-24
@rockon404

Learn to typeset.
An example of a solution to your problem 1
An example of a solution to your problem 2
JavaScript is acceptable only where it is indispensable or its use would be a simpler and more rational solution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question