Trying to make a generic search bar in React, having trouble preventing the search button from moving when minimizing the window. The arrow will always move out of position when I minimize the window even if just a bit, wondering what I am missing in my code. I want the search arrow button to maintain its place even when minimizing the window but it keeps moving.
Searchbar.js
import React from "react";
import './SearchBar.css';
import arrow from './arrow.png';
const SearchBar = ({placeholder,data}) => {
return (
<div className="search">
<div className="searchInputs">
<input type="text" placeholder={placeholder}/>
<button className='button' style={{position: 'relative',
right: 420, top: 15}}>
<img className='arrow' src={arrow} alt="logo"
style={{position: 'relative', right: 15, bottom: 11}}
></img>
</button>
<div className="searchIcon"></div>
</div>
<div className="dataResult"></div>
</div>
);
}
export default SearchBar;
Searchbar.css
.searchInputs {
margin-top: 55px;
display: flex;
position: relative;
}
.search input {
background-color: white;
border: 0;
border-radius: 40px;
font-size: 16px;
height: 72px;
width: 676px;
margin: auto;
font-family: Proxima Nova,Arial,sans-serif;
font-weight: 700;
line-height: 1.33;
color: #414141;
}
input:focus {
outline: none;
}
.searchIcon svg {
font-size: 16px;
}
.button {
display: flex;
flex-direction: row;
align-items: left;
height: 10px;
width: 10px;
border-radius: 50%;
border: none;
padding: 20px;
background-color: #428a13;
transition: background-color .2s;
}
.arrow {
height: 24px;
width: 31px;
}
.button:hover {
color: rgba(255, 255, 255, 1);
box-shadow: 0 0px 22px orange;
}
That's because you put position:relative in button element. When you minimize Browser, the button moves to the coordinates you put from one of its element having position: relative. (if you didn't put position :relative to its parents, the button moves from the body element.).
This is why the trouble happened and if you wanna control this, you should remove the position value as code below and position the button with display flex options.
<button className='button' >