我正在尝试制作菜单。问题是,当我尝试将屏幕缩小到600width
以下时,菜单会因为响应性而消失。我希望菜单项像文本一样转到下一行。
我该如何实现这种行为?
<section class="panel">
<div class="panel-body" style="margin-top: -20px; min-width: 550px;">
<div style="margin:0 auto;width: 550px;">
<ul id="main-menu">
<li <?php echo $menuItem=='dashboard' ? 'class="current-menu-item"' : 'parent'?>><a href="index.php">Home</a></li>
<li <?php echo $menuItem=='submitForm' ? 'class="current-menu-item"' : 'parent'?>><a href="submissionForm.php">Submit Sale</a></li>
<li <?php echo $menuItem=='sales' ? 'class="current-menu-item"' : 'parent'?>><a href="saleslist.php">My Sales</a></li>
<li <?php echo $menuItem=='help' ? 'class="current-menu-item"' : 'parent'?>><a href="help.php">Help</a></li>
<li <?php echo $menuItem=='intro' ? 'class="current-menu-item"' : 'parent'?>><a href="intro.php?mode=view">Incentive Program Code</a></li>
</ul>
</div>
</div>
</section>
我的CSS文件
@import url(http://fonts.googleapis.com/css?family=Open+Sans);
body {
background-color: #eee;
background-image: url(../images/patterns/light_toast.png);
color: #666;
font-family: 'Open Sans', sans-serif;
font-size: 12px;
margin:0px;
padding:0px;
}
a {
color: #23dbdb;
text-decoration: none;
}
a:hover {
color: #000;
}
ol, ul {
list-style: none;
padding:0px;
margin:0px;
}
#wrap {
margin: 0 auto;
}
.inner {
margin: 0 auto;
max-width: 940px;
padding: 0 40px;
}
.relative {
position: relative;
}
.right {
float: right;
}
.left {
float: left;
}
/* HEADER */
#wrap > header {
background-color: #333;
padding-bottom: 20px;
}
.logo {
display: inline-block;
font-size: 0;
padding-top:15px;
}
#navigation {
position: absolute;
right: 40px;
bottom: 0px;
}
#menu-toggle {
display: none;
float: right;
}
/* HEADER > MENU */
#main-menu {
float: left;
font-size: 0;
margin: 10px 0;
}
#main-menu > li {
display: inline-block;
margin-left: 30px;
padding: 2px 0;
}
#main-menu > li.parent {
background-image: url(../images/plus-gray.png);
background-size: 7px 7px;
background-repeat: no-repeat;
background-position: left center;
}
#main-menu > li.parent > a {
padding-left: 14px;
}
#main-menu > li > a {
color: #666;
font-size: 13px;
line-height: 14px;
padding: 30px 0;
text-decoration:none;
}
#main-menu > li:hover > a,
#main-menu > li.current-menu-item > a {
color: #23dbdb;
}
/* HEADER > MENU > DROPDOWN */
#main-menu li {
position: relative;
}
ul.sub-menu { /* level 2 */
display: none;
left: 0px;
top: 38px;
padding-top: 10px;
position: absolute;
width: 150px;
z-index: 9999;
}
ul.sub-menu ul.sub-menu { /* level 3+ */
margin-top: -1px;
padding-top: 0;
left: 149px;
top: 0px;
}
ul.sub-menu > li > a {
background-color: #333;
border: 1px solid #444;
border-top: none;
color: #bbb;
display: block;
font-size: 12px;
line-height: 15px;
padding: 10px 12px;
}
ul.sub-menu > li > a:hover {
background-color: #2a2a2a;
color: #fff;
}
ul.sub-menu > li:first-child {
border-top: 3px solid #23dbdb;
}
ul.sub-menu ul.sub-menu > li:first-child {
border-top: 1px solid #444;
}
ul.sub-menu > li:last-child > a {
border-radius: 0 0 2px 2px;
}
ul.sub-menu > li > a.parent {
background-image: url(../images/arrow.png);
background-size: 5px 9px;
background-repeat: no-repeat;
background-position: 95% center;
}
#main-menu li:hover > ul.sub-menu {
display: block; /* show the submenu */
}
@media all and (max-width: 700px) {
#navigation {
position: static;
margin-top: 20px;
}
#menu-toggle {
display: block;
}
#main-menu {
display: none;
float: none;
}
#main-menu li {
display: block;
margin: 0;
padding: 0;
}
#main-menu > li {
margin-top: -1px;
}
#main-menu > li:first-child {
margin-top: 0;
}
#main-menu > li > a {
background-color: #333;
border: 1px solid #444;
color: #bbb;
display: block;
font-size: 14px;
padding: 12px !important;
padding: 0;
}
#main-menu li > a:hover {
background-color: #444;
}
#main-menu > li.parent {
background: none !important;
padding: 0;
}
#main-menu > li:hover > a,
#main-menu > li.current-menu-item > a {
border: 1px solid #444 !important;
color: #fff !important;
}
ul.sub-menu {
display: block;
margin-top: -1px;
margin-left: 20px;
position: static;
padding: 0;
width: inherit;
}
ul.sub-menu > li:first-child {
border-top: 1px solid #444 !important;
}
ul.sub-menu > li > a.parent {
background: #333 !important;
}
}
答案 0 :(得分:1)
您隐藏导航为700px(不是600px,如您的问题中所述)。如果您不希望隐藏它,请从媒体查询中删除此CSS:
@media all and (max-width: 700px) {
...
#main-menu {
display: none;
float: none;
}
...
}
如果您希望li
流向下一行(即不堆栈),请从同一媒体查询块中删除以下内容:
@media all and (max-width: 700px) {
...
#main-menu li {
display: block; <-- remove this
margin: 0;
padding: 0;
}
...
}
答案 1 :(得分:0)
@media all和(max-width:700px){
#main-menu {
display: none;
/* Display : none; This Property Hide this section when it goes less than 700px*/
}
}
在不同的样式表(i,e responsive.css)中编写您的响应式CSS。然后记下不同设备大小的css。
@media(min-width:480px)和(max-width:767px){
}
@media(min-width:959px)和(max-width:1024px){
}
@media(min-width:980px)和(max-width:1170px){
}