質問編集履歴
1
ソースコードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,7 +1,45 @@
|
|
1
1
|
position: relative,absoluteによる位置制御について
|
2
2
|
2階層なら
|
3
|
-
親要素 : relative
|
3
|
+
親要素 : relative (box1)
|
4
|
-
子要素 : absolute
|
4
|
+
子要素 : absolute (box2)
|
5
5
|
で問題ありませんが子要素にさらに孫要素を追加した時に
|
6
6
|
子要素 : absoluteとなり
|
7
|
-
孫要素の扱いがわかりません。
|
7
|
+
孫要素(box3)の扱いがわかりません。
|
8
|
+
|
9
|
+
```html
|
10
|
+
<!DOCTYPE html>
|
11
|
+
<html lang="ja">
|
12
|
+
<head>
|
13
|
+
<meta charset="UTF-8" />
|
14
|
+
<link rel="stylesheet" href="style.css" />
|
15
|
+
<title>Document</title>
|
16
|
+
</head>
|
17
|
+
<body>
|
18
|
+
<div class="box box1">
|
19
|
+
<div class="box box2">
|
20
|
+
<div class="box box3"></div>
|
21
|
+
</div>
|
22
|
+
</div>
|
23
|
+
</div>
|
24
|
+
</body>
|
25
|
+
</html>
|
26
|
+
```
|
27
|
+
|
28
|
+
```CSS
|
29
|
+
.box {
|
30
|
+
width: 200px;
|
31
|
+
height: 200px;
|
32
|
+
}
|
33
|
+
|
34
|
+
.box1 {
|
35
|
+
position: relative;
|
36
|
+
background-color: royalblue;
|
37
|
+
}
|
38
|
+
|
39
|
+
.box2 {
|
40
|
+
position: absolute;
|
41
|
+
background-color: red;
|
42
|
+
top: 20px;
|
43
|
+
left: 20px;
|
44
|
+
}
|
45
|
+
```
|