Center Div inside another (100% width) div

后端 未结 6 1146
闹比i
闹比i 2020-12-23 09:42

Quite a \"simple\" problem here and not sure why it\'s being so complicated.

  1. Have a 100% (width) sized div.
  2. Have another div positioned in the middle
6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-23 10:12

    for detail info, let's say the code below will make a div aligned center:

    margin-left: auto;
    margin-right: auto;
    

    or simply use:

    margin: 0 auto;
    

    but bear in mind, the above CSS code only works when you specify a fixed width (not 100%) on your html element. so the complete solution for your issue would be:

    .your-inner-div {
          margin: 0 auto;
          width: 900px;
    }
    

提交回复
热议问题