I am facing a challenge with the layout of my header bar containing a logo and search form, both floated to the left. I have been struggling to control the vertical spacing of the search form using CSS as a solution that works consistently across browsers eludes me. Adjusting padding or margin has not provided a satisfactory fix thus far. The same issue arises when there is a search button adjacent to the search field. Is there a cross-browser compatible solution for this, or should I consider incorporating JavaScript? Are there established standards for addressing such design concerns?
P.S. I have reset the CSS in my development code.
Below is a simplified snippet of my header code:
body {
font-family: Arial, sans-serif;
}
header {
overflow: hidden;
background-color: black;
}
a {
text-decoration: none;
color: white;
}
#site-title, #search {
float: left;
}
#site-title {
margin-right: 50px;
background-color: green;
font-size: 28px;
}
#search {
background-color: red;
margin-top: 5px
}
<body>
<header>
<div id="site-title"><a href="#">Site Title</a></div>
<div id="search">
<form>
<input type="search" placeholder="Search..." />
</form>
</div>
</header>
</body>
Link to code on JSFiddle: http://jsfiddle.net/mg535m80/2/
Edit: After some exploration, I discovered a workaround that, while not entirely cross-browser compatible, functions well in modern browsers. By adding display: flex;
and align-items: center
to the parent element, the issue was resolved effortlessly. Updated code example:
body {
font-family: Arial, sans-serif;
}
header {
overflow: hidden;
background-color: black;
display: flex;
align-items: center;
}
a {
text-decoration: none;
color: white;
}
#site-title, #search {
float: left;
}
#site-title {
margin-right: 50px;
background-color: green;
font-size: 28px;
}
#search {
background-color: red;
}
<body>
<header>
<div id="site-title"><a href="#">Site Title</a></div>
<div id="search">
<form>
<input type="search" placeholder="Search..." />
</form>
</div>
</header>
</body>
Updated JSFiddle: http://jsfiddle.net/mg535m80/9/