Reputation: 93
I have made this search bar... And i want to use this page on many pages using iframe tag. But when i use it and when results are shown, it shifts other elements, or a scroll bar is visible ... I want the result to overlaped on the other contents of the site... So that it is visible normally... here is my code---
function filterFunction() {
let isInputAvail = false;
var input, filter, ul, li, a, i;
input = document.getElementById("myInput");
filter = input.value.toLowerCase();
if (filter.length > 0) {
document.getElementById("myDropdown").classList.add("show");
} else {
document.getElementById("myDropdown").classList.remove("show");
}
div = document.getElementById("myDropdown");
a = div.getElementsByTagName("a");
for (i = 0; i < a.length; i++) {
txtValue = a[i].innerText;
if (txtValue.toLowerCase().indexOf(filter) > -1) {
isInputAvail = true;
a[i].style.display = "block";
} else {
a[i].style.display = "none";
}
}
if (!isInputAvail) {
document.getElementById("noMatches").classList.add('show');
} else {
document.getElementById("noMatches").classList.remove('show');
}
}
.div {
display: none;
}
.dropbtn {
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
border-radius: 25px;
}
#myInput {
box-sizing: border-box;
background-position: 14px 12px;
background-repeat: no-repeat;
font-size: 16px;
padding: 14px 20px 12px 45px;
border: 5px solid #ddd;
border-radius: 25px;
}
#myInput:focus {
outline: 4px solid #f2f2f2;
border-color: #171313;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
max-height: 215px;
display: none;
position: absolute;
background-color: #f6f6f6;
min-width: 230px;
overflow-y: scroll;
border: none;
z-index: 1;
border-radius: 25px;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown a:hover {
background-color: #ddd;
}
.show {
display: block;
}
<div class="dropdown">
<input type="text" class="dropbtn" placeholder="Search Here..." id="myInput" onInput="filterFunction()">
<div id="myDropdown" class="dropdown-content">
<a href="#">Result 1</a>
<a href="#">Result 2</a>
<a href="#">Result 3</a>
<a href="#">Result 4</a>
<a href="#">Result 5</a>
<a href="#">Result 6</a>
<a href="#">Result 7</a>
<a href="#">Result 8</a>
<a href="#">Result 9</a>
<a href="#">Result 10</a>
<a href="#">Result 11</a>
<a href="#">Result 12</a>
<a href="#">Result 13</a>
<a href="#">Result 14</a>
<a href="#">Result 15</a>
</div>
<div id="noMatches" class="dropdown-content">
<a href="#tools">No Matches</a>
</div>
</div>
Upvotes: 0
Views: 202
Reputation: 93
I still don't get was this what you meant.
<style>
.dropbtn{
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
border-radius: 25px;
}
#myInput{
box-sizing: border-box;
background-position: 14px 12px;
background-repeat: no-repeat;
font-size: 16px;
padding: 14px 20px 12px 45px;
border: 5px solid #ddd;
border-radius: 25px;
}
#myInput:focus{
outline: 4px solid #f2f2f2;
border-color: #171313;
}
.dropdown{
position: relative;
display: inline-block;
flex-direction: column;
justify-content: flex-start;
}
.dropdown-content{
max-height: 215px;
display: none;
top: 60px;
left: 0;
position: absolute;
background-color: #f6f6f6;
min-width: 230px;
max-width: 70px;
overflow-y: scroll;
border: none;
z-index: 1;
border-radius: 25px;
}
.dropdown-content a{
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown a:hover{background-color: #ddd;}
.show{display: block;}
body{margin: 0;}
.header{
height: 90px;width: 100vw;
display: flex;position: relative;
align-items: center;
justify-content: space-around;
z-index: 10;
}
.dropdown-content::-webkit-scrollbar{
background: transparent;
width: 0;
display: none;
}
.banner{
background-color: #AAA;color: white;
height: 150px;width: 100vw;
top: 90px;left: 0;
display: block;position: absolute;
z-index: 1;
}
</style>
<div class="header">
<div class="dropdown">
<input type="text" class="dropbtn"placeholder="Search Here..." id="myInput" onInput="filterFunction()"/>
<div id="myDropdown" class="dropdown-content">
<a href="#">Result 1 a very long long line one result</a>
<a href="#">Result 2</a>
<a href="#">Result 3</a>
<a href="#">Result 4</a>
<a href="#">Result 5</a>
<a href="#">Result 6</a>
<a href="#">Result 7</a>
<a href="#">Result 8</a>
<a href="#">Result 9</a>
<a href="#">Result 10</a>
<a href="#">Result 11</a>
<a href="#">Result 12</a>
<a href="#">Result 13</a>
<a href="#">Result 14</a>
<a href="#">Result 15</a>
</div>
<div id="noMatches" class="dropdown-content">
<a href="#tools">No Matches</a>
</div>
</div>
<div>Other</div>
</div>
<div class="banner">Banner Content<div>
Upvotes: 1
Reputation: 93
Don't get it but is it something like top: 60px;left: 0; in .dropdown-content?
Upvotes: 0