Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I position a div at the bottom center of the screen

Tags:

html

css

I have this css:

#manipulate {   position:absolute;   width:300px;   height:300px;   background:#063;   bottom:0px;   right:25%; } 

I have this html:

<div id="manipulate" align="center">  </div> 

How do we position that div at the bottom center of the screen?!?

like image 206
BlackFire27 Avatar asked Feb 21 '12 18:02

BlackFire27


People also ask

How do I move a div to the bottom of the screen?

Try position:fixed; bottom:0; . This will make your div to stay fixed at the bottom.

How do I position something at the bottom of a page in CSS?

If position: absolute; or position: fixed; - the bottom property sets the bottom edge of an element to a unit above/below the bottom edge of its nearest positioned ancestor. If position: relative; - the bottom property makes the element's bottom edge to move above/below its normal position.

How do I align the content at the bottom of a div?

To align the div content to the bottom, use position: relative to the container class and position: absolute to the div element.

How do I center a div according to my screen size?

Easiest way to center something regardless of page width is margin: auto; in your CSS, with height and width defined. Show activity on this post. This will center your DIV with class center-div horizontally AND vertically. The margin-left must be negative half of what your width is.


2 Answers

align="center" has no effect.

Since you have position:absolute, I would recommend positioning it 50% from the left and then subtracting half of its width from its left margin.

#manipulate {     position:absolute;     width:300px;     height:300px;     background:#063;     bottom:0px;     right:25%;     left:50%;     margin-left:-150px; } 
like image 26
Purag Avatar answered Nov 04 '22 05:11

Purag


If you aren't comfortable with using negative margins, check this out.

HTML -

<div>  Your Text </div> 

CSS -

div {   position: fixed;   left: 50%;   bottom: 20px;   transform: translate(-50%, -50%);   margin: 0 auto; } 

Especially useful when you don't know the width of the div.

like image 155
mutp Avatar answered Nov 04 '22 05:11

mutp