Why should I use a container div in HTML?

前端 未结 9 1673
陌清茗
陌清茗 2020-12-23 14:33

I have noticed a common technique is to place a generic container div in the root of the body tag:


  
    ...
  
  <         


        
9条回答
  •  庸人自扰
    2020-12-23 14:56

    The container div, and sometimes content div, are almost always used to allow for more sophisticated CSS styling. The body tag is special in some ways. Browsers don't treat it like a normal div; its position and dimensions are tied to the browser window.

    But a container div is just a div and you can style it with margins and borders. You can give it a fixed width, and you can center it with margin-left: auto; margin-right: auto.

    Plus, content, like a copyright notice for example, can go on the outside of the container div, but it can't go on the outside of the body, allowing for content on the outside of a border.

提交回复
热议问题