Is there a way to center align an input text box on a webpage using only inline CSS? I have tried various techniques, including the following code snippet, but nothing seems to work:
<input type="text" id="myInput" style= "margin: auto; width: 80%;background-repeat: no-repeat;" >
I feel like I may be missing something conceptually, but I can't figure out what it is. Any insights would be greatly appreciated.
If necessary, here is the full code for reference:
function myFunction() {
var input, filter, ul, li, a, i, txtValue;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
ul = document.getElementById("myUL");
li = ul.getElementsByTagName("li");
for (i = 0; i < li.length; i++) {
a = li[i].getElementsByTagName("a")[0];
txtValue = a.textContent || a.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
li[i].style.display = "block";
} else {
li[i].style.display = "none";
}
}
}
* {
box-sizing: border-box;
}
#myUL {
list-style-type: none;
padding: 0;
margin: 0;
}
#myUL li a {
border: 1px solid #ddd;
margin-top: -1px;
/* Prevent double borders */
background-color: #f6f6f6;
padding: 12px;
text-decoration: none;
font-size: 18px;
color: black;
display: block
}
#myUL li a:hover:not(.header) {
background-color: #eee;
}
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for a product.." title="Product Search" style="margin: auto; width: 80%;background-repeat: no-repeat;">
<ul id="myUL">
<li style="display: none"><a href="#">phones</a></li>
<li style="display: none"><a href="#">laptops</a></li>
<li style="display: none"><a href="#">desktops</a></li>
<li style="display: none"><a href="#">headphones</a></li>
<li style="display: none"><a href="#">speakers</a></li>
<li style="display: none"><a href="#">cameras</a></li>
<li style="display: none"><a href="#">fridges</a></li>
</ul>