A Pen by Larry Geams Parangan.
body{
margin: 0px;
padding: 0px;
font-family: 'Lato', sans-serif;
}
h2{
font-weight: 250;
font-size: 50px;
}
h4{
font-weight: 200;
font-size: 30px;
}
article{
text-align: center;
color: #fff;
}
.red{
background: #B23751;
}
.blue{
background: #346CA5;
}
.green{
background: #65B237;
}
/*font face*/
@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 100;
src: local('Lato Hairline'), local('Lato-Hairline'), url(http://themes.googleusercontent.com/static/fonts/lato/v6/boeCNmOCCh-EWFLSfVffDg.woff) format('woff');
}
@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 300;
src: local('Lato Light'), local('Lato-Light'), url(http://themes.googleusercontent.com/static/fonts/lato/v6/KT3KS9Aol4WfR6Vas8kNcg.woff) format('woff');
}
@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 400;
src: local('Lato Regular'), local('Lato-Regular'), url(http://themes.googleusercontent.com/static/fonts/lato/v6/9k-RPmcnxYEPm8CNFsH2gg.woff) format('woff');
}
@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 700;
src: local('Lato Bold'), local('Lato-Bold'), url(http://themes.googleusercontent.com/static/fonts/lato/v6/wkfQbvfT_02e2IWO3yYueQ.woff) format('woff');
}
function isMobile(){
return $(window).innerWidth()<=680;
}
function resizeWindows() {
if (!isMobile()) {
$('.full-height').each(function (index, element) {
$(element).height($(window).innerHeight());
$(element).find('article').each(function (index, article) {
if ($(article).height() + (isMobile ? 0 : 90) > $(element).height())
$(element).height($(article).height() + (isMobile ? 0 : 90));
$(article).css('padding-top', ($(window).innerHeight() / 2 - $(article).height() / 2) - 60);
});// end article each condition
});
} //end of if condition
}//end of function
$(function () {
$(window).resize(function () { resizeWindows(); });
resizeWindows();
});
<section id="main" class="red full-height">
<article>
<h2>Auto Resize Div Height</h2>
<h4>{ Try zooming out or minimize your window }</h4>
</article>
</section>
<section class="blue full-height">
<article>
<h2>Div Height == Height of the window</h2>
<h4>{ See the CSS code if you can find any height attrb, nothing eh? }</h4>
</article>
</section>
<section class="green full-height">
<article>
<h2>Other than that, it's responsive</h2>
<h4>{ It's all in the JS }</h4>
</article>
</section>
The height of your div tag, well in my case I'm using an article tag, is set to be equivalent to the height of your window that can be done using this code e.g $(element).height($(window).innerHeight()); Try zooming out or minimizing your window to test it. Feel free to give feedbacks :)
A Pen by Larry Geams Parangan on CodePen.