how to position a search bar in html/css

user3247608

This is my code so far:

html:

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="home_style.css">
</head>

<body>

<div class="header">
    <div class="search_bar">
        <input type="text" name="search" value="search">
</div>

</body>
</html>

css:

html,body{
height:100%;
min-height:100%; 
width:100%
min-width:100%;
}

.header{
margin-bottom:0;
height:10%; 
width:100%;
background-color:#343430;
}

.search_bar input[type="text"]{
position:relative;  
left:20%;
top:25%;
width:30%;

background-color:white; 
color:grey;
}

How do I make the search bar be positioned further down, i need the search bar to be positioned in the middle of the header not the top. Why is top:25% not working?

Cilan

Replace position:relative with position:absolute:

html, body {
    height:100%;
    min-height:100%;
    width:100% min-width:100%;
}
.header {
    margin-bottom:0;
    height:10%;
    width:100%;
    background-color:#343430;
}
.search_bar input[type="text"] {
    position:absolute;
    left:20%;
    top:25%;
    width:30%;
    background-color:white;
    color:grey;
}

If you look at the definition for relative positioning:

The element is positioned relative to its normal position,
so "left:20" adds 20 pixels to the element's LEFT position

your search bar was really positioning itself.

Demo

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Changing the position of a search bar when it is clicked

From Dev

UISearchController Search Bar Position Drops 64 points

From Dev

cant get the wordpress search bar on the right position

From Dev

Changing the position of a search bar when it is clicked

From Dev

Position search bar at the right side of div and centered

From Dev

how to change the position of app bar?

From Dev

How to add a search bar to the navigation bar

From Dev

How to move the search button inside the search bar?

From Java

how to display a search bar with SwiftUI

From Dev

HTML: How to create search bar?

From Dev

How to hide a temporary search bar?

From Dev

How to add a Search to an action bar?

From Dev

how to make a search bar reactjs

From Dev

How to add search into action bar

From Dev

how to create a live search bar?

From Dev

How to search a text document by position

From Dev

How to search a text document by position

From Dev

Background position SVG search icon in input bar (possible bug?)

From Dev

Is it possible to change the vertical position of cancel button in the search bar?

From Java

How to change scroll bar position with CSS?

From Dev

How to change Bar Charts Legend position in PrimeFaces?

From Dev

How to position horizontal scroll bar at center of DIV

From Dev

How to fix nav-bar position?

From Dev

How to adjust the vertical position of the button in the navigation bar?

From Dev

How to get position:fixed; behavior with scroll bar

From Dev

How to fix nav-bar position?

From Dev

How to change Bar Charts Legend position in PrimeFaces?

From Dev

How to change button position in navigation bar

From Dev

How to show viewpager fragment position on action bar?

Related Related

HotTag

Archive