centering root div through percentage width in all kind of resolutions

后端 未结 2 893
傲寒
傲寒 2021-01-17 01:54

i need to center the root div through percentage based width not pixel based

#container
{
  width:80%;
  margin:0px auto;
}

it will center

相关标签:
2条回答
  • 2021-01-17 02:08

    add padding-left and padding-right. also give width=100%

    0 讨论(0)
  • 2021-01-17 02:25

    Here you go.

    WORKING DEMO

    The HTML Code:

    <div id="container">&nbsp;</div>
    

    The CSS Code:

    #container
    {
      width:80%;
      margin:0px auto;
        background:green;
    }
    
    html{width:100%; min-width:100%;}
    

    Hope this helps.

    0 讨论(0)
提交回复
热议问题