LoginSignup
18
13

More than 3 years have passed since last update.

CSSで2つの要素を重ねる

Last updated at Posted at 2019-07-09

2つの要素を重ねる

position: absolute;で要素同士を重ねて表示できる。
topやleftを指定して、表示位置を調整できる。
その場合、サイト全体の左上部分が基準位置となる。

基準としたい親要素にposition: absolute;を指定すると、
基準位置を、親要素の左上に変更できる。

index.html
<div class="parent">
  <img class="child">
</div>
stylesheet.css
.parent {
  position: relative;
}
.child {
  position: absolute;
  top: 20px;
  left: 15px;
}

18
13
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
18
13