2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

paddingのある親要素と同じwidth100%の要素を入れる

2
Posted at

よくある作り

See the Pen paddingのある親要素と同じwidth100%の要素を入れる by nozomi (@key055) on CodePen.

# mainContent {
  width: 600px;
  min-height: 100vh;
  background-color: #fff;
  margin: 0 auto;
  padding: 40px;
  box-sizing: border-box;
}
.haba100 {
  background-color: #29292e;
  color: #fff;
  width: 600px;
  margin-left: -40px;
  box-sizing: border-box;
  padding: 10px 40px;
  font-size: 14px;
}

widthを親と同じにして、親のpaddingの分だけmarginでマイナスに良い。

簡単だった。
今まで頭硬かったなぁ。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?