質問編集履歴

3

コード変更

2022/12/05 05:18

投稿

mumu1354
mumu1354

スコア18

test CHANGED
File without changes
test CHANGED
@@ -13,12 +13,14 @@
13
13
 
14
14
  aに
15
15
  ```css
16
- transform: translate(0, 0);
16
+ opacity: 1;
17
17
  ```
18
18
  を設定しているため
19
+ aに
20
+ transform-style: preserve-3d;
19
21
  bに
20
22
  ```css
21
- z-index: -1;
23
+ transform: translateZ(-1px);
22
24
  ```
23
25
  をつけても背面に行かない
24
26
 
@@ -26,23 +28,176 @@
26
28
  ### 該当のソースコード
27
29
 
28
30
  ```HTML
29
- <div class="a"></div>
30
- ```
31
- ```css
32
- .a{
33
- widthやheightは省略
34
- position: relative;
35
- transform: translate(0, 0);
36
- &::after (b){
37
- widthやheightは省略
38
- content: '';
39
- position: absolute;
40
- top: -xxxx;
41
- right: -xxxx;
42
- z-index: -1;
43
- }
44
- }
45
- ```
31
+ <div class="box-inner">
32
+ <section class="section">
33
+ <div class="box0">
34
+ </div>
35
+ </section>
36
+ <section class="section2">
37
+ <h2 class="section2__ttl">タイトル</h2>
38
+ <div class="fade-in fade-in-up box">
39
+ <ul class="box__list">
40
+ <li class="box__list-item">
41
+ <div class="box__list-icon">
42
+ <i class="box__fas fas fa-thumbs-up"></i>
43
+ </div>
44
+ <h3 class="box__list-ttl">Good</h3>
45
+ <p class="box__txt">テキストテキストテキストテキストテキストテキスト</p>
46
+ </li>
47
+ <li class="box__list-item">
48
+ <div class="box__list-icon">
49
+ <i class="box__fas fas fa-thumbs-up"></i>
50
+ </div>
51
+ <h3 class="box__list-ttl">Good</h3>
52
+ <p class="box__txt">テキストテキストテキストテキストテキストテキスト</p>
53
+ </li>
54
+ <li class="box__list-item">
55
+ <div class="box__list-icon">
56
+ <i class="box__fas fas fa-thumbs-up"></i>
57
+ </div>
58
+ <h3 class="box__list-ttl">Good</h3>
59
+ <p class="box__txt">テキストテキストテキストテキストテキストテキスト</p>
60
+ </li>
61
+ <li class="box__list-item">
62
+ <div class="box__list-icon">
63
+ <i class="box__fas fas fa-thumbs-up"></i>
64
+ </div>
65
+ <h3 class="box__list-ttl">Good</h3>
66
+ <p class="box__txt">テキストテキストテキストテキストテキストテキスト</p>
67
+ </li>
68
+ <li class="box__list-item">
69
+ <div class="box__list-icon">
70
+ <i class="box__fas fas fa-thumbs-up"></i>
71
+ </div>
72
+ <h3 class="box__list-ttl">Good</h3>
73
+ <p class="box__txt">テキストテキストテキストテキストテキストテキスト</p>
74
+ </li>
75
+ <li class="box__list-item">
76
+ <div class="box__list-icon">
77
+ <i class="box__fas fas fa-thumbs-up"></i>
78
+ </div>
79
+ <h3 class="box__list-ttl">Good</h3>
80
+ <p class="box__txt">テキストテキストテキストテキストテキストテキスト</p>
81
+ </li>
82
+ </ul>
83
+ </div>
84
+ </section>
85
+ </div>
86
+ ```
87
+ ```css
88
+ //sass
89
+ .box-inner{
90
+ padding: 0 15.66vw;
91
+ color: #E4EAF3;
92
+ }
93
+ .box0{
94
+ height:100svh;
95
+ width:100%;
96
+ background-color: #800080;
97
+ }
98
+ .section2{
99
+ margin-top:440px;
100
+ position: relative;
101
+ &__ttl{
102
+ font-size: 1.5rem;
103
+ margin: 0;
104
+ letter-spacing: 0.1875rem;
105
+ padding: 152px 74px;
106
+ background-color: #800080;
107
+ display: inline-block;
108
+ position: absolute;
109
+ right: 0;
110
+ top: -156px;
111
+ z-index: 1;
112
+ }
113
+ }
114
+ .box{
115
+ margin-left: -15.66vw;
116
+ margin-right: 183px;
117
+ margin-top: 156px;
118
+ padding-right: 304px;
119
+ padding-left: 15.66vw;
120
+ padding-top: 116px;
121
+ padding-bottom: 142px;
122
+ background-color: #908fb1;
123
+ box-sizing: border-box;
124
+ position: relative;
125
+ transform-style: preserve-3d;
126
+ &::after {
127
+ opacity: 1;
128
+ width: calc(100vw - 15.66vw);
129
+ content: '';
130
+ background-color: #bbbcd2;
131
+ position: absolute;
132
+ height: calc(100% + 32px);
133
+ top: -84px;
134
+ z-index: -1;
135
+ -webkit-transform: translateZ(-1px);
136
+ transform: translateZ(-1px);
137
+ }
138
+ &__list{
139
+ display: flex;
140
+ justify-content: end;
141
+ flex-wrap: wrap;
142
+ padding-left: 0;
143
+ list-style: none;
144
+ margin-top: -116px;
145
+ margin-left: -96px;
146
+ }
147
+ &__list-item{
148
+ width: 224px;
149
+ text-align: center;
150
+ margin-top: 116px;
151
+ margin-left: 96px;
152
+ }
153
+ &__list-icon {
154
+ width: 100px;
155
+ margin: 0 auto;
156
+ }
157
+ &__fas{
158
+ font-size: 56px;
159
+ }
160
+ &__list-ttl{
161
+ margin-top: 16px;
162
+ margin-bottom: 0;
163
+ font-size: 1.25rem;
164
+ font-weight: 600;
165
+ }
166
+ &__txt {
167
+ text-align: left;
168
+ line-height: 1.65;
169
+ }
170
+ }
171
+ .fade-in {
172
+ opacity: 0;
173
+ transition-duration:2s;
174
+ transition-property:opacity,transform;
175
+ }
176
+
177
+ .fade-in-up {
178
+ transform: translate(0, 50px);
179
+ }
180
+
181
+ .scroll-in {
182
+ opacity: 1;
183
+ transform: translate(0, 0);
184
+ }
185
+ ```
186
+ ```JavaScript
187
+ let fadeInTarget = document.querySelectorAll('.fade-in');
188
+ window.addEventListener('scroll', () => {
189
+ for (let i = 0; i < fadeInTarget.length; i++){
190
+ const rect = fadeInTarget[i].getBoundingClientRect().top;
191
+ const scroll = window.pageYOffset || document.documentElement.scrollTop;
192
+ const offset = rect + scroll;
193
+ const windowHeight = window.innerHeight; // 現在のブラウザの高さ
194
+ if (scroll > offset - windowHeight + 150) {
195
+ fadeInTarget[i].classList.add('scroll-in');
196
+ }
197
+ }
198
+ });
199
+ ```
200
+
46
201
  aに
47
202
  ```css
48
203
  transform: translate(0, 0);
@@ -67,7 +222,10 @@
67
222
  aの疑似要素で実現したいとおもっています。
68
223
 
69
224
 
225
+ bのほうが大きい(width: calc(100vw - 15.66vw);
226
+ height: calc(100% + 32px);
227
+ )ため
70
- bのほうが大きいためbox-shadowではできませんでした。
228
+ box-shadowではできませんでした。
71
229
 
72
230
  ### 試したこと
73
231
 

2

codepen追加

2022/12/05 05:09

投稿

mumu1354
mumu1354

スコア18

test CHANGED
File without changes
test CHANGED
@@ -5,6 +5,8 @@
5
5
  ### 実現したいこと
6
6
 
7
7
  aの後ろにbのような背景を作成したいです。
8
+ codepen
9
+ https://codepen.io/yon-s/pen/KKebPgp
8
10
 
9
11
 
10
12
  ### 発生している問題・エラーメッセージ

1

//スクロール前に transition-duration:2s; transition-property:opacity,transform; を追加しました。

2022/12/01 03:02

投稿

mumu1354
mumu1354

スコア18

test CHANGED
File without changes
test CHANGED
@@ -50,6 +50,8 @@
50
50
  スクロールすると
51
51
  ```css
52
52
  //スクロール前
53
+ transition-duration:2s;
54
+ transition-property:opacity,transform;
53
55
  opacity: 0;
54
56
  transform: translate(-50%, 0);
55
57