.searchbar is my background for the searchbar, but i don't know how to center my searchbar to his background vertically.
Here is my CSS
.searchbar {
display: block;
width: 100%;
height: 100px;
overflow: hidden;
background-color: lightgray;
text-align: center;
position: relative;
}
.searchbar input[type="text"] {
color: black;
text-align: left;
text-decoration: none;
width: 50%;
height: 40px;
font-size: 20px;
align-self: center;
position: relative;
vertical-align: middle;
}
And here is the html
<div class="searchbar">
<input type="text" placeholder="Search..." />
</div>
CodePudding user response:
This is actually works
.searchbar {
display: block;
width: 100%;
height: 80px;
overflow: hidden;
background-color: lightgray;
text-align: center;
position: relative;
display: flex;
align-items: center;
}
.searchbar input[type="text"] {
color: black;
text-align: left;
text-decoration: none;
width: 50%;
height: 40px;
font-size: 20px;
align-self: center;
position: relative;
vertical-align: middle;
border-radius: 50px;
border: none;
margin: auto;
}
CodePudding user response:
.searchbar {
width: 100%;
height: 100px;
overflow: hidden;
background-color: lightgray;
text-align: center;
}
.searchbar input[type="text"] {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
display: block;
color: black;
text-align: left;
text-decoration: none;
width: 50%;
height: 40px;
font-size: 20px;
align-self: center;
position: relative;
vertical-align: middle;
}
<div class="searchbar">
<input type="text" placeholder="Search..." />
</div>