I have a searchbar written in react like this:
import './search.css'
const SearchBar = ({searchQuery, setSearchQuery}) => (
<div className="search">
<input
value = {searchQuery}
onInput = {e => setSearchQuery(e.target.value)}
type = "text"
placeholder = "Search driver apps..."
/>
<div className = "inSearch"></div>
</div>
);
and my css for it looks like this:
@import url('https://fonts.googleapis.com/css?family=Inconsolata:700');
.search{
position: relative;
margin-top: 50px;
margin-left: 30px;
width: 300px;
height: 100px;
}
.search .inSearch
{
/*width: 140px;
opacity: 1;
margin-left: 50px;
margin-top: 100px;
outline: auto;*/
position: absolute;
margin-top: 30px;
margin-left: 0px;
width: 70px;
height: 70px;
background: #faa81a;
border-radius: 50%;
transition: all 1s ease-out;
z-index: 4;
box-shadow: 0 0 25px 0 rgba(0, 0, 0, 0.4);
opacity: 1;
}
.search .inSearch:hover{
cursor: pointer;
}
.search .inSearch::before{
content: "";
position: absolute;
margin: auto;
top: 22px;
right: 0;
bottom: 0;
left: 22px;
width: 12px;
height: 2px;
background: white;
transform: rotate(45deg);
transition: all 0.5s ease-out;
}
.search .inSearch::after{
content: "";
position: absolute;
margin: auto;
top: -5px;
right: 0;
bottom: 0;
left: -5px;
width: 25px;
height: 25px;
border-radius: 50%;
border: 2px solid white;
transition: all .5s;
}
.search input {
font-family: 'Inconsolata', monospace;
position: absolute;
margin-top: 30px;
margin-left: 0px;
width: 60px;
height: 60px;
outline: none;
border: none;
background: #faa81a;
color: white;
text-shadow: 0 0 10px #faa81a;
padding: 0 80px 0 20px;
border-radius: 30px;
box-shadow: 0 0 25px 0 #faa81a, 0 20px 25px 0 rgba(0, 0, 0, 0.2);
transition: all 1s ease-out;
opacity: 0;
z-index: 5;
font-weight: bolder;
letter-spacing: 0.1em;
}
.search input:hover{
cursor: pointer;
}
.search input:focus{
height: 50px;
width: 200px;
opacity: 1;
cursor: text;
}
.search input:focus ~ .inSearch {
right: -20px;
background: #151515;
z-index: 6;
}
.search input:focus ~ .inSearch::before{
top: 0;
left: 0;
width: 25px;
}
.search input:focus ~ .inSearch::after{
top: 0;
left: 0;
width: 25px;
height: 2px;
border: none;
background: white;
border-radius: 0%;
transform: rotate(-45deg);
}
.search input::placeholder {
color: white;
opacity: 0.5;
font-weight: bolder;
}
I’m happy with 99% of the transition, but I can’t figure out why the inSearch div moves to the right so quickly and the searchbar is left to catch up. I want them both to move outward at the same time. I have tried easing the transitions, I have tried linear, prolonging the time, and delaying but it seems no matter what I change it just jumps to the right.
>Solution :
To transition the right property in your .search input:focus ~ .inSearch rule needs to know where to start from. So you need to add a right property to your .insearch element in the non-transitioned state. Add right to .search .inSearch and this fixes this. Code below:
@import url("https://fonts.googleapis.com/css?family=Inconsolata:700");
.search {
position: relative;
margin-top: 50px;
margin-left: 30px;
width: 300px;
height: 100px;
}
.search .inSearch {
/*width: 140px;
opacity: 1;
margin-left: 50px;
margin-top: 100px;
outline: auto;*/
right: 80%; /* added this */
position: absolute;
margin-top: 30px;
margin-left: 0px;
width: 70px;
height: 70px;
background: #faa81a;
border-radius: 50%;
transition: all 1s ease-out;
z-index: 4;
box-shadow: 0 0 25px 0 rgba(0, 0, 0, 0.4);
opacity: 1;
}
.search .inSearch:hover {
cursor: pointer;
}
.search .inSearch::before {
content: "";
position: absolute;
margin: auto;
top: 22px;
right: 0;
bottom: 0;
left: 22px;
width: 12px;
height: 2px;
background: white;
transform: rotate(45deg);
transition: all 0.5s ease-out;
}
.search .inSearch::after {
content: "";
position: absolute;
margin: auto;
top: -5px;
right: 0;
bottom: 0;
left: -5px;
width: 25px;
height: 25px;
border-radius: 50%;
border: 2px solid white;
transition: all 0.5s;
}
.search input {
font-family: "Inconsolata", monospace;
position: absolute;
margin-top: 30px;
margin-left: 0px;
width: 60px;
height: 60px;
outline: none;
border: none;
background: #faa81a;
color: white;
text-shadow: 0 0 10px #faa81a;
padding: 0 80px 0 20px;
border-radius: 30px;
box-shadow: 0 0 25px 0 #faa81a, 0 20px 25px 0 rgba(0, 0, 0, 0.2);
transition: all 1s ease-out;
opacity: 0;
z-index: 5;
font-weight: bolder;
letter-spacing: 0.1em;
}
.search input:hover {
cursor: pointer;
}
.search input:focus {
height: 50px;
width: 200px;
opacity: 1;
cursor: text;
}
.search input:focus ~ .inSearch {
right: -20px;
background: #151515;
z-index: 6;
}
.search input:focus ~ .inSearch::before {
top: 0;
left: 0;
width: 25px;
}
.search input:focus ~ .inSearch::after {
top: 0;
left: 0;
width: 25px;
height: 2px;
border: none;
background: white;
border-radius: 0%;
transform: rotate(-45deg);
}
.search input::placeholder {
color: white;
opacity: 0.5;
font-weight: bolder;
}
<div class="search">
<input value="searchQueryd" type="text" placeholder="Search driver apps..." >
<div class="inSearch"></div>
</div>