How do I center a div horizontally inside its parent div with CSS?
Text How do I center a div horizontally inside its parent div with CSS?
Text I am assuming the parent div has no width or a wide width, and the child div has a smaller width. The following will set the margin for the top and bottom to zero, and the sides to automatically fit. This centers the div.
div#child { margin: 0 auto; } Text Text You can use the "auto" value for the left and right margins to let the browser distribute the available space equally at both sides of the inner div:
Text Just out of interest, if you want to center two or more divs (so they're side by side in the center), then here's how to do it:
Div 1 Div 2