*{
margin: 0px;
padding: 0px;
}
.nav{
background-color:bisque;
width: 100%;
height: 60px;
display: flex;
align-items: center;
}
.b{
height: 60px;
width: 10%;
background-color: antiquewhite;
margin: 2px;
justify-content: center;
font-family: 'Anton', sans-serif;
border-radius: 20px;
align-items: center;
display: flex;
}
img{
width: 80px;
height: 60px;
}
#srch{
width: 10%;
height:60px;
display: inline-block;
float: right;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lost and Found</title>
<link rel="stylesheet" href="style.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Anton&display=swap" rel="stylesheet">
</head>
<body>
<div >
<img src="img.png" alt="logo" srcset="">
<div ><span>Electronincs</span></div>
<div ><span>Plastics</span></div>
<div ><span>Wearables</span></div>
<div ><span>Others</span></div>
<input id="srch" type="search" value="Search">
</div>
</body>
</html>
The first code is Style.css while the 2nd code for Html file. Why is the search box not sticking to the right ? What mistake have i made ? I am not able to understand.The code is self explantory. The searchbox has the id #srch. I am designing the nav bar and am a beginner.
CodePudding user response:
Instead of going with this float approach you could do something like,
<div >
<div >
<img src="img.png" alt="logo" srcset="">
<div ><span>Electronincs</span></div>
<div ><span>Plastics</span></div>
<div ><span>Wearables</span></div>
<div ><span>Others</span></div>
</div>
<input id="srch" type="search" value="Search">
</div>
.nav{
background-color:bisque;
width: 100%;
height: 60px;
display: flex;
align-items: center;
justify-content: space-between;
}
justify-content: space-between takes care of positioning the search box to the right and other items to the left.
Also note that, I added an extra div class "nav-items". It helps to separate other items with search box
CodePudding user response:
Try to avoid float: right;
and use instead of it a margin-left: auto;
on the input.
You can put it into div for the better layout.
CodePudding user response:
You can use right: 0;
to move your search bar to the right.
#srch {
width: 10%;
height:60px;
/* these 2 lines should do the trick! */
right: 0;
position: absolute;
}