css - why does't my title center when I use margin: 0 auto? -


i have set div inline-block , set margin (0 auto). why doesn't work? enter image description here

  1. 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: block automargins 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

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -