css - why does't my title center when I use margin: 0 auto? -
- an inline block lays out content block, laid out inline in parent , can have text before , after on same line, auto-margins don't kind of centering, not on span. need
display: blockautomargins center things
2.a. if had display: block still wouldn't work, default fill whole width. auto margins center things equaly distributing leftover space both side, need have leftover space begin with. try using width or max-width properties. if not have fixed width, , want depends on size of content, try width: fit-content / width: -moz-fit-content / width: -webkit-fit-content (https://developer.mozilla.org/en-us/docs/web/css/width#fit-content).
2.b. alternatively, depending on you're after, instead of centering div in parent, may want center text inside div, text-align: center. you'll still need make div block rather inline block, otherwise width of text contains, , there won't centering possible.

Comments
Post a Comment