CSS body element width not working

前端 未结 6 792
挽巷
挽巷 2021-01-28 14:32

HTML:


    

Some content

CSS:

body {
    margin: 0 auto;
    width: 470px;
    back         


        
6条回答
  •  走了就别回头了
    2021-01-28 15:13

    The body actually is taking that width, and it is centering. It's just a CSS quirk that makes the background occupy the whole page rather than the space actually occupied by the body element.

    A way to fix this is to include a background property on the html tag.

    Here's an example.

    However, as mentioned by others, this probably isn't something you want to do. It's better to add a div within the body and style that.

提交回复
热议问题