Say I have the following CSS and HTML code:
#header {
height: 150px;
}
<div id="header">
<h1>Header title</h1>
Header content (one or multiple lines)
</div>
The header section is fixed height, but the header content may change. I would like to content of the header to be vertically aligned to the bottom of the header section, so the last line of text "sticks" to the bottom of the header section.
So if there is only one line of text it would be like:
-----------------------------
| Header title
|
|
|
| header content (resulting in one line)
-----------------------------
And if there were three lines:
-----------------------------
| Header title
|
| header content (which is so
| much stuff that it perfectly
| spans over three lines)
-----------------------------
How can this be done in CSS?
You don't need absolute+relative for this. It is very much possible using relative position for both container and data. This is how you do it.
Assume height of your data is going to be
x
. Your container is relative and footer is also relative. All you have to do is add to your dataYour data will always be at the bottom of your container. Works even if you have container with dynamic height.
HTML will be like this
CSS will be like this
Live example here
Hope this helps.
a very simple, one-line solution, is to add line-heigth to the div, having in mind that all the div's text will go bottom.
CSS:
HTML:
keep in mind that this is a practical and fast solution when you just want text inside div to go down, if you need to combine images and stuff, you will have to code a bit more complex and responsive CSS
if you could set the height of the wrapping div of the content (#header-content as shown in other's reply), instead of the entire #header, maybe you can also try this approach:
HTML
CSS
show on codepen
I know this is over 2 years old, but I have devised a way which is a lot simpler than whats been mentioned.
Set the height of the header div. Then inside that, style your H1 tag as follows:
I'm working on a site for a client, and the design requires the text to be at the bottom of a certain div. I've achieved the result using these two lines and it works fine. Also, if the text does expand, the padding will still remain the same.
2015 solution
http://codepen.io/anon/pen/qERMdx
your welcome
The site I just did for a client requested that the footer text was a high box, with the text at the bottom I achieved this with simple padding, should work for all browsers.