CSS: Center block, but align contents to the left

后端 未结 8 788
别那么骄傲
别那么骄傲 2020-11-30 19:27

I want a whole block to be centered in its parent, but I want the contents of the block to be left aligned.

Examples serve best

On this page :

http

8条回答
  •  暖寄归人
    2020-11-30 19:55

    I've found the easiest way to centre and left-align text inside a container is the following:

    HTML:

    Some interesting text.

    CSS:

    P {
      width: 50%; //or whatever looks best
      margin: auto; //top and bottom margin can be added for aesthetic effect
    }
    

    Hope this is what you were looking for as it took me quite a bit of searching just to figure out this pretty basic solution.

提交回复
热议问题