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

質問編集履歴

1

説明の不足を補足

2021/09/16 11:58

投稿

nightmare10good
nightmare10good

スコア2

title CHANGED
File without changes
body CHANGED
@@ -1,12 +1,75 @@
1
1
  CSSとHTMLのみでアコーディオンを作りたいのですが、うまくいきません。
2
+
3
+ アコーディオンAをクリックしたらアコーディオンが開きaaa・bbb・cccを表示、
4
+ アコーディオンBをクリックしたらアコーディオンが開きddd・eee・fffを表示、
5
+
6
+ というものを作りたいのですが、アコーディオンAをクリックすると aaa・bbb・ccc だけでなく ddd・eee・fff も表示されてしまいます。
7
+ また、アコーディオンをクリックする前から aaa・bbb・ccc ddd・eee・fff それぞれあるだろう位置にスペースができてしまっています。
8
+ どうすればうまくいくでしょうか?
2
9
  ```HTML
3
10
  <div class="table">
4
11
  <input type="checkbox" id="acd-btn01" class="acd-check">
5
- <label class="row past-data acd-label" for="acd-btn01">
12
+ <label class="row acd-label" for="acd-btn01">
6
- <div class="cell">2020年</div>
13
+ <div class="cell">アコーディオンA</div>
7
- <div class="cell"></div>
14
+ <div class="cell"></div>
8
- <div class="cell">1200000 kg</div>
9
- <div class="cell">1200 台</div>
10
15
  </label>
16
+ <div class="row">
17
+ <div class="cell">aaa</div>
18
+ <div class="cell">子</div>
19
+  </div>
20
+ <div class="row">
21
+ <div class="cell">bbb</div>
22
+ <div class="cell">子</div>
23
+  </div>
24
+ <div class="row">
25
+ <div class="cell">ccc</div>
26
+ <div class="cell">子</div>
27
+  </div>
28
+ <input type="checkbox" id="acd-btn02" class="acd-check">
29
+ <label class="row acd-label" for="acd-btn02">
30
+ <div class="cell">アコーディオンB</div>
31
+ <div class="cell">親</div>
32
+ </label>
33
+ <div class="row">
34
+ <div class="cell">ddd</div>
35
+ <div class="cell">子</div>
36
+  </div>
37
+ <div class="row">
38
+ <div class="cell">eee</div>
39
+ <div class="cell">子</div>
40
+  </div>
41
+ <div class="row">
42
+ <div class="cell">fff</div>
43
+ <div class="cell">子</div>
44
+  </div>
11
45
  </div>
46
+ ```
47
+ ```css
48
+ div.table {
49
+ display: table;
50
+ width: 100%;
51
+ }
52
+ div.table .row {
53
+ display: table-row;
54
+ }
55
+ div.table .cell {
56
+ display: table-cell;
57
+ font-size: 1.1em;
58
+ height: 2.3em;
59
+ line-height: 2.3em;
60
+ padding: 0 10px;
61
+ }
62
+ .acd-check {
63
+ display: none;
64
+ }
65
+ .acd-content {
66
+ height: 0;
67
+ opacity: 0;
68
+ visibility: hidden;
69
+ }
70
+ .acd-check:checked + .acd-label ~ .acd-content {
71
+ height: 2.3em;
72
+ opacity: 1;
73
+ visibility: visible ;
74
+ }
12
75
  ```