Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Text Align Bottom of Container

Tags:

html

css

I have a header which has a large image floated on one side, and a small paragraph of text on the other side. I want the paragraph to start at the bottom of the header div. If there were 5 lines in the paragraph, I want the last line to be at the bottom of the header. I'm having trouble getting the paragraph to align itself down there.

I have something like this:

<div id='header'>       <img id='logo' />       <p id='quote'></p>  </div> 

And the CSS is:

div#header {     height: 200px; }  div#header img#logo {     float: left; }  p#quote {     float: left; } 
like image 722
djt Avatar asked Dec 06 '11 17:12

djt


People also ask

How do I align text at the bottom of the container?

display:flex on the container. flex-direction: column will distribute children from top to bottom. margin-top: auto to the element that you want to stick at the bottom, flex will apply all the free space above.

How do I align text to the bottom of a box in CSS?

Use the text-align property to align the inner content of the block element. Use the bottom and left properties. The bottom property specifies the bottom position of an element along with the position property.

How do I align text in a container in CSS?

To just center the text inside an element, use text-align: center; This text is centered.

How do I align something to the bottom of a div?

Set the position of div at the bottom of its container can be done using bottom, and position property. Set position value to absolute and bottom value to zero to placed a div at the bottom of container.


2 Answers

http://jsfiddle.net/danheberden/ymwPe/

<div id="container">     <div id="gonnaBeOnTheBottom">         <p>Hi there!</p>         <p>I'm on the bottom!</p>     </div> </div> 

css:

#container {     background: #EEE;     height:400px;     width:400px;     position:relative; } #gonnaBeOnTheBottom {     position:absolute;     bottom:0; } 

by setting position:relative on the parent container, you can absolute position elements inside of it :)

like image 90
Dan Heberden Avatar answered Sep 24 '22 22:09

Dan Heberden


A more modern approach would be the usage of flexbox, that vastly eases the responsive work afterwards:

  • display:flex on the container
  • flex-direction: column will distribute children from top to bottom
  • margin-top: auto to the element that you want to stick at the bottom, flex will apply all the free space above

#container {   background: #eaeaea;   height:180px;   display: flex;   flex-direction: column; }  #bottom {   border: 1px solid blue;   margin-top: auto; }
<div id="container">     Whatever content     <div id="bottom">Will stick to bottom</div> </div>
like image 32
Creaforge Avatar answered Sep 21 '22 22:09

Creaforge