Simple center a object with css and no hacks

前端 未结 7 821
不思量自难忘°
不思量自难忘° 2021-02-01 05:13

I want to center an object using CSS and no hacks, is this possible and how?

I have tried this, but than my p tag is gone.

.centered {
  position: fixed;         


        
7条回答
  •  时光说笑
    2021-02-01 05:45

    HTML:

    Centered

    CSS:

    div {
        margin: 0 auto;
        width: 200px;
    }
    

    Live example: http://jsfiddle.net/v3WL5/

    Note that margin: 0 auto; will only have an effect if the div has a width.

提交回复
热议问题