HTML - Problema con acordeón html

 
Vista:

Problema con acordeón html

Publicado por Camila (1 intervención) el 24/11/2020 19:08:22
Buenas, he estado echando una mano con un proyecto de un amigo, pero en este ultimo script para un acordeon que se abre y muestra mas items pasa que no puedo poner mas de 3 porque uno deja de funcionar, para integrarlo a la pagina uso elementor con el witget para codigo html

Aquí el código

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src='https://kit.fontawesome.com/a076d05399.js'></script>
<style>
 
 
.accordion {
  background-color: white;
  color: #D8AC00;
  cursor: pointer;
  padding: -18px;
  width: 100%;
  border: none;
  text-align: left;
  outline: none;
  font-size: 15px;
  transition: 0.4s;
  font-family: 'Poppins', sans-serif;
}
 
.active, .accordion:hover {
  background-color: white;
  color: #8B6E00;
}
 
.active, .accordion:hover:after {
  background-color: white;
  color: #8B6E00;
}
 
.accordion:after {
    content: '\002B';
    color: #D8AC00;
    font-weight: bold;
    float: left;
    font-size: 20px;
}
 
.active:after {
  content: "\2212";
  color: #8B6E00;
}
 
.panel {
  padding: 0 18px;
  background-color: white;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease-out;
  z-index: 800;
}
 
ul {
  list-style: none; /* Remove list bullets */
  padding: 0;
  margin-left: -20px;
}
 
.fa-chevron-right:before {
    content: "\f054";
    color:#D8AC00;
    position: relative;
    top: 3px;
    margin-right: 10px;
    margin-left: -1px;
}
 

h3.texst {
    font-family: 'Poppins', sans-serif;
}
 
hr {
    border-top: 1px solid #DDDDDD;
    height: 0;
    margin: 10px 5px;
    box-sizing: border-box;
    max-width: 42rem;
}
 
 
 
</style>
 
</head>
<body>
 
<button class="accordion">Ver Mas</button>
<div class="panel">
<ul>
	<li class="lista"><h3 class="texst" style="font-family: 'Poppins', sans-serif; font-size:16px; color:#54595F; font-weight: 400"><i class='fas fa-chevron-right' style='font-size:15px'></i>Item</h3></li>
	<hr>
	<li class="lista"><h3 class="texst" style="font-family: 'Poppins', sans-serif; font-size:16px; color:#54595F; font-weight: 400"><i class='fas fa-chevron-right' style='font-size:15px'></i>Item</h3></li>
	<hr>
	<li class="lista"><h3 class="texst" style="font-family: 'Poppins', sans-serif; font-size:16px; color:#54595F; font-weight: 400"><i class='fas fa-chevron-right' style='font-size:15px'></i>Item</h3></li>
	<hr>
	<li class="lista"><h3 class="texst" style="font-family: 'Poppins', sans-serif; font-size:16px; color:#54595F; font-weight: 400"><i class='fas fa-chevron-right' style='font-size:15px'></i>Item</h3></li>
	<hr>
	<li class="lista"><h3 class="texst" style="font-family: 'Poppins', sans-serif; font-size:16px; color:#54595F; font-weight: 400"><i class='fas fa-chevron-right' style='font-size:15px'></i>Item</h3></li>
</ul>
</div>
 
<script>
var acc = document.getElementsByClassName("accordion");
var i;
 
for (i = 0; i < acc.length; i++) {
  acc[i].addEventListener("click", function() {
    this.classList.toggle("active");
    var panel = this.nextElementSibling;
    if (panel.style.maxHeight) {
      panel.style.maxHeight = null;
    } else {
      panel.style.maxHeight = panel.scrollHeight + "px";
    }
  });
}
</script>
 
</body>
</html>


No se que tan bien o mal este hecho pues es un rejunte varias cosas que he ido encontrando y de lo que he ido aprendo pues aun soy bastante novata
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de joel
Val: 1.453
Oro
Ha mantenido su posición en HTML (en relación al último mes)
Gráfica de HTML

Problema con acordeón html

Publicado por joel (460 intervenciones) el 29/11/2020 09:25:28
Hola Camila, no me queda muy claro tu problema... lo acabo de probar y me abre los 5 elementos correctamente.

Nos puedes comentar con mas detalle?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar