I have a table <td>
which contains an <input>
control. Typing text in the input shows a <div>
with search results. Specifically, if you start typing owner's name, people whose name contains that text will list in the search results. Here it is in action:
The problem is that the <div>
with the search results is showing inside the table, but I want it to overflow.
Here is the related HTML code:
<table >
...
<tr>
...
<td>
<div >
<input type="text" placeholder="Type user name">
</div>
<div >
<div >
...
</div>
</div>
</td>
...
</tr>
</table>
And here is the CSS for the related classes:
.table {
display: block;
width: 100%;
height: 100%;
border-spacing: 0;
overflow-x: auto;
}
.table td {
padding: 8px 12px;
vertical-align: top;
user-select: none;
white-space: nowrap;
}
.people-picker {
min-width: 148px;
}
.people-picker input {
width: 100%;
background: url('../img/users-black.svg') no-repeat scroll right center;
padding-right: 32px;
}
.search-results-wrapper {
position: relative;
}
.search-results {
position: absolute;
top: 4px;
z-index: 2000;
overflow-y: auto;
}
How do I make the .search-results <div>
render under the .people-picker <div>
but outside of the table? Thanks, I appreciate your help!
CodePudding user response:
Here check out this answer. I did it using only css and html and but as mentioned in the question that you wanted to render div outside of table, this does work.
Hope this helps!
.table {
width: 100%;
height: 100%;
}
table,
tr,
td {
position: relative;
display: block;
}
.table td {
background: red;
padding: 8px 12px;
vertical-align: top;
user-select: none;
white-space: nowrap;
}
#searchUser {
min-width: 148px;
}
.search-results-wrapper {
position: absolute;
display: block;
bottom: -105px;
left: 0;
width: 100%;
height: 100px;
background: blue;
opacity: 0;
transitions: opacity 0.2s ease-in-out;
}
.search-results {
width: 100%;
min-height: inherit;
max-height: fit-content;
padding: 8px 12px;
top: 4px;
z-index: 2000;
overflow-y: auto;
}
input:not(:placeholder-shown) .search-results-wrapper {
opacity: 1;
}
<table >
<tr>
<td>
<input type="text" id="searchUser" placeholder="Type user name">
<div >
<div >
<p>Demo text</p>
</div>
</div>
</td>
</tr>
</table>
CodePudding user response:
You could create an overlay to show the results. From your example:
CSS
.search-results {
display: none;
position: absolute;
width: 200px;
height: 100px;
top: 4px;
z-index: 2000;
overflow-y: auto;
border: 1px solid blue;
background-color: rgba(0,0,0,0.7);
color: white;
}
HTML
<div >
<div id="overlay" >
and in JS show or hide the results:
let isHidden = true;
function showHide() {
if (isHidden) {
document.getElementById("overlay").style.display = "block";
} else {
document.getElementById("overlay").style.display = "none";
}
isHidden = !isHidden;
}
Check this StackBlitz example based on your code: https://web-platform-fifydh.stackblitz.io