So, here the background-size of <main>
element is contain
, which cause it's container #main
contains the space towards the bottom on lower screen sizes.
So, I wanted to resize the height of #main
responsively according to <main>
's background-image height to remove the vertical gap in lower screen sizes.
Note that the background image shouldn't be stretched or hidden.
HTML
<div id="main">
<main>
</main>
</div>
CSS
#main{
width: 100%;
height: 70%;
}
main{
max-width: 100%;
height: 100%;
background: url(images/img-main.png) no-repeat top center;
background-size: contain;
}
JavaScript
var toHeight = $('main')//?????? I'm stacked here
$('#main').css('height',toHeight);
Any ideas?
Here's the jsfiddle demo (resize the window to understand)
+--------------------------+--------
| |
| background-image |
| height | main
| |
| | height
+--------------------------+
| vertical |
| gap |
+--------------------------+---------
Should be converted to:
+--------------------------+--------
| | main
| background-image |
| height | height
| |
| |
+--------------------------+----------