gpt4 book ai didi

html - 响应式下拉菜单?

转载 作者:行者123 更新时间:2023-11-28 00:07:18 25 4
gpt4 key购买 nike

我需要一个响应式下拉菜单,我已经浏览了教程等。但是所有内容都涉及我还不能使用的 javascript。菜单最好使用汉堡包。我一直在尝试并设法在没有汉堡包的情况下做到这一点,但它看起来很糟糕,而且内容也很丰富。

我附上了没有响应式菜单的代码。请仅使用 CSS 提供任何帮助,我们将不胜感激。

<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width",initial-scale=1.0>

<title>MardiDrama Club</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>
<div class = "nav">
<ul>
<li><a href="events.html">Events</a></li>
<li><a href="classes.html">Classes</a>
<ul>
<div class="links"><li><a href="musical_theatre.html">Musical Theatre</a></li>
<li><a href="after_school.html">After School</a></li>
<li><a href="holiday_programmes.html">Holiday Programmes</a>
</div></ul>

<li><a href="where.html">Where</a></li>
<li><a href="about.html">About</a></li>
<li><a href="register.html">Register</a></li>
<li><a href="blog.html">Blog</a></li>
</li>
<li><a href="index.html">HomePage</a></li>
</li>

</ul>

<div class="logo"><a href="index.html"><img src="assets/images/maridrama_logo.png" class="centre"></a></div>

</div>
@media only screen and (max-width: 600px) {
body article{
background-color: white;
}

html{
height: 100%;
}
}
body{
background-color: white;
margin-right: auto;
margin-left: auto;
margin-top: 0;
margin-bottom: 0;
padding: 0;
margin: 0 auto;
font-family: "Century Gothic";
}


.nav{
width: 100%;
height: 70vh;
background:linear-gradient(rgba(0,0,0,0.5),rgba(0,0,0,0.5)), url(assets/images/kilyan-sockalingum-478724-unsplash.jpg);
background-size: cover;
background-position: center;
}

ul{

list-style-type: none;
margin: 0 auto;
}

ul li{
float: right;
width: 160px;
font-size: 15px;
line-height: 80px;
text-align: center;
}
.links{
float: right;
width: 160px;
font-size: 15px;
line-height: 80px;
text-align: center;

}

ul li a{
text-decoration: none;
color: #fff;
display: block;
width: 160px;
}

ul li a:hover{
background-color: #96C7ED;
transition: 1s all ease;
}

ul li ul li{

display: none;
width: 100%;
font-size: 13px;
transition: 1s all;
}

ul li:hover ul li{
display: block;
}

div.logo {
position: absolute;
top: 0;
left: 0;
background : url(assets/images/LogoMakr_59ebir.png) no-repeat 0 0;

}

最佳答案

我们为此提供了手动选项。正如我在评论中提到的,Bootstrap 默认为您提供此功能。同样,任何其他框架(如 Zurb foundation 或 UI kit)也为您提供响应式导航功能。对于纯 HTML/CSS,您可以将此模板用于响应式导航栏:

body {
margin: 25px;
-webkit-animation: bugfix infinite 1s;
/* needed for checkbox hack */
background: #021320;
}

@-webkit-keyframes bugfix {
from {
padding: 0;
}
to {
padding: 0;
}
}
/* needed for checkbox hack */
h1, p {
color: white;
}

#nav {
position: relative;
}
#nav ul {
display: none;
width: 100%;
list-style: none;
margin: 0px;
padding: 0px;
}
#nav ul li a {
display: block;
padding: 1em;
background: #0F9962;
color: white;
text-decoration: none;
border-right: 1px solid #0a6b44;
}
#nav ul li a:hover {
background: #0d8253;
}
#nav ul li:last-of-type a {
border-right: 0px;
}
#nav ul li ul li a {
padding-left: 1.5em;
}
#nav ul li ul li ul li a {
padding-left: 3.125em;
}
#nav input.trigger {
position: absolute;
top: -9999px;
left: -9999px;
}
#nav input.trigger:checked ~ ul, #nav input.trigger:checked ~ ul li ul {
display: block !important;
}
@media (min-width: 48em) {
#nav input.trigger:checked ~ ul, #nav input.trigger:checked ~ ul li ul {
/* older flexbox */
display: -webkit-box;
display: -moz-box;
display: box;
-webkit-box-orient: horizontal;
-moz-box-orient: horizontal;
box-orient: horizontal;
/* newer flexbox */
display: flex;
flex-direction: row;
}
}
#nav label {
position: relative;
display: block;
min-height: 2em;
padding: .45em;
font-size: 1.1em;
margin: 0;
cursor: pointer;
background: #005292;
line-height: 2em;
color: #bfe1fb;
}
#nav label:after {
position: absolute;
right: 1em;
top: .2em;
content: "\2261";
font-size: 1.8em;
color: white;
}
@media (min-width: 48em) {
#nav ul {
/* older flexbox */
display: -ms-flexbox;
flex-direction: -ms-row;
display: -webkit-box;
display: -moz-box;
display: box;
-webkit-box-orient: horizontal;
-moz-box-orient: horizontal;
box-orient: horizontal;
/* newer flexbox */
display: flex;
flex-direction: row;
}
#nav ul li {
position: relative;
text-align: center;
/* older flexbox */
-ms-flex: 1;
-webkit-box-flex: 1;
-moz-box-flex: 1;
box-flex: 1;
/* newer flexbox */
flex: 1;
}
#nav ul li ul {
display: none !important;
position: absolute;
top: 3.0625em;
left: 0;
display: block;
width: 12.5em;
z-index: 200;
}
#nav ul li ul li {
text-align: left;
}
#nav ul li ul li ul {
z-index: 300;
top: 0px;
left: 12.4em;
}
#nav ul li ul li ul li a {
padding-left: 30px !important;
}
#nav ul li:hover > ul {
display: block !important;
}
#nav label {
display: none;
}
}
<nav role="navigation" id="nav">
<input class="trigger" type="checkbox" id="mainNavButton">
<label for="mainNavButton" onclick>Menu</label>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About Us</a>
<ul>
<li><a href="#">Sub Nav Item</a></li>
<li><a href="#">Sub Nav Item</a>
<ul>
<li><a href="#">Sub Sub Nav Item</a></li>
<li><a href="#">Sub Sub Nav Item</a></li>
<li><a href="#">Sub Sub Nav Item</a></li>
<li><a href="#">Sub Sub Nav Item</a></li>
</ul>
</li>
<li><a href="#">Sub Nav Item</a></li>
<li><a href="#">Sub Nav Item</a></li>
</ul>
</li>
<li><a href="#">Products</a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">Specials</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</ul>
</nav>

其他方法在这个链接里给出,也是我的答案码的出处:https://1stwebdesigner.com/code-snippets-responsive-navigation-menu/

关于html - 响应式下拉菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55628275/

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