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

質問編集履歴

2

改善

2021/01/15 13:03

投稿

zawa0
zawa0

スコア1

title CHANGED
File without changes
body CHANGED
@@ -6,7 +6,7 @@
6
6
  書き方がわからずにいます
7
7
  別々の画像を設定するにはどうしたらいいでしょうか?
8
8
 
9
- ### 該当ソースコード
9
+ ### 現在のコード
10
10
 
11
11
  ```ここに言語名を入力
12
12
  <style>
@@ -34,7 +34,7 @@
34
34
  transition: 0.2s;
35
35
  box-sizing: border-box;
36
36
  }
37
- label:after {
37
+ #toggle1 + label:after {
38
38
  background-image:url('https://pics.prcm.jp/63a6a9d594d2a/77587568/png/77587568_480x480.png');
39
39
  background-repeat:no-repeat;
40
40
  background-position:100%;
@@ -49,79 +49,11 @@
49
49
  z-index: 2;
50
50
  transition: .1s;
51
51
  }
52
- .a:checked + label:after {
52
+ #toggle2 + label:after {
53
- content: "";
54
53
  background-image:url('https://pics.prcm.jp/63a6a9d594d2a/77587568/png/77587568_480x480.png');
55
54
  background-repeat:no-repeat;
56
55
  background-position:100%;
57
56
  background-size:80% 80%;
58
- left: 75%;
59
- }
60
- .toggle-switch {
61
- position: relative;
62
- width: 80%;
63
- height: 20%;
64
- }
65
-
66
- </style>
67
-
68
- <div class="toggle-switch">
69
- <input id="toggle" class="a" type="checkbox">
70
- <label for="toggle"></label>
71
- </div>
72
-
73
- <div class="toggle-switch">
74
- <input id="toggle" class="a" type="checkbox">
75
- <label for="toggle"></label>
76
- </div>
77
- ```
78
-
79
- 助言いただき、こうしましたが、うまくできません
80
-
81
- ```ここに言語を入力
82
- <style>
83
- body,html{
84
- background-color:black;
85
- height:100%;
86
- }
87
- .a {
88
- position: absolute;
89
- left: 0;
90
- top: 0%;
91
- width: 100%;
92
- height: 100%;
93
- z-index: 5;
94
- opacity: 0;
95
- cursor: pointer;
96
- }
97
- .label1 {
98
- background-color:red;
99
- width: 90%;
100
- height: 75%;
101
- position: relative;
102
- display: inline-block;
103
- border-radius: 5px;
104
- transition: 0.2s;
105
- box-sizing: border-box;
106
- }
107
-
108
- .label2 {
109
- background-color:red;
110
- width: 90%;
111
- height: 75%;
112
- position: relative;
113
- display: inline-block;
114
- border-radius: 5px;
115
- transition: 0.2s;
116
- box-sizing: border-box;
117
- }
118
-
119
-
120
- label1:after {
121
- background-image:url('https://pics.prcm.jp/63a6a9d594d2a/77587568/png/77587568_480x480.png');
122
- background-repeat:no-repeat;
123
- background-position:100%;
124
- background-size:80% 80%;
125
57
  content: "";
126
58
  position: absolute;
127
59
  width: 30%;
@@ -132,44 +64,24 @@
132
64
  z-index: 2;
133
65
  transition: .1s;
134
66
  }
67
+
135
- .a:checked + label1:after {
68
+ #toggle1 +.a:checked + label:after {
136
69
  content: "";
137
- background-image:url('https://pics.prcm.jp/63a6a9d594d2a/77587568/png/77587568_480x480.png');
70
+ background-image:url('https://cdn0.iconfinder.com/data/icons/small-n-flat/24/678087-heart-512.png');
138
71
  background-repeat:no-repeat;
139
72
  background-position:100%;
140
73
  background-size:80% 80%;
141
74
  left: 75%;
142
75
  }
143
76
 
144
-
145
-
146
- label2:after {
147
- background-image:url('https://cdn0.iconfinder.com/data/icons/small-n-flat/24/678087-heart-512.png');
148
- background-repeat:no-repeat;
77
+ #toggle2 +.a:checked + label:after {
149
- background-position:100%;
150
- background-size:80% 80%;
151
78
  content: "";
152
- position: absolute;
153
- width: 30%;
154
- height: 100%;
155
- border-radius: 50%;
156
- left: 0;
157
- top: 0;
158
- z-index: 2;
159
- transition: .1s;
160
- }
161
- .a:checked + label2:after {
162
- content: "";
163
79
  background-image:url('https://cdn0.iconfinder.com/data/icons/small-n-flat/24/678087-heart-512.png');
164
80
  background-repeat:no-repeat;
165
81
  background-position:100%;
166
82
  background-size:80% 80%;
167
83
  left: 75%;
168
84
  }
169
-
170
-
171
-
172
-
173
85
  .toggle-switch {
174
86
  position: relative;
175
87
  width: 80%;
@@ -179,12 +91,12 @@
179
91
  </style>
180
92
 
181
93
  <div class="toggle-switch">
182
- <input id="toggle" class="a" type="checkbox">
94
+ <input id="toggle1" class="a" type="checkbox">
183
- <label for="toggle" class="label1"></label>
95
+ <label for="toggle1"></label>
184
96
  </div>
185
97
 
186
98
  <div class="toggle-switch">
187
- <input id="toggle" class="a" type="checkbox">
99
+ <input id="toggle2" class="a" type="checkbox">
188
- <label for="toggle" class="label2"></label>
100
+ <label for="toggle2"></label>
189
101
  </div>
190
102
  ```

1

追記

2021/01/15 13:03

投稿

zawa0
zawa0

スコア1

title CHANGED
File without changes
body CHANGED
@@ -74,4 +74,117 @@
74
74
  <input id="toggle" class="a" type="checkbox">
75
75
  <label for="toggle"></label>
76
76
  </div>
77
+ ```
78
+
79
+ 助言いただき、こうしましたが、うまくできません
80
+
81
+ ```ここに言語を入力
82
+ <style>
83
+ body,html{
84
+ background-color:black;
85
+ height:100%;
86
+ }
87
+ .a {
88
+ position: absolute;
89
+ left: 0;
90
+ top: 0%;
91
+ width: 100%;
92
+ height: 100%;
93
+ z-index: 5;
94
+ opacity: 0;
95
+ cursor: pointer;
96
+ }
97
+ .label1 {
98
+ background-color:red;
99
+ width: 90%;
100
+ height: 75%;
101
+ position: relative;
102
+ display: inline-block;
103
+ border-radius: 5px;
104
+ transition: 0.2s;
105
+ box-sizing: border-box;
106
+ }
107
+
108
+ .label2 {
109
+ background-color:red;
110
+ width: 90%;
111
+ height: 75%;
112
+ position: relative;
113
+ display: inline-block;
114
+ border-radius: 5px;
115
+ transition: 0.2s;
116
+ box-sizing: border-box;
117
+ }
118
+
119
+
120
+ label1:after {
121
+ background-image:url('https://pics.prcm.jp/63a6a9d594d2a/77587568/png/77587568_480x480.png');
122
+ background-repeat:no-repeat;
123
+ background-position:100%;
124
+ background-size:80% 80%;
125
+ content: "";
126
+ position: absolute;
127
+ width: 30%;
128
+ height: 100%;
129
+ border-radius: 50%;
130
+ left: 0;
131
+ top: 0;
132
+ z-index: 2;
133
+ transition: .1s;
134
+ }
135
+ .a:checked + label1:after {
136
+ content: "";
137
+ background-image:url('https://pics.prcm.jp/63a6a9d594d2a/77587568/png/77587568_480x480.png');
138
+ background-repeat:no-repeat;
139
+ background-position:100%;
140
+ background-size:80% 80%;
141
+ left: 75%;
142
+ }
143
+
144
+
145
+
146
+ label2:after {
147
+ background-image:url('https://cdn0.iconfinder.com/data/icons/small-n-flat/24/678087-heart-512.png');
148
+ background-repeat:no-repeat;
149
+ background-position:100%;
150
+ background-size:80% 80%;
151
+ content: "";
152
+ position: absolute;
153
+ width: 30%;
154
+ height: 100%;
155
+ border-radius: 50%;
156
+ left: 0;
157
+ top: 0;
158
+ z-index: 2;
159
+ transition: .1s;
160
+ }
161
+ .a:checked + label2:after {
162
+ content: "";
163
+ background-image:url('https://cdn0.iconfinder.com/data/icons/small-n-flat/24/678087-heart-512.png');
164
+ background-repeat:no-repeat;
165
+ background-position:100%;
166
+ background-size:80% 80%;
167
+ left: 75%;
168
+ }
169
+
170
+
171
+
172
+
173
+ .toggle-switch {
174
+ position: relative;
175
+ width: 80%;
176
+ height: 20%;
177
+ }
178
+
179
+ </style>
180
+
181
+ <div class="toggle-switch">
182
+ <input id="toggle" class="a" type="checkbox">
183
+ <label for="toggle" class="label1"></label>
184
+ </div>
185
+
186
+ <div class="toggle-switch">
187
+ <input id="toggle" class="a" type="checkbox">
188
+ <label for="toggle" class="label2"></label>
189
+ </div>
77
190
  ```