【问题标题】:Div Ignore max-width on bodyDiv 忽略身体上的最大宽度
【发布时间】:2017-09-17 00:23:34
【问题描述】:

我已经在我的 body 上设置了一个最大宽度,但我希望一个 div 没有这个最大宽度但有一个全宽。

HTML

<body>
<header> stuff here </header>
<main> 
more stuff

<div> The div I want to have a full-width </div>
</main>
</body>

CSS

    body {
            max-width: 1200px;
            margin-right: auto;
            margin-left: auto;
          }

div { ?}

【问题讨论】:

  • 你的问题很不清楚。请注意提供一些有关您的实际问题的信息。默认情况下,Divs 通常具有 100% 的宽度,因此在这种情况下,全宽将是为 body 定义的 1200px。
  • 抱歉,我希望 div 有全宽。所以如果屏幕是1600px,body就是1200px。所以我希望 div 然后有 1600px 宽度

标签: html css width


【解决方案1】:

如果你想让 div 全宽,你必须把它放在 body 外面。

   <body>
   <header> stuff here </header>
   <main> 
    more stuff


   </main>
   </body>
   <div> The div I want to have a full-width </div>

和css:

 div{width: 100%;}

【讨论】:

    【解决方案2】:

    您需要将位置设置为absolute 以使DIV 脱离身体。然后将宽度设置为 100% 以匹配屏幕尺寸。

    例如,请查看fiddle

    【讨论】:

      猜你喜欢
      • 2016-10-11
      • 2018-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-24
      • 1970-01-01
      • 2015-06-08
      • 1970-01-01
      相关资源
      最近更新 更多