teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

コメントを受けて追記

2020/08/26 03:41

投稿

Lhankor_Mhy
Lhankor_Mhy

スコア37488

answer CHANGED
@@ -10,4 +10,129 @@
10
10
  transition: all 0.5s ease;
11
11
  z-index: 2;
12
12
  }
13
- ```
13
+ ```
14
+
15
+ # コメントを受けて追記
16
+
17
+ 以下のように変更してみてはいかがでしょうか。
18
+
19
+ [サンプル](https://jsfiddle.net/Lhankor_Mhy/an67y13e/)
20
+
21
+ ```scss
22
+
23
+ //ドロワーサイドメニュー
24
+ .side-menu {
25
+ position: fixed;
26
+ top: 0;
27
+ right: -300px;
28
+ width: 300px;
29
+ height: 100%;
30
+ padding-top: 150px;
31
+ text-align: left;
32
+ font-size: 13px;
33
+ background-color: rgba($font-color,0.95);
34
+ z-index: 2;
35
+ z-index: -1; // 追加
36
+
37
+ // ...
38
+
39
+ //ドロワー内コンテンツ
40
+ .wrapper {
41
+ position: relative;
42
+ width: 100%;
43
+ height: 100%;
44
+ -webkit-transition: all .5s ease;
45
+ transition: all .5s ease;
46
+ // z-index: 2; 削除
47
+ }
48
+
49
+ .contents {
50
+ width: 100%;
51
+ background: #fff;
52
+
53
+ }
54
+
55
+ // ...
56
+
57
+ // index.html トップページ
58
+ .top-wrapper {
59
+ background:linear-gradient(90deg,#fff 0%,#fff 24.5%,$bg-color 24.5%,$bg-color 100%);
60
+ color: #FFFFFF;
61
+ height: 668px;
62
+ position: relative;
63
+ // z-index: 0; 削除
64
+ margin-bottom: 78px;
65
+ @include mq('md') {
66
+ height: 1024px;
67
+ background:linear-gradient(90deg,#fff 0%,#fff 27%,$bg-color 27%,$bg-color 100%);
68
+ }
69
+ @include mq('lg') {
70
+ height: 740px;
71
+ background:linear-gradient(90deg,#fff 0%,#fff 46%,$bg-color 46%,$bg-color 100%);
72
+ }
73
+
74
+ // 追加
75
+ .top-text-logo,
76
+ .top-sub-head-top,
77
+ .top-sub-head-bottom
78
+ {
79
+ position: relative;
80
+ z-index: 1;
81
+ }
82
+ // 追加ここまで
83
+
84
+ &:before {
85
+ content: "";
86
+ position: absolute;
87
+ background-image: url(http://placehold.jp/24/cc9999/993333/150x100.png?text=the-honest-company-uM-WXMr-3@2x.png);
88
+ width: 76.5%;
89
+ height: 87%;
90
+ object-fit: cover;
91
+ background-position: 54.5% 0%;
92
+ background-size: 450%;
93
+ background-repeat: no-repeat;
94
+ // z-index: -2; 削除
95
+ @include mq('md') {
96
+ height: 87%;
97
+ width: 78%;
98
+ background-position: 55% 0;
99
+ background-size: 330%;
100
+ }
101
+ @include mq('lg') {
102
+ background-size: 123%;
103
+ background-position: 80% 5%;
104
+ width: 76.5%;
105
+ height: 86.5%;
106
+ }
107
+
108
+ }
109
+
110
+ &:after{
111
+ content: "";
112
+ position: absolute;
113
+ background-color: rgba($color: #000000, $alpha: 0.35);
114
+ width: 76.5%;
115
+ height: 87%;
116
+ background-position: 55% 0%;
117
+ top: 0;
118
+ // z-index: -2; 削除
119
+ @include mq('md') {
120
+ width: 78%;
121
+ height: 87%;
122
+ background-position: 45% 44%;
123
+
124
+ }
125
+ @include mq('lg') {
126
+ width: 76.5%;
127
+ height: 86.5%;
128
+ background-position: 30% 45%;
129
+ }
130
+ }
131
+ ```
132
+
133
+ ---
134
+
135
+ z-indexは意外とややこしい仕様なので、あまり多用すると自分の首を絞めかねないです。
136
+
137
+ 参考:
138
+ [君は真に理解しているか?z-indexとスタッキングコンテキストの関係 - ICS MEDIA](https://ics.media/entry/200609/)