В этом пример (код скопирован ниже) всегда отображается первый элемент «Home». Как я могу скрыть элемент «Дом», как и все остальные, если окно достаточно маленькое?
Любая помощь очень ценится, спасибо.
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width=device-width, initial-scale=1">
<style>
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
.topnav {
overflow: hidden;
background-color: #333;
}
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover {
background-color: #ddd;
color: black;
}
.active {
background-color: #4CAF50;
color: white;
}
.topnav .icon {
display: none;
}
@media screen and (max-width: 600px) {
.topnav a:not(:first-child) {display: none;}
.topnav a.icon {
float: right;
display: block;
}
}
@media screen and (max-width: 600px) {
.topnav.responsive {position: relative;}
.topnav.responsive .icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
}
</style>
</head>
<body>
<div class = "topnav" id = "myTopnav">
<a href = "#home" class = "active">Home</a>
<a href = "#news">News</a>
<a href = "#contact">Contact</a>
<a href = "#about">About</a>
<a href = "javascript:void(0);" style = "font-size:15px;" class = "icon" onclick = "myFunction()">☰</a>
</div>
<div style = "padding-left:16px">
<h2>Responsive Topnav Example</h2>
<p>Resize the browser window to see how it works.</p>
</div>
<script>
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
</script>
</body>
</html>У вас есть а: нет (: первенец), который пропускает первого ребенка, который находится дома: D
@LucianoGiordano "Достаточно маленькое" означает, что окно достаточно маленькое, чтобы отображать меню в верхней части навигации.



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Причина в том, что в медиа-запросе указано: not (: first-child), а другой дочерний дисплей: none. в другом, чтобы скрыть все дочерние элементы, включая изменение firstchild
@media screen and (max-width: 600px) {
.topnav a:not(:first-child) {display: none;}
.topnav a.icon {
float: right;
display: block;
}
}
to
@media screen and (max-width: 600px) {
.topnav a {display: none;}
.topnav a.icon {
float: right;
display: block;
}
}
Ты должен сказать почему
причина, если из-за медиа-запроса указано: not (: first-child), а другой дочерний дисплей: none;
Я знаю, зачем добавлять свой ответ для других
Пожалуйста, уточните, что вы имеете в виду под словом «достаточно маленький» :-)