Mobile virtual-keyboard pushes up content

I have an html layout / css problem in a basic chat application. There is a page with a chat-header a chat-body and a chat-footer. Body contains the messages, it is scrollable, the footer contains the text input. When the user clicks on the text input, the entire content is pushed up on mobile, and i can't see my header. Here is a snippet
body{
display: flex;
flex-direction: column;
padding: 0px;
margin: 0px;
overflow: hidden;
position: fixed;
top: 0px;
left: 0px;
height: 100svh;
}

.chat {
flex-grow: 1;
overflow: auto;
padding: 15px;
}

.footer,
.header {
padding: 15px;
background-color: cornflowerblue;
color: white;
}
body{
display: flex;
flex-direction: column;
padding: 0px;
margin: 0px;
overflow: hidden;
position: fixed;
top: 0px;
left: 0px;
height: 100svh;
}

.chat {
flex-grow: 1;
overflow: auto;
padding: 15px;
}

.footer,
.header {
padding: 15px;
background-color: cornflowerblue;
color: white;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>

<div class="header">
<button>Menu</button>
</div>
<div class="chat">
<!-- loremx500 -->
</div>
<div class="footer">
<input type="text" placeholder="Type here..." name="" id="">
</div>

</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>

<div class="header">
<button>Menu</button>
</div>
<div class="chat">
<!-- loremx500 -->
</div>
<div class="footer">
<input type="text" placeholder="Type here..." name="" id="">
</div>

</body>
</html>
2 Replies
Dr.Random
Dr.RandomOP2y ago
Here is how it looks like on mobile when the virtual keyboard is visible: https://i.stack.imgur.com/RNLmu.png The weird thing is that i can scroll the body or at least the document, even if i specified the following css for the body:
body{
display: flex;
flex-direction: column;
padding: 0px;
margin: 0px;
overflow: hidden;
position: fixed;
top: 0px;
left: 0px;
height: 100svh;
}
body{
display: flex;
flex-direction: column;
padding: 0px;
margin: 0px;
overflow: hidden;
position: fixed;
top: 0px;
left: 0px;
height: 100svh;
}
I have tried without flex box, with different positions and different javascript alternatives. Tried to make my header and footer fixed/absolute but it did not help either. When my footer is fixed, it works in a way, but the header does not. This javascript snippet is helping somewhat.
var body = document.querySelector("body");
if (window && window.visualViewport){
visualViewport.addEventListener('resize', function(){
let viewHeight = visualViewport.height;
body.style.height = `${viewHeight}px`;
});
}
var body = document.querySelector("body");
if (window && window.visualViewport){
visualViewport.addEventListener('resize', function(){
let viewHeight = visualViewport.height;
body.style.height = `${viewHeight}px`;
});
}
It does resize my body to the correct height when the virtual keyboard is visible but i can still scroll the entire document?? The javascript "fix" is what i want, but without the ability to scroll the document meanwhile. I want the same chat behaviour which is on discord or any other message platform. When the virtual keyboard pops up, i want to squeeze my chat message body into the available space along with my header and footer. Here is a gif demonstrating the javascript fix problem:
Dr.Random
Dr.RandomOP2y ago
Want results from more Discord servers?
Add your server