gpt4 book ai didi

html - 响应式导航菜单

转载 作者:太空宇宙 更新时间:2023-11-04 13:37:26 25 4
gpt4 key购买 nike

我正在尝试开发一个响应式菜单。没有响应时,菜单应如下所示: enter image description here

当平板电脑/手机的屏幕缩小时,就像下面这样:

enter image description here

你可以在这里找到一个 fiddle :http://jsfiddle.net/yxMhj/

HTML 代码:

<div id='cssmenu'>

<div class="logo">
<img src="images/logo.png" />
</div>

<ul>
<li class='active'><a href='index.html'>Home</a></li>
<li class='has-sub '><a href='#'>Products</a>
<ul>
<li class='has-sub '><a href='#'>Product 1</a>
<ul>
<li><a href='#'>Sub Item</a></li>
<li><a href='#'>Sub Item</a></li>
</ul>
</li>
<li class='has-sub '><a href='#'>Product 2</a>
<ul>
<li><a href='#'>Sub Item</a></li>
<li><a href='#'>Sub Item</a></li>
</ul>
</li>
</ul>
</li>
<li><a href='#'>About</a></li>
<li><a href='#'>Contact</a></li>
</ul>
</div>

CSS 代码:

@import url(http://fonts.googleapis.com/css?family=Oxygen+Mono);

#cssmenu {padding: 0; margin: 0; border: 0;}
#cssmenu ul, #cssmenu li {list-style: none; margin: 0; padding: 0;}
#cssmenu ul {position: relative; z-index: 597; }
#cssmenu ul li { float: left; min-height: 1px; vertical-align: middle;}
#cssmenu ul li.hover,
#cssmenu ul li:hover {position: relative; z-index: 599; cursor: default;}
#cssmenu ul ul {visibility: hidden; position: absolute; top: 100%; left: 0; z-index: 598;}
#cssmenu ul ul li {float: none;}
#cssmenu ul ul ul {top: 0; left: auto; right: -99.5%; }
#cssmenu ul li:hover > ul { visibility: visible;}
#cssmenu ul ul {bottom: 0; left: 0;}
#cssmenu ul ul {margin-top: 0; }
#cssmenu ul ul li {font-weight: normal;}
#cssmenu a { display: block; line-height: 1em; text-decoration: none; }

#cssmenu {
background: #333;
border-bottom: 4px solid #1b9bff;
font-family: 'Oxygen Mono', Tahoma, Arial, sans-serif;
font-size: 16px;
}

#cssmenu > ul { *display: inline-block; }

#cssmenu:after, #cssmenu ul:after {
content: '';
display: block;
clear: both;
}

#cssmenu a {
background: #333;
color: #CBCBCB;
padding: 0 20px;
}
#cssmenu ul { text-transform: uppercase; }

#cssmenu ul ul {
border-top: 4px solid #1b9bff;
text-transform: none;
min-width: 190px;
}
#cssmenu ul ul a {
background: #1b9bff;
color: #FFF;
border: 1px solid #0082e7;
border-top: 0 none;
line-height: 150%;
padding: 16px 20px;
}
#cssmenu ul ul ul { border-top: 0 none; }

#cssmenu ul ul li { position: relative }

#cssmenu > ul > li > a { line-height: 80px; }

#cssmenu ul ul li:first-child > a { border-top: 1px solid #0082e7; }
#cssmenu ul ul li:hover > a { background: #35a6ff; }

#cssmenu ul ul li:last-child > a {
border-radius: 0 0 3px 3px;
box-shadow: 0 1px 0 #1b9bff;
}
#cssmenu ul ul li:last-child:hover > a { border-radius: 0 0 0 3px; }

#cssmenu ul ul li.has-sub > a:after {
content: '+';
position: absolute;
top: 50%;
right: 15px;
margin-top: -8px;
}

#cssmenu ul li:hover > a, #cssmenu ul li.active > a {
background: #1b9bff;
color: #FFF;
}
#cssmenu ul li.has-sub > a:after {
content: '+';
margin-left: 5px;
}
#cssmenu ul li.last ul {
left: auto;
right: 0;
}
#cssmenu ul li.last ul ul {
left: auto;
right: 99.5%;
}
.logo{
margin-top:0px;
float:left;
margin-left:20%;
padding-right:10px;
}

非常感谢你们的帮助!

最佳答案

试试这个

<style>
.menu {
border: 0;
margin: 0 0 10px 0;
padding: 0;
width: 100%;
}

.menu ul {
display: table;
list-style: none;
margin: 0;
padding: 0;
width: 100%;
}

.menu li {
display: table-cell;
background-color: #eee;
}

.menu li:hover {
background-color: #ccc;
}

.menu a {
display: block;
padding: 10px 0;
width: 100%;
}

.menu li, .menu a {
text-align: center;
}

@Media screen and (max-width:480px) {
div.menu li {
display: block !important;
width: 100% !important;
}
}
</style>
<div class="menu">
<ul>
<li>Your logo here</li>
<li><a href="#">Home</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">Company</a></li>
<li><a href="#">Blog</a></li>
</ul>
</div>

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

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