tags:

views:

16167

answers:

4

Say I have a page:

<body>
<div id="header">
    <h1>some title</h1>
    some header content
</div>
<div id="content">
    Some content
</div>
</body>

and the corresponding css

#header 
{
    height: 150px;
}

The header section is of fixed height but the content of that section may change. I would like to content of the header to be 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 section --------
|
|
|
| one line header text
-----------------------------

and if there were say 3:

----- header section --------
|
| first line of header text
| second line of header text
| third, last line of header text
-----------------------------

How can this be done in css?

+3  A: 

Use CSS positioning.

#header
{ 
    position: relative; 
}

#header-content 
{ 
    position: absolute; 
    bottom: 0; 
}

As cletus noted, you need identify the header-content to make this work.

<span id="header-content">some header content</span>
Patrick McElhaney
+1. Thanks for the answer, I accepted the one by cletus as it pointed me into the right drection first
kristof
+11  A: 

Relative+absolute positioning is your best bet:

<style type="text/css">
  #header { position: relative; }
  #header-content { position: absolute; bottom: 0; left: 0; }
</style>
<div id="header">
  <h1>Title</h1>
  <div id="header-content">Some content</div>
</div>

But you may run into issues with that. When I tried it I had problems with dropdown menus appearing below the content. It's just not pretty.

Honestly, for vertical centering issues and, well, any vertical alignment issues with the items aren't fixed height, it's easier just to use tables.

Example: Can you do this HTML layout without using tables?

cletus
I actually found that solution before asking here, but somehow forgot to add the position: relative; to the header div and the content kept landing at the bottom of the page. Thanks
kristof
A: 

Hi, I use this porperties and it work! ^_^

> display:table-cell;
> vertical-align:bottom;
`table-cell` [isn't supported in IE.](http://htmldog.com/reference/cssproperties/display/ "css display reference")
Ben
A: 

display:table-cell works only with firefox and not with IE :(

yassar