1 2 3 |
.box{ position: ○○○○; } |
static | 通常の位置に配置(デフォルト) |
---|---|
relative | 通常の位置を基準とした相対位置 |
absolute | static以外を指定された親要素を基準とした絶対位置 |
fixed | ウィンドウを基準とした絶対位置 |
top: ○○px; | 基準点の上から、○○px下に移動(%でも可,マイナスの値も可) |
---|---|
right: ○○px; | 基準点の右から、○○px左に移動 |
bottom: ○○px; | 基準点の下から、○○px上に移動 |
left: ○○px; | 基準点の左から、○○px右に移動 |
z-index: ○; | 要素の重なり順(数値が大きいほど上,マイナスの値も可) |
1 2 3 |
<div class="wrap_sample"> <div class="relative_sample"></div> </div> |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
.wrap_sample{ width: 300px; height: 200px; margin: 0 auto; background: #333; } .relative_sample{ position: relative; width: 50px; height: 50px; background: #f00; opacity: 0.5; } |
1 2 3 4 5 6 7 8 9 |
.relative_sample{ position: relative; top: 50px; left: 50px; width: 50px; height: 50px; background: #f00; opacity: 0.5; } |
1 2 3 4 5 6 7 8 9 |
.relative_sample{ position: relative; bottom: 25px; right: 25px; width: 50px; height: 50px; background: #f00; opacity: 0.5; } |
1 2 3 |
<div class="wrap_sample"> <div class="absolute_sample"></div> </div> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
.wrap_sample{ position: relative; width: 300px; height: 200px; margin: 0 auto; background: #333; } .absolute_sample{ position: absolute; top: 50px; left: 50px; width: 50px; height: 50px; background: #f00; opacity: 0.5; } |
1 2 3 4 5 6 7 8 9 |
.absolute_sample{ position: absolute; bottom: 25px; right: 25px; width: 50px; height: 50px; background: #f00; opacity: 0.5; } |
1 2 3 4 5 6 7 8 9 |
.absolute_sample{ position: absolute; bottom: 75px; right: -25px; width: 50px; height: 50px; background: #f00; opacity: 0.5; } |
1 2 3 4 5 |
<div class="wrap_sample"> <div class="z_sample_1"></div> <div class="z_sample_2"></div> <div class="z_sample_3"></div> </div> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
.wrap_sample{ position: relative; width: 300px; height: 200px; margin: 0 auto; background: #333; } .z_sample_1{ position: absolute; top: 50px; left: 25px; width: 100px; height: 100px; background: #f00; /* 赤 */ opacity: 0.65; } .z_sample_2{ position: absolute; top: 50px; left: 100px; width: 100px; height: 100px; background: #0f0; /* 緑 */ opacity: 0.65; } .z_sample_3{ position: absolute; top: 50px; left: 175px; width: 100px; height: 100px; background: #00f; /* 青 */ opacity: 0.65; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
.z_sample_1{ position: absolute; top: 50px; left: 25px; width: 100px; height: 100px; background: #f00; /* 赤 */ opacity: 0.65; z-index: 3; } .z_sample_2{ position: absolute; top: 50px; left: 100px; width: 100px; height: 100px; background: #0f0; /* 緑 */ opacity: 0.65; z-index: 2; } .z_sample_3{ position: absolute; top: 50px; left: 175px; width: 100px; height: 100px; background: #00f; /* 青 */ opacity: 0.65; z-index: 1; } |
1 2 3 4 5 6 7 8 9 |
<div class="wrap_sample"> <div class="relative_sample"></div> ああああ...ああああ </div> <br /> <div class="wrap_sample"> <div class="absolute_sample"></div> ああああ...ああああ </div> |