In my header, I have a logo top left that shouldn't move, and a search input form that I want to center horizontally (even when the browser resizes) but am finding hard to do so (the "Go" button should be next to it as well.
I attempted to auto margin and all but could not get this to work. I have included the code and a jsfiddle.
Thank you!
html:
<header>
<h1 id="logo">Test Logo</h1>
<form method="get" id="search-form">
<input type="text" id="search" placeholder="Search Here" autocomplete="off" />
<ul id="suggestions"></ul>
<input type="submit" value="Go" />
</form>
</header>
css:
body {
font: 14px/1.5 "Open Sans", "PT Sans", "Source Sans Pro",
"Helvetica Neue", Helvetica, Arial, Sans-Serif;
color: #333;
height: 100%;
}
h1, h2, h3, h4, h5, h6 {
margin-bottom: 10px;
font-weight: bold;
margin-top: 0px;
}
header {
position: relative;
height: 50px;
background-color: black;
padding-top: 10px;
}
#logo {
margin-bottom: 10px;
font-weight: bold;
margin-top: 0px;
margin-left:20px;
text-align:left;
color:#ECF0F1;
display:inline
}
#search {
width: 350px;
padding: 4px 8px;
outline: none;
display:inline;
}
#search-form input[type='submit'] {
display:inline;
padding: 5px 8px;
border: 1px solid #aaa;
background-color: #eee;
background-image: -webkit-gradient(linear, left top, left bottom, from(#eee), to(#ddd));
background-image: -webkit-linear-gradient(top, #eee, #ddd);
background-image: -moz-linear-gradient(top, #eee, #ddd);
background-image: -o-linear-gradient(top, #eee, #ddd);
background-image: linear-gradient(to bottom, #eee, #ddd);
}
#search-form {
position: relative;
margin-bottom: 20px;
display:inline;
}
See the fiddle
Changed CSS
What I have done is, I've set the display of your
header
toinline-block
and usedtext-align:center
for theheader
. Then, to make thelogo
stick to the left always, I have usedfloat:left
. And, to make the searchform centered, I set itsdisplay
toinline-block
.