LoginSignup
1
1

More than 3 years have passed since last update.

height プロパティが有効になる条件

Posted at

height プロパティが有効になる条件

基本的にheightプロパティが有効になるのは、親要素のスタイルにheightが指定されているときである。

<div class="parent">
  <div class="child">aaa</div>
  <div class="child">bbb</div>
  <div class="child">ccc</div>
</div>
.parent {
  height: 600px;
}
.child {
  height: 50%;
}

例外

要素が絶対位置指定されている場合(position: absolute;かposition: fixed;が指定されている場合)は親要素にheightが指定されていなくてもheightプロパティを指定することができる。

.parent {
  position: relative;
}
.child {
  position: absolute;
  height: 200px;
}
1
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
1
1