Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align a div to center

I want to float a div to center. Is it possible? text-align: center is not working in IE.

like image 532
ACP Avatar asked Nov 16 '09 07:11

ACP


People also ask

How do I align a div element to the center?

You can do this by setting the display property to "flex." Then define the align-items and justify-content property to “center.” This will tell the browser to center the flex item (the div within the div) vertically and horizontally.

How do I center a div without CSS?

use text-align:center for div -> this will align text inside div center. include width property in div (i.e. width:200px) and it will work fine.

How do I center a div 2021?

One way to center a Div in CSS is to set the position to absolute and set the left and right property values to 50% which will move the div to the center.


1 Answers

There is no float to center per se. If you want to center a block element inside another do this:

<div id="outer">   <div id="inner">Stuff to center</div> </div> 

with:

#outer { width: 600px; } #inner { width: 250px; margin: 0 auto; } 

Now that won't make the text wrap around it (like it would with a float left or right) but like I said: there is no float center.

like image 50
cletus Avatar answered Oct 15 '22 13:10

cletus