我想按照材质设计制作一个应用栏。

css - 100%宽度 flex 盒内的额外余量-LMLPHP

我编写的代码尝试使用宽度为100%的flexbox绘制此代码。

.appbar {
  display: flex;
  flex-direction: row;
  align-items: center;

  width: 100%;
  height: 48px;

  box-sizing: border-box;
  box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.46);
}


但是我在应用栏中获得了额外的利润。为什么会这样呢?

css - 100%宽度 flex 盒内的额外余量-LMLPHP

最佳答案

添加margin: 0;
    padding: 0;body


 body{
  margin: 0;
padding: 0;
 }
 .appbar {
  display: flex;
  flex-direction: row;
  align-items: center;
  background-color: red;

  width: 100%;
  height: 48px;

  box-sizing: border-box;
  box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.46);
}

<div class="appbar"></div>

关于css - 100%宽度 flex 盒内的额外余量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51632861/

10-12 12:36
查看更多