html - Responsive div is taller than 100% when I flip my smartphone to landscape. How to fix it? -


here html code divs (parent/child):

<div id="header">     <div id="elements">         <img style="margin: auto" class="img-responsive" src="https://s20.postimg.org/59ntjyiot/arvan_tourism_logo_web.png" alt="arvantourismlogo.png">         <p style="font-size: 2.5em; color: white">arvan tourism</p>         <p style="font-size: 1.5em; color: white">explore our wonderful albania.</p>         <button id="whatweofferbutton" class="btn btn-success" style="margin-top: 5px"> offer? </button>     </div> </div> 

here css code:

#header {     box-sizing: border-box;     background-image: url("https://s20.postimg.org/o8ddqmo7x/blue_eye.jpg");     background-size: cover;     background-position: center;     width: 100%;     height: 100%;     display: table; }  #elements {     display: table-cell;      text-align: center;     vertical-align: middle; } 

here screenshots of how looks on mobile.

portrait screenshot

landscape screenshot

what tweaks should perform can prevent being taller on landscape mode? using bootstrap framework.

you need detect change in orientation , , reset div height 100% of new viewport. here's how can it:

simple fix:

// listen orientation changes window.addeventlistener("orientationchange", function() {     $('.your_div').height('100%'); }, false); 

some browsers may not support event, safer way first check if event supported, , if not use 'resize' event. can achieve described in answer:

safer fix:

// detect whether device supports orientationchange event, otherwise fall // resize event. var supportsorientationchange = "onorientationchange" in window,     orientationevent = supportsorientationchange ? "orientationchange" : "resize";  window.addeventlistener(orientationevent, function() {    $('.your_div').height('100%'); }, false); 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -