CSS - Menú vertical desplegable de 3 niveles

 
Vista:

Menú vertical desplegable de 3 niveles

Publicado por Selma (2 intervenciones) el 25/09/2019 16:43:00
Hola, estoy intentando hacer un menú vertical desplegable de 3 niveles pero no consigo hacer el tercer nivel porque los li no se desplazan hacia abajo cuando selecciono una opción, aquí está el código, gracias:

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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<html>
 
<head>
    <link href="icofont/icofont.min.css" rel="stylesheet">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <style>
        body {
            color: white;
        }
 
        nav {
            position: fixed;
            top: 55px;
            left: 0px;
            height: calc(100% - 55px);
            width: 180px;
            background: rgba(0, 0, 0, 0.7);
            overflow: hidden;
        }
        /*Nivel 1*/
 
        nav ul {
            list-style-type: none;
            margin: 0px;
            padding: 0px;
            cursor: pointer;
            position: relative;
        }
 
        nav>ul {
            margin-top: 20px;
        }
 
        nav>ul>li {
            text-align: left;
            font: 13px "Roboto Condensed", sans-serif;
            position: relative;
        }
 
        nav>ul>li>a {
            position: relative;
            display: flex;
            align-items: center;
            line-height: 40px;
            height: 40px;
            width: 100%;
            display: inline-block;
        }
 
        nav>ul>li>a>i {
            line-height: 40px !important;
        }
 
        nav>ul>li.seleccionado>a {
            background: #209E91;
        }
 
        nav>ul>li>a>span {
            width: 137px;
            display: inline-block;
            position: absolute;
            top: 0px;
            left: 45px;
        }
 
        nav>ul>li>a>span>i.flechita {
            position: absolute;
            top: 0px;
            right: 0px;
            margin-left: 10px;
            margin-right: 10px;
            line-height: 40px;
            font-size: 15px;
            transition: 0.8s;
            -moz-transition: 0.8s;
            -webkit-transition: 0.8s;
            -o-transition: 0.8s;
        }
 
        nav>ul>li>a>i {
            margin-left: 15px;
            margin-right: 15px;
        }
        /*Nivel 2*/
 
        nav>ul>li>ul {
            display: none;
        }
 
        nav>ul>li>ul>li {
            position: relative;
            height: 30px;
            border: 1px solid yellow;
        }
 
        nav>ul>li>ul>li.seleccionado a {
            background: #209E91;
        }
 
        nav>ul>li>ul>li>a {
            padding-left: 45px;
            width: 100%;
            height: 100%;
            display: inline-block;
            display: flex;
            align-items: center;
        }
 
        nav>ul>li>a:hover,
        nav>ul>li>ul>li>a:hover {
            color: #209E91;
        }
 
        nav>ul>li.seleccionado>a:hover,
        nav>ul>li>ul>li.seleccionado>a:hover {
            color: white;
        }
        /*Nivel 3*/
 
        nav>ul>li>ul>li>ul {
            position: relative;
            display: block;
            height: 90px !important;
        }
 
        nav>ul>li>ul>li>ul>li {
            position: relative;
            height: 30px;
        }
    </style>
</head>
 
<body>
 
    <nav>
        <ul>
            <li><a><span>Sección 1 <i class="icofont-curved-down flechita"></i></span></a>
                <ul>
                    <li><a>Sección 1.1</a></li>
                    <li><a>Sección 1.2</a></li>
                    <li><a>Sección 1.3</a></li>
                </ul>
            </li>
            <li><a><span>Sección 2 <i class="icofont-curved-down flechita"></i></span></a>
                <ul>
                    <li><a><span>Sección 2.1 <i class="icofont-curved-down flechita"></i></span></a>
                        <ul>
                            <li><a>Sección 2.1.1</a></li>
                            <li><a>Sección 2.1.2</a></li>
                            <li><a>Sección 2.1.3</a></li>
                        </ul>
 
                    </li>
                    <li><a>Sección 2.2</a></li>
 
                </ul>
            </li>
        </ul>
    </nav>
 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
 
    <script>
        var i = 0;
        var rotation = 0;
        $(document).ready(function() {
 
            $("nav ul li a").click(function() {
 
 
                $("nav").css("width", "180px");
                $("nav>ul>li>a>span").css("display", "inline");
 
 
 
                if (i % 2 === 0) {
                    rotation += 180;
                    i++;
                } else {
                    rotation -= 180;
                    i++;
                }
                $(this).parent().children("ul").slideToggle();
 
                $(this).children("span").children("i").css("transform", "rotate(" + rotation + "deg)");
                bandera = true;
            });
        });
    </script>
</body>
 
</html>
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 juan jose
Val: 165
Bronce
Ha mantenido su posición en CSS (en relación al último mes)
Gráfica de CSS

Menú vertical desplegable de 3 niveles

Publicado por juan jose (57 intervenciones) el 27/09/2019 21:26:02
el problema lo tienes en el script, que tienes en la zona inferior, lo que no entiendo por que script y no usar css directamente
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

Menú vertical desplegable de 3 niveles

Publicado por Selma (2 intervenciones) el 01/10/2019 16:08:14
Ya encontré el error, era que estaba poniendo una altura a los <li> que no dejaba que la lista hija se viera correctamente.
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