How do I center an inline-block/floated header with no extra markup?

前端 未结 3 1777
南笙
南笙 2021-01-05 06:06

I have a variable width header that must have a background color that is as wide as the text (no wider). The only way I can think of doing this (with no ext

3条回答
  •  孤街浪徒
    2021-01-05 06:28

    replace the p tag with center as my markup is

    
    

    and it's CSS is

    body{
        width:100%;
    }
    #header{
        text-align:center;
    }
    #header center{
        display:inline-block;
        background:red;
    }
    

提交回复
热议问题