User Tools

Site Tools


css

Center a block element

text-align only centers the text inside the block. To center an entire block element, we must make it smaller than the parent (otherwise, what's the point?) then tell the browser to adjust the left and right margins accordingly.

div.center {
	width: 80%;
	margin-left: auto;
	margin-right: auto;
/* -or-
	margin: 0 auto;
*/
}
css.txt · Last modified: 2017/03/15 23:45 by shawn

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki