Reputation: 15
I am trying to align the search bar in a navigation bar, but all my efforts are going in vain.
I have not included the whole of my navbar code here, only the search bar which is inside my navbar in a div container.
.search {
width: 100%;
position: relative;
display: flex;
}
.searchTerm {
width: 100%;
border: 3px solid #00B4CC;
border-right: none;
padding: 5px;
height: 20px;
border-radius: 5px 0 0 5px;
outline: none;
color: #9DBFAF;
}
.searchTerm:focus{
color: #00B4CC;
}
.searchButton {
width: 20px;
height: 20px;
border: 1px solid #00B4CC;
background: #00B4CC;
text-align: center;
color: #fff;
border-radius: 0 5px 5px 0;
cursor: pointer;
font-size: 20px;
}
.wrap{
width: 30%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.topnav-right {
float: right;
}
<div class="topnav-right">
<div class="wrap">
<div class="search">
<input type="text" class="searchTerm" placeholder="What are you looking for?">
<button type="submit" class="searchButton">
<i class="fa fa-search"></i>
</button>
</div>
</div>
</div>
Am I doing it the right way or not ?
Upvotes: 0
Views: 605
Reputation: 141
I don't know why you used ".topnav-right" class and used it to float right. It works well without that too.
.wrap{
width: 30%;
position: absolute;
top: 50%;
right: 0;
}
You might need to adjust width and height of the .searchButton class.
Upvotes: 0
Reputation: 14149
Change CSS
.wrap{
width: 30%;
position: absolute;
top: 50%;
right: 0%;
transform: translate(0%, -50%);
}
https://jsfiddle.net/lalji1051/L7dnvqbm/1/
Upvotes: 3