gpt4 book ai didi

html - 带有 flexbox 的响应式导航栏

转载 作者:行者123 更新时间:2023-11-28 15:06:39 25 4
gpt4 key购买 nike

我正在学习从头开始构建一个网站,这样我就可以正确地学习如何构建一个漂亮的网站,但是我从导航栏开始,但即使使用 flexbox 也没有响应,你愿意指定我正确的方向吗,我我正在使用媒体查询,但我没做对

* {
margin: 0;
padding: 0;
}

nav {
display: flex;
align-items: center;
justify-content: space-around;
width: 100%;
height: 10vh;
background-color: aqua;
margin: 0;
padding: 0;
}

.logo {
list-style-type: none;
display: flex;
flex-wrap: wrap
}

.first {
list-style-type: none;
margin-right: 30rem;
padding: 0;
display: flex;
flex-wrap: wrap;
}

.second {
list-style-type: none;
margin: 0;
padding: 0;
display: flex;
flex-wrap: wrap;
}

.first li {
padding-left: 2rem;
}

.first li a {
display: block;
color: #000;
padding: 8px 16px;
text-decoration: none;
}

.first li:hover {}

.second li {
padding-left: 2rem;
}

nav ul li a {
display: block;
color: #000;
padding: 8px 16px;
text-decoration: none;
text-transform: uppercase;
}

@media all and (max-width: 500px) {
nav {
flex-direction: column;
}
}
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="/css/style.css">
<title>Document</title>
</head>

<body>
<nav>
<ul class="logo">
<li> <a href="">brand</a></li>

</ul>
<ul class="first">
<li> <a href=""> our products</a></li>

<li> <a href=""> Title2</a></li>
<li> <a href=""> Title3</a></li>
</ul>


<ul class="second">
<li> <a href=""> En</a></li>
<li> <a href=""> Login in</a></li>

</ul>

</nav>

</body>

</html>

最佳答案

这里的主要内容 - 您要确定并为桌面设置 flex-direction: row。我还将 nav 的高度设置为 auto,将宽度设置为 100vw,主要用于代码演示。由于某种原因,代码演示在预览窗口中看起来不正确,但在全屏中显示正确。

* {
margin: 0;
padding: 0;
}

nav {
display: flex;
align-items: center;
flex-direction: row;
justify-content: space-around;
width: 100vw;
height: auto;
background-color: aqua;
margin: 0;
padding: 0;
}

.logo {
list-style-type: none;
display: flex;
}

.first {
list-style-type: none;
margin-right: 30rem;
padding: 0;
display: flex;
}

.second {
list-style-type: none;
margin: 0;
padding: 0;
display: flex;
}

.first li {
padding-left: 2rem;
}

.first li a {
display: block;
color: #000;
padding: 8px 16px;
text-decoration: none;
}

.first li:hover {}

.second li {
padding-left: 2rem;
}

nav ul li a {
display: block;
color: #000;
padding: 8px 16px;
text-decoration: none;
text-transform: uppercase;
}

@media all and (max-width: 500px) {
nav {
flex-direction: column;
}
}
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="/css/style.css">
<title>Document</title>
</head>

<body>
<nav>
<ul class="logo">
<li> <a href="">brand</a></li>

</ul>
<ul class="first">
<li> <a href=""> our products</a></li>

<li> <a href=""> Title2</a></li>
<li> <a href=""> Title3</a></li>
</ul>


<ul class="second">
<li> <a href=""> En</a></li>
<li> <a href=""> Login in</a></li>

</ul>

</nav>

</body>

</html>

关于html - 带有 flexbox 的响应式导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56192174/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com