I struggle with CSS and often get stuck, even on simple layout questions. I'm currently reading a book but still can't figure out how to design a website with a header at the top, followed by a menu bar and content. However, I want the header to have text on the left and a logo on the right.
My approach so far:
<div id="headline">
<div id="headertext">Some title<br/>some more title text</div>
<div id="logo"><a href="http://www.example.com/~somelink"><img src="somelogo.png" /></a></div>
</div>
CSS code:
#headline { overflow: hidden;
height: 224px;
text-align: left;
padding: 0px 80px 0px 80px;
}
#headertext { font-family: "Trebuchet MS", Helvetica, sans-serif;
font-size: 20pt;
color: #000000;
float: left;
font-weight: bold;
}
#logo {
float: right;
}
I've successfully floated the text and logo to the left and right sides, respectively. Now, I want to vertically align both elements in the center of the parent <div>
with a specific height.
Desired outcome (blue rectangle represents the logo):
I've tried using vertical-align: middle
, but it hasn't worked. I also experimented with display:table-cell
and display:inline
, but they didn't yield the desired result. Should I add another wrapping <div>
inside the headline element?
Edit: thanks for the fiddle suggestion; here's my attempt: http://jsfiddle.net/f5vpakdv/
Appreciate your assistance!