gpt4 book ai didi

html - 导航栏中 "Menu"按钮的响应问题

转载 作者:行者123 更新时间:2023-12-05 05:43:03 25 4
gpt4 key购买 nike

我正在建立一个网站,我想让它更具响应性,目前我只需要让导航栏响应,但我遇到了问题,尤其是“菜单”按钮,当我制作屏幕时更小,“菜单”按钮在导航栏下方,有人可以帮我吗? (如果你需要看这个网站,我已经把它放在 Github Pages 上了:

https://eduardwildneto.github.io/ConversorDeUnidades/ ),

这是我的代码:

.navbar {
background: rgb(6, 0, 206);
color: rgb(0, 0, 0);
padding: 1px;
max-height: 55px;
margin-bottom: 10px;
position: sticky;
font-size: 20x;
z-index: 999;
top: 0px;
position: sticky;
}

.navbar ul {
list-style: none;
padding: 0;
}

.navbar ul li {
display: inline;
}

.navbar ul li a {
display: inline;
color: white;
text-decoration: none;
padding: 15px;
display: inline-block;
margin: auto;
}

#dominio-principal {
padding-left: 10%;
padding-right: 61%;
font-size: 18px;
}

#outros-dominios-1 {
float: left;
font-size: 15px;
}

#outros-dominios {
font-size: 15px;
padding-left: 1px;
}


/*.navbar {
background: rgb(6, 0, 206);
color: white;
font-size: 20px;
padding: 1%;
min-height: 65px;
}

.navbar ul {
list-style: none;
}

.navbar ul li {
display: inline;
}

.navbar ul li:last-child {
float: right;
margin-right: 4%;
}

.navbar ul li a {
color: white;
text-decoration: none;
}

#dominio-principal {
font-size: 18px;
position: absolute;
}


#outros-dominios-1 {
padding-left: 406px;
font-size: 15px;
}

#outros-dominios {
font-size: 15px;
padding-left: 1px;
}*/


/*Dropdown*/

.dropbtn {
background-color: rgb(6, 0, 206);
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
z-index: 999;
color: white;
}


/* Dropdown button on hover & focus */

.dropbtn:hover,
.dropbtn:focus {
background-color: rgb(6, 0, 206);
z-index: 999;
}


/* The container <div> - needed to position the dropdown content */

.dropdown {
position: relative;
display: inline-block;
z-index: 999;
}


/* Dropdown Content (Hidden by Default) */

.dropdown-content {
display: none;
position: absolute;
background-color: rgb(238, 238, 238);
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 999;
}


/* Links inside the dropdown */

.dropdown-content a {
padding: 12px 16px;
text-decoration: none;
display: block;
z-index: 999;
color: black;
}


/* Change color of dropdown links on hover */

.dropdown-content a:hover {
background-color: #ddd;
z-index: 999;
}


/* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */

.show {
display: block;
z-index: 999;
}
<header>
<nav class="navbar">
<ul>
<li><a href="" id="dominio-principal">Conversor de Unidades</a></li>
<div class="dropdown">
<button onclick="dropdown()" class="dropbtn">Menu</button>
<div id="myDropdown" class="dropdown-content">
<a href="index.html">Distância</a>
<a href="">Peso (Em construção)</a>
<a href="">Área (Em construção)</a>
<a href="">Volume (Em construção)</a>
<a href="">Temperatura (Em construção)</a>
<a href="">Tempo (Em construção)</a>
<a href="">Dados (Em construção)</a>
</div>
</div>
</ul>
</nav>
</header>

最佳答案

尝试使用 flexbox 让你的导航栏响应。引用访问 https://www.w3schools.com/css/css3_flexbox.asp

要开始使用 Flexbox,您需要先在您的 css 文件 style.css 中定义一个 flex 容器 .navbar ul :

你可以改变它:

.navbar ul {
list-style: none;
padding: 0 10%; /*To adjust left & right navbar padding*/
display: flex;
justify-content: space-between; /*or space-around*/
}

之后你可以改变子元素#dominio-principal:

#dominio-principal {
/*
padding-left: 10%;
padding-right: 61%;
*/
font-size: 18px;
}

关于html - 导航栏中 "Menu"按钮的响应问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71903586/

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