Кто-нибудь знает, как мне держать раскрывающиеся меню открытыми при нажатии кнопки?CSS

Разбираемся в CSS
Ответить Пред. темаСлед. тема
Anonymous
 Кто-нибудь знает, как мне держать раскрывающиеся меню открытыми при нажатии кнопки?

Сообщение Anonymous »

Я сейчас изучаю JS, поэтому я новичок в этом и учусь самостоятельно. Когда я нажимаю кнопки раскрывающегося списка, мои кнопки не остаются активными, открываются на полсекунды и снова закрываются. Сможет ли кто-нибудь рассказать мне, как я могу держать их открытыми с помощью JS? Вот мой код на данный момент! был бы признателен за помощь! Кстати, я не знал об этом проекте, поэтому он и на Илоне Маске, лол.

Код: Выделить всё

let menu_icons = document.querySelector('.menu-icons'),
nav = document.querySelector('nav');

menu_icons.addEventListener('click', () => {
nav.classList.toggle('active');
});

Код: Выделить всё

* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}

#fullscreen-video-container {
position: absolute;
top: 0;
left: 0;
scale: 100%;
overflow: hidden;
z-index: -10;
}

#fullscreen-video-container video {
object-fit: cover;
width: 100%;
height: 100%;
}

img {
top: 5px;
position: relative;
height: 200px;
width: 200px;

}
:root {
--main-color: rgb(228, 145, 37);
}

html {
font-size: 10px;
}

body {

background-attachment: fixed;
background-size: cover;
background-repeat: no-repeat;
min-height: 100vh;
overflow-x: hidden;
}

body::before {
position: absolute;
min-height: 100vh;
content: '';
width: 100%;

}

a {
text-decoration: none;
}

ul {
list-style: none;
}

header {
width: 100%;
position: absolute;
top: 0;
left: 0;
}

.container {
width: 100%;
margin: 0 auto;
}

.menu-icons {
display: none;
align-items: center;
justify-content: center;
color: #eee;
font-size: 2rem;
position: absolute;
top: 50%;
right: 2rem;
transform: translateY(-50%);
-webkit-transform: translateY(-50%);
-moz-transform: translateY(-50%);
-ms-transform: translateY(-50%);
-o-transform: translateY(-50%);
cursor: pointer;
z-index: 1500;
/* display: none;  */
}

nav {
width: 100%;
border-radius: 1px solid rgba(255, 255, 255, 0.1);
-webkit-border-radius: 1px solid rgba(255, 255, 255, 0.1);
-moz-border-radius: 1px solid rgba(255, 255, 255, 0.1);
-ms-border-radius: 1px solid rgba(255, 255, 255, 0.1);
-o-border-radius: 1px solid rgba(255, 255, 255, 0.1);
display: flex;
align-items: center;
height: 60px;

justify-content: center;
gap: 2rem;
}

.nav-list {
display: flex;
align-items: center;
}

.nav-list li {
line-height: 8rem;
position: relative
}

.sub-menu li {
line-height: 4rem;
}

.nav-list a {
display: block;
color: #eee;
padding: 0 1.5rem;
font-size: 1.4rem;
text-transform: uppercase;
transition: color 650ms;
-webkit-transition: color 650ms;
-moz-transition: color 650ms;
-ms-transition: color 650ms;
-o-transition: color 650ms;
position: relative;
width: 100%;
align-items: center;
top: 15px;
margin-left: 50px;

}

.nav-list a:active {
color: var(--main-color);
}

.btn {
padding: 1.3rem;
display: inline-block;
border: 2px solid var(--main-color);
border-radius: 0.5rem;
-webkit-border-radius: 0.5rem;
-moz-border-radius: 0.5rem;
-ms-border-radius: 0.5rem;
-o-border-radius: 0.5rem;
transition: background-color 650ms;
-webkit-transition: background-color 650ms;
-moz-transition: background-color 650ms;
-ms-transition: background-color 650ms;
-o-transition: background-color 650ms;
}

.btn:active {
color: var(--main-color);
}

.sub-menu {
width: 20rem;
display: block;
position: absolute;
border-top: 3px solid var(--main-color);
background-color: #ff2222;
z-index: 100;
top: 16rem;
transition: all 250ms ease;
-webkit-transition: all 250ms ease;
-moz-transition: all 250ms ease;
-ms-transition: all 250ms ease;
-o-transition: all 250ms ease;
opacity: 0;
visibility: hidden;
}

.sub-menu::before {
content: '';
position: absolute;
top: -2.5rem;
left: 3rem;
border: 1.2rem solid transparent;
border-bottom: 1.2rem solid var(--main-color);
}

.sub-menu .sub-menu::before {
top: .9rem;
left: -2.5rem;
border: 1.2rem solid transparent;
border-right-color: var(--main-color);
}

.sub-menu .sub-menu {
border-top: none;
border-left: 3px solid var(--main-color);
top: 0;
left: 160%;
}

.nav-list li:active>.sub-menu {
top: 8rem;
opacity: 1;
visibility: visible;
}

.sub-menu li:active>.sub-menu {
top: 0;
left: 100%;
}

li.move-right {
margin: auto 0 auto auto;
line-height: initial;
}

@media screen  and (max-width: 900px) {
.nav-list {
position: fixed;
top: 0;
height: 100vh;
flex-direction: column;
background-color: #191919;
z-index: 1000;
align-items: initial;
display: none;
overflow-y: scroll;
width: 50%;
right: 0;
}

.nav-list > li {
line-height: 6rem;
}

.sub-menu {
position: initial;
border: 3px solid transparent;
margin-left: 1rem;
max-height: 0;
background: rgba(0, 0, 0, 0.5);
overflow: hidden;
margin-right: 0.4rem;
padding-right: 1rem;
}

.sub-menu .sub-menu {
border: none;
overflow: hidden;
margin-right: 0.4rem;
}

.sub-menu::before {
display: none;
}

.nav-list li:active >  .sub-menu {
opacity: 1;
visibility: visible;
max-height: initial;
}

li.move-right {
margin: 0 auto 0 0;
line-height: initial;
}

.menu-icons {
display: block;
}

.fa-times {
display: none;
}

nav.active .fa-times {
display: block;
}

nav.active .fa-bars {
display: none;
}

nav.active .nav-list {
display: flex;
}
}

Код: Выделить всё






[*]

Document






[i][/i]
[i][/i]

[url=#][i][/url]

[list]

[url=#]Home[/url]

[*]
[url=#]ELON MUSK[/url]

[*]
[url=#]THROUGH TIME[/url]

[*]
[url=#]ELON ODYSSEY [/i][/url]


[url=#]SPACE X[/url]

[*]
[url=#]NEUROLINK[/url]

[*]
[url=#]TESLA[/url]

[/list]



[*]
[url=#]MORE
[i][/i]
[/url]
[list]

[url=#]DOGE[/url]

[*]
[url=#]FORUMS[/url]

[*]
[url=#]BLOGS[/url]

[/list]

















Подробнее здесь: https://stackoverflow.com/questions/792 ... on-is-clic
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «CSS»