How can I center a box of unknown width in CSS?

后端 未结 7 763
被撕碎了的回忆
被撕碎了的回忆 2020-12-13 19:39

I have this html:

This is the caption &l
7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-13 19:56

    something along this should work

    HTML:

    
        

    foo

    and CSS:

    msgbox {
        width: 100%;
        display: block;
        text-align: center;
    }
    p {
        display: inline-block;
    }
    

    ... only sad thing is, the msgbox element, when using position absolute, blocks clicking through it (but that is only a related problem, and might not be one for you)

提交回复
热议问题