- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我查看了此处的所有支持,并尝试了许多不同的方法将此 CSS 下拉菜单拆分为 2 列,因为我有许多条目将导航列表向下延伸到折叠下方。
即使菜单是响应式的,我只需要两列在展开时工作,而不是在移动浏览时收缩(这方面很好)。我也在使用 jQuery 脚本。
我还没有成功地对我的代码进行任何调整。有人对我如何将此下拉列表拆分为 2 个并排的列有任何建议吗?
这是 HTML:
<div id='cssmenu' class='align-center'>
<ul>
<li><a href='index.html'>Home</a></li>
<li class='has-sub'><a href='equipment.html'>Equipment</a>
<ul>
<li><a href='#'>Automotive</a></li>
<li><a href='#'>Building Equip.</a></li>
<li><a href='#'>Concrete Tools</a></li>
<li><a href='#'>Drills</a></li>
<li><a href='#'>Generators</a></li>
<li><a href='#'>Heaters</a></li>
<li><a href='#'>Household Equip.</a></li>
<li><a href='#'>Ladders</a></li>
<li><a href='#'>Painting</a></li>
<li><a href='#'>Party / Canopy</a></li>
<li><a href='#'>Plumbing</a></li>
<li><a href='#'>Pumps</a></li>
<li><a href='#'>Sanders</a></li>
<li><a href='#'>Saws</a></li>
<li><a href='#'>Stage</a></li>
<li><a href='#'>Table & Chairs</a></li>
<li><a href='#'>Trailers</a></li>
<li><a href='#'>Trenchers</a></li>
<li><a href='#'>Garden & Lawn Care</a></li>
<li><a href='#'>Miscellaneous</a></li>
</ul>
</li>
<li><a href='concrete.html'>Concrete</a></li>
<li><a href='gravel.html'>Gravel</a></li>
<li><a href='propane.html'>Propane</a></li>
</ul>
</div>
这是 CSS:
@import url(http://fonts.googleapis.com/css?family=Open+Sans:400,700);
#cssmenu,
#cssmenu ul,
#cssmenu ul li,
#cssmenu ul li a,
#cssmenu #menu-button {
margin: 0;
padding: 0;
border: 0;
list-style: none;
line-height: 1;
display: block;
position: relative;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
#cssmenu:after,
#cssmenu > ul:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
#cssmenu #menu-button {
display: none;
}
#cssmenu {
z-index: 100;
width: auto;
font-family: 'Open Sans', Helvetica, sans-serif;
background: #468cc6;
background: -moz-linear-gradient(top, #5d9bcd 0%, #3677ae 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #5d9bcd), color-stop(100%, #3677ae));
background: -webkit-linear-gradient(top, #5d9bcd 0%, #3677ae 100%);
background: -o-linear-gradient(top, #5d9bcd 0%, #3677ae 100%);
background: -ms-linear-gradient(top, #5d9bcd 0%, #3677ae 100%);
background: linear-gradient(to bottom, #5d9bcd 0%, #3677ae 100%);
}
#cssmenu > ul {
background: url('images/bg.png');
box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.05);
}
#cssmenu.align-right > ul > li {
float: right;
}
#cssmenu > ul > li {
float: left;
display: inline-block;
}
#cssmenu.align-center > ul {
float: none;
text-align: center;
font-size: 0;
}
#cssmenu.align-center > ul > li {
float: none;
}
#cssmenu.align-center ul ul {
text-align: left;
}
#cssmenu > ul > li > a {
padding: 18px 25px 21px 25px;
border-right: 1px solid rgba(80, 80, 80, 0.12);
text-decoration: none;
font-size: 14px;
font-weight: 700;
color: #FFFFFF;
text-transform: uppercase;
letter-spacing: 1px;
}
#cssmenu > ul > li:hover > a,
#cssmenu > ul > li > a:hover,
#cssmenu > ul > li.active > a {
color: #ffffff;
background: #3c85c1;
background: rgba(0, 0, 0, 0.1);
}
#cssmenu > ul > li.has-sub > a {
padding-right: 45px;
}
#cssmenu > ul > li.has-sub > a::after {
content: "";
position: absolute;
width: 0;
height: 0;
border: 6px solid transparent;
border-top-color: #c7def0;
right: 17px;
top: 22.5px;
}
#cssmenu > ul > li.has-sub.active > a::after,
#cssmenu > ul > li.has-sub:hover > a {
border-top-color: #ffffff;
}
#cssmenu ul ul {
position: absolute;
left: -9999px;
top: 60px;
z-index: 9999;
padding-top: 6px;
font-size: 14px;
opacity: 0;
-webkit-transition: top 0.2s ease, opacity 0.2s ease-in;
-moz-transition: top 0.2s ease, opacity 0.2s ease-in;
-ms-transition: top 0.2s ease, opacity 0.2s ease-in;
-o-transition: top 0.2s ease, opacity 0.2s ease-in;
transition: top 0.2s ease, opacity 0.2s ease-in;
}
#cssmenu.align-right ul ul {
text-align: right;
}
#cssmenu > ul > li > ul::after {
content: "";
position: absolute;
width: 0;
height: 0;
border: 5px solid transparent;
border-bottom-color: #468cc6;
top: -4px;
left: 20px;
}
#cssmenu.align-right > ul > li > ul::after {
left: auto;
right: 20px;
}
#cssmenu ul ul ul::after {
content: "";
position: absolute;
width: 0;
height: 0;
border: 5px solid transparent;
border-right-color: #468cc6;
top: 11px;
left: -4px;
}
#cssmenu.align-right ul ul ul::after {
border-right-color: transparent;
border-left-color: #468cc6;
left: auto;
right: -4px;
}
#cssmenu > ul > li > ul {
top: 120px;
}
#cssmenu > ul > li:hover > ul {
top: 53px;
left: 0;
opacity: 1;
}
#cssmenu.align-right > ul > li:hover > ul {
left: auto;
right: 0;
}
#cssmenu ul ul ul {
padding-top: 0;
padding-left: 6px;
}
#cssmenu.align-right ul ul ul {
padding-right: 6px;
}
#cssmenu ul ul > li:hover > ul {
left: 180px;
top: 0;
opacity: 1;
}
#cssmenu.align-right ul ul > li:hover > ul {
left: auto;
right: 100%;
opacity: 1;
}
#cssmenu ul ul li a {
text-decoration: none;
font-weight: 400;
padding: 11px 25px;
width: 180px;
color: #ffffff;
background: #468cc6;
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.1), 1px 1px 1px rgba(0, 0, 0, 0.1), -1px 1px 1px rgba(0, 0, 0, 0.1);
}
#cssmenu ul ul li:hover > a,
#cssmenu ul ul li.active > a {
color: #333333;
}
#cssmenu ul ul li:first-child > a {
border-top-left-radius: 3px;
border-top-right-radius: 3px;
}
#cssmenu ul ul li:last-child > a {
border-bottom-left-radius: 3px;
border-bottom-right-radius: 3px;
}
#cssmenu > ul > li > ul::after {
position: absolute;
display: block;
}
#cssmenu ul ul li.has-sub > a::after {
content: "";
position: absolute;
width: 0;
height: 0;
border: 4px solid transparent;
border-left-color: #ffffff;
right: 17px;
top: 14px;
top: 14.5px;
}
#cssmenu.align-right ul ul li.has-sub > a::after {
border-left-color: transparent;
border-right-color: #ffffff;
right: auto;
left: 17px;
}
#cssmenu ul ul li.has-sub.active > a::after,
#cssmenu ul ul li.has-sub:hover > a::after {
border-left-color: #333333;
}
#cssmenu.align-right ul ul li.has-sub.active > a::after,
#cssmenu.align-right ul ul li.has-sub:hover > a::after {
border-right-color: #333333;
border-left-color: transparent;
}
@media all and (max-width: 725px), only screen and (-webkit-min-device-pixel-ratio: 2) and (max-width: 1024px), only screen and (min--moz-device-pixel-ratio: 2) and (max-width: 1024px), only screen and (-o-min-device-pixel-ratio: 2/1) and (max-width: 1024px), only screen and (min-device-pixel-ratio: 2) and (max-width: 1024px), only screen and (min-resolution: 192dpi) and (max-width: 1024px), only screen and (min-resolution: 2dppx) and (max-width: 1024px) {
#cssmenu {
background: #468cc6;
}
#cssmenu > ul {
display: none;
}
#cssmenu > ul.open {
display: block;
border-top: 1px solid rgba(0, 0, 0, 0.1);
}
#cssmenu.align-right > ul {
float: none;
}
#cssmenu.align-center > ul {
text-align: left;
}
#cssmenu > ul > li,
#cssmenu.align-right > ul > li {
float: none;
display: block;
}
#cssmenu > ul > li > a {
padding: 18px 25px 18px 25px;
border-right: 0;
}
#cssmenu > ul > li:hover > a,
#cssmenu > ul > li.active > a {
background: rgba(0, 0, 0, 0.1);
}
#cssmenu #menu-button {
display: block;
text-decoration: none;
font-size: 13px;
font-weight: 700;
color: #FFFFFF;
padding: 18px 25px 18px 25px;
text-transform: uppercase;
letter-spacing: 1px;
background: url('images/bg.png');
cursor: pointer;
}
#cssmenu ul ul,
#cssmenu ul li:hover > ul,
#cssmenu > ul > li > ul,
#cssmenu ul ul ul,
#cssmenu ul ul li:hover > ul,
#cssmenu.align-right ul ul,
#cssmenu.align-right ul li:hover > ul,
#cssmenu.align-right > ul > li > ul,
#cssmenu.align-right ul ul ul,
#cssmenu.align-right ul ul li:hover > ul {
left: 0;
right: auto;
top: auto;
opacity: 1;
width: 100%;
padding: 0;
position: relative;
text-align: left;
}
#cssmenu ul ul li {
width: 100%;
}
#cssmenu ul ul li a {
width: 100%;
box-shadow: none;
padding-left: 35px;
}
#cssmenu ul ul ul li a {
padding-left: 45px;
}
#cssmenu ul ul li:first-child > a,
#cssmenu ul ul li:last-child > a {
border-radius: 0;
}
#cssmenu #menu-button::after {
display: block;
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
box-sizing: content-box;
content: '';
position: absolute;
height: 3px;
width: 22px;
border-top: 2px solid #c7def0;
border-bottom: 2px solid #c7def0;
right: 25px;
top: 18px;
}
#cssmenu #menu-button::before {
display: block;
content: '';
position: absolute;
height: 3px;
width: 22px;
border-top: 2px solid #c7def0;
right: 25px;
top: 28px;
}
#cssmenu > ul > li.has-sub > a::after,
#cssmenu ul ul li.has-sub > a::after {
display: none;
}
}
这是 jQuery:
(function($){
$(document).ready(function(){
$('#cssmenu').prepend('<div id="menu-button">Menu</div>');
$('#cssmenu #menu-button').on('click', function(){
var menu = $(this).next('ul');
if (menu.hasClass('open')) {
menu.removeClass('open');
} else {
menu.addClass('open');
}
});
});
})(jQuery);
最佳答案
这是 HTML:
$(function() {
if ($(window).width() <= 768) {
$('.sub-menu').hide();
$('.has-ancho > a').on('click', function() {
$(this).parent('.has-ancho').toggleClass('open').find('i:eq(0)').toggleClass('fa-rotate-180');
if (!$(this).parent('.has-ancho').hasClass('open')) {
$(this).parent('.has-ancho').find('.has-ancho').removeClass('open');
}
});
} else {
$('.sub-menu').show();
}
});
.menu-arrow,
.menu-heading {
display: none;
}
.sub-menu {
margin: 0px;
padding: 0px;
list-style: none;
}
.sub-menu li {
display: inline-block;
padding: 5px 10px;
}
.ancho {
list-style: none;
margin: 0px;
padding: 0px;
text-align: center;
}
@media only screen and (max-width: 768px) {
.sub-menu li {
display: block;
padding: 0px;
}
.ancho {
list-style: none;
margin: 0;
padding: 0;
text-align: left;
}
.menu-arrow,
.menu-heading {
display: block;
}
.ancho a {
display: block;
padding: 10px 15px;
background-color: #e5e5e5;
text-decoration: none;
cursor: pointer;
transition: all 0.2s ease;
margin: 3px 0;
border-radius: 5px;
}
.ancho a i {
float: right;
}
.ancho a:hover {
background-color: #C5C3C3;
}
.ancho .has-ancho > ul {
margin: 0;
padding: 0;
list-style: none;
}
.ancho .has-ancho.open > .sub-menu {
display: block !important;
}
.ancho .has-ancho.open > a {
background-color: #B7B7B7;
color: #FFF;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="container">
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
<ul class="ancho">
<li class="has-ancho">
<a href="#" class="menu-heading">menu <i class="fa fa-angle-down menu-arrow"></i></a>
<ul class="sub-menu">
<li><a href="#">Home 1</a>
</li>
<li><a href="#">Home 2</a>
</li>
<li><a href="#">Home 3</a>
</li>
<li><a href="#">Home 4</a>
</li>
<li><a href="#">Home 5</a>
</li>
<li><a href="#">Home 6</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
关于jquery - CSS 响应式下拉菜单 - 分成两列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31348061/
我刚刚更新了 Ruby,现在我在尝试启动 compass 时遇到以下错误: Encoding::CompatibilityError on line ["28"] of /usr/local/Cell
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 6 年前。
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我正在尝试在我的 iOS 应用程序中开发可折叠/ Accordion 式的功能。这将是您可以在网站上找到的典型 FAQ 类型功能。我想点击标题,然后显示详细信息。 因为这是帮助部分,只有几个项目,我认
我正在尝试设计一个基于 REST 的 Web 服务来与我正在开发的农场动物管理系统进行交互。 为了详细说明问题,我收藏了动物 属于一个农场。每只动物都有自己的信息——例如姓名、身份证号、品种年龄等。因
我有 3 种不同的表单,其中复选框数量不同,每个部分基本上代表一个表单,因此当用户选择该部分中的复选框时,它会显示他们在该部分的总金额中 checkout 了多少 HTML
我有一份 32 页的 PDF 版家谱。与其将家谱全部放在一个非常大的 PDF 页面上(这是我想要的),不如将其格式化为一组 8 个单独的美国信纸大小的页面应该在整个宽度上缝合; 4 行这样就完成了树。
指SASS implementation for Java? : 在 Maven 目标编译包中自动编译 compass-style.org 样式表的最佳方法是什么? 我不想发送太多的自编译库,也不想通
鉴于以下 XAML... 我正在寻找一种绑定(bind) ComboBox、Button 和 Command 的方法,以便当 ComboBox 的值更改时,在 Command 上调用 CanExe
在玩具应用程序中,我有一个显示所有帖子标题的“帖子”模板。当您单击每个标题时,我不想直接进入“显示” View ,而是直接内联展开该帖子的其余内容。 我考虑过让 postRoute 重用 postsR
我需要一些使用 Twitter Bootstrap 或其他响应式框架的自定义 Swagger-UI 实现。需要在我的移动设备上使用这样的 UI 测试我的 API,但 swagger-ui 不能很好地扩
我正在做一个项目,我真的在尝试编写面向对象的 JavaScript 代码。我刚刚开始阅读Douglas Crockford's JavaScript: The Good Parts我很快开始意识到用
在 C# 中,我通过执行以下操作来加密文本数据(请注意我正在以 block ( block )的形式加密数据): public string EncryptData(string pu
我正在构建一个社交网站,该网站将向全世界公开 REST API (WCF WebAPI),以便任何开发人员都能够为该网站创建客户端应用程序、将其与其他服务集成等。 我想为 API 实现 Faceboo
我是一名优秀的程序员,十分优秀!