Absolute Positioning & Text Alignment

后端 未结 5 978
我在风中等你
我在风中等你 2021-01-30 20:19

I would like some text to be centered in the bottom of the screen.

I tried this, but it doesn\'t work. It looks like absolute positioning conflicts with the alignment.

5条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-30 20:53

    The div doesn't take up all the available horizontal space when absolutely positioned. Explicitly setting the width to 100% will solve the problem:

    HTML

    I want to be centered

    CSS

    #my-div {
       position: absolute;
       bottom: 15px;
       text-align: center;
       width: 100%;
    }
    

提交回复
热议问题