9951 explained code solutions for 126 technologies


cssHow to center an element horizontally


div { width: 50%; margin: 0 auto; }ctrl + c
div

element to center horizontally

width: 50%

set width (any width less than 100%)

margin: 0 auto

will automatically make left and right margin the same (thus center the element)