Consider an autosuggest input sitting in a container with some content and a vertical scrollbar:
When autosuggest suggestions are shown, they should appear on top of the content without affecting container's scrollbar.
I expect to get:
Note that the scrollbar is exactly the same as above.
But, I get the following:
Note that the scrollbar is affected, and suggestions are cut.
Why absolutely positioned suggestions affect container's scrollbar?
How would you fix that?
Notes:
- When scrolling the container, the input and suggestions should move together.
- You are allowed to modify the HTML, but the input and the suggestions list should stay inside
.autosuggest
(consider.autosuggest
as a third party component whose HTML cannot be changed, but you can change its CSS). - You can use flexbox, if it helps.
- I'm looking for CSS only solution. No Javascript please.
.container {
height: 100px;
width: 300px;
margin-top: 50px;
overflow-y: auto;
border: 1px solid black;
}
.autosuggest {
position: relative;
width: 250px;
}
.input {
font-size: 16px;
width: 230px;
padding: 5px 10px;
border: 0;
background-color: #FFEBBF;
}
.suggestions {
list-style-type: none;
margin: 0;
padding: 5px 10px;
width: 230px;
background-color: #85DDFF;
position: absolute;
}
.content {
width: 120px;
padding: 5px 10px;
}
<div class="container">
<div class="autosuggest">
<input class="input" type="text" value="input">
</div>
<div class="content">
content content content content content content content content content content
</div>
</div>
<div class="container">
<div class="autosuggest">
<input class="input" type="text" value="input">
<ul class="suggestions">
<li>suggestion 1</li>
<li>suggestion 2</li>
<li>suggestion 3</li>
<li>suggestion 4</li>
<li>suggestion 5</li>
<li>suggestion 6</li>
<li>suggestion 7</li>
<li>suggestion 8</li>
<li>suggestion 9</li>
</ul>
</div>
<div class="content">
content content content content content content content content content content
</div>
</div>