【问题标题】:Have an issue with the designed menu设计的菜单有问题
【发布时间】:2015-07-13 10:30:44
【问题描述】:

我有以下可以正常工作的菜单。我所需要的是,一旦选择或悬停一个项目,它的整个部分就会在所有尺寸的屏幕中突出显示。目前,每个项目的仅部分部分被突出显示。

代码

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

<link rel="stylesheet"
    href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link rel="stylesheet"
    href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">

<link rel="stylesheet"
    href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<link rel="stylesheet"
    href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-social/4.2.1/bootstrap-social.css">



<style>

.container-menu {
    width: 100%;
    background: none repeat scroll 0 0 rgb(0,0,0);
    min-height: 63px;
}

.menu-items {
    max-width: 1130px;
    width: 100%;
    height: 100%;
    margin: 0 auto; //
    text-align: center;
    text-align: left;
    position: relative;
    padding-top: 36px;
    text-align: center;
}

.menu-items li {
    background-color: rgb(0,0,0);
}

.menu-items #home {
    background-color: green;
}
.menu-items {
    position: relative;
}

.menu-items a {
    color: #fff;
}

.menu-items ul {
    padding: 0;
    list-style: none;
    margin: 0;
}

.menu-items li {
    display: inline;
    border-left: 1px solid #fff;
}

.menu-items li:last-child {
    border-right: 1px solid #fff;
}

.burger {
    width: 25px;
    height: 25px;
    position: absolute;
    top: 7px;
    right: 7px;
    display: none;
}

.menu-items li:hover {
    background-color: green;
}

@media only screen and (max-width: 720px) {
    .burger {
        display: block;
    }
    .menu-items ul {
        display: none;
    }
    .menu-items li {
        display: block;
        border: 0;
    }
    .container-menu>img {
        display: none;
    }
}


@media ( min-width :1500px) {
    .menu-items li {
        padding: 8px 38px;
    }
}

@media ( min-width : 979px) and (max-width:1500px) {
    .menu-items li {
        border-left: 1px solid #fff;
        display: inline;
        padding: 8px 15px;
    }
}

@media ( min-width : 768px) and (max-width: 979px) {

    .menu-items li {
        border-left: 1px solid #fff;
        display: inline;
        padding: 8px 15px;
    }
    .item {
        height: 186px !important;
    }

}

@media ( max-width : 767px) {

    .container-menu {
        min-height: 63px;
    }
    .menu-items li {
        border-left: 1px solid #fff;
        padding: 8px 12px;
    }

}

@media ( max-width : 480px) {
    .container-menu {
        min-height: 48px;
    }
    .menu-top-center {
        width: 100%;
    }
    .menu-top-right {
        padding-bottom: 4px;
    }
}
</style>
</head>


<body>


<header>
    <div class="container-menu">
        <div class="menu-items">
            <ul id="">
                <li id="home"><a href="#"><i class="fa fa-home f24"></i>
                        Home</a></li>
                <li id="item1"><a href="#">Item 1</a></li>
                <li id="item2"><a href="#">Item 2</a></li>
                <li id="mitem3"><a href="#">Item 3</a></li>
                <li id="item4"><a href="#">Item 4</a></li>
                <li id="item5"><a href="#">Item 5</a></li>
                <li id="item6"><a href="#">Item 6</a></li>
                <li id="item7"><a href="#">Item 7</a></li>
            </ul>
            <div class="burger hidden-md">
                <i class="fa fa-align-justify fa-2x"></i>
            </div>
        </div>
    </div>
</header>

    <script
        src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script
        src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script>
$(document).ready(function() {
            $('.burger').click(function() {
                $('.menu-items ul').toggleClass("visible");
            });
        });
</script>
</body>


</html>

【问题讨论】:

  • 没有任何解释的反对票是可怕的你知道吗? :D
  • 您的输出没有显示&lt;a&gt;标签的内容,即(项目1.项目2等)
  • @Dimple 那是我使用 jsfiddle 的问题,结果窗口的左上角有一个“结果”图标,与我的按钮重叠。
  • @MatthewRath 我正在试验。这不是实际设计。
  • 我想知道这些反对票是为了什么?

标签: html twitter-bootstrap css twitter-bootstrap-3


【解决方案1】:

我根据您的图片完全重新设计了新的导航栏。请看一下。

  • 100% 响应
  • 在大屏幕上工作正常
  • 在移动视图中,我禁用了导航栏的折叠功能,因此在较小的设备中设计将相同

body {
  line-height: 0 !important;
}
.navbar-collapse.collapse {
  display: block!important;
}
.navbar-nav>li,
.navbar-nav {
  float: left !important;
}
.navbar-nav.navbar-right:last-child {
  margin-right: -15px !important;
}
.navbar-right {
  float: right!important;
}
.navbar > .container {
  text-align: center !important;
}
.navbar-header,
.navbar-brand,
.navbar .navbar-nav,
.navbar .navbar-nav > li {
  float: none !important;
  display: inline-block !important;
}
.collapse.navbar-collapse {
  float: none !important;
  display: inline-block!important;
  width: auto !important;
  clear: none !important;
}
.navbar {
  position: relative !important;
}
.back-stripe {
  /*display: none;*/
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 75px;
  z-index: 999999;
  background-image: url('http://i59.tinypic.com/2yvucqw.png');
  background-size: contain;
  background-repeat: no-repeat;
  pointer-events: none;
}
.navbar-default {
  background: #4C0084 !important;
}
.navbar-default .navbar-nav > li:first-child {
  border-left: 1px solid #FFA600;
}
.navbar-default .navbar-nav > li {
  box-sizing: border-box;
  border-right: 1px solid #FFA600;
}
.navbar-default .navbar-nav > li > a {
  color: #fff !important;
  font-weight: bold !important;
}
.navbar-default .navbar-nav > li > a.active {
  background: #FFA600 !important;
}
.navbar-default .navbar-nav > li > a:hover {
  background: #FFA600 !important;
  color: #fff !important;
}
.navbar-nav {
  margin: 0 !important;
}
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class="back-stripe"></div>
  <div class="container" style="padding-top: 3%;margin-top:-4px;">
    <div class="collapse navbar-collapse">
      <ul class="nav navbar-nav">
        <li><a href="#" class="active">Home</a>
        </li>
        <li><a href="#">Item2</a>
        </li>
        <li><a href="#">Item3</a>
        </li>
        <li><a href="#">Item4</a>
        </li>
        <li><a href="#">Item5</a>
        </li>
        <li><a href="#">Item6</a>
        </li>
        <li><a href="#">Item7</a>
        </li>
      </ul>
    </div>
  </div>
</div>

【讨论】:

  • 感谢您的回答,正如问题中解释的那样,我需要一个汉堡风格的菜单,如何将其添加到您的设计中。此外,所有菜单项都应该在您的设计中的一行中,最后一项进入第二行。
  • @Jack 汉堡式菜单有什么好玩的?
  • 所以你想在移动视图中显示?? @杰克
  • 是的,我的代码中有,请参考这部分 $('.burger').click(function()
【解决方案2】:

我可以通过添加以下代码来解决问题

.menu-items li{
   padding:16px 38px;
}

【讨论】:

    【解决方案3】:

    我想我解决了你的问题。尝试使用此代码

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-social/4.2.1/bootstrap-social.css">
    <style>
    body {
        margin-bottom: 60px;
    }
    html {
        position: relative;
        min-height: 100%;
    }
    body {
        margin: 0;
        padding: 0;
    }
    * {
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
    }
    .container-m-tp {
        width: 100%;
        background-color: orange;
    }
    .container-m-btn {
        width: 100%;
        background: none repeat scroll 0 0 rgb(75, 0, 130);
        min-height: 62px;
    }
    .container-m-btn>img {
        max-height: 40px;
        width: 100%;
        position: absolute;
        z-index: 99999;
    }
    .m-tp {
        max-width: 970px;
        max-width: 1237px;
        width: 100%;
        height: 100%;
        margin: 0 auto;
        text-align: center;
        position: relative;
    }
    .m-btn {
        max-width: 1900px;
        width: 100%;
        height: 100%;
        margin: 0 auto;
        text-align: center;
        text-align: left;
        position: relative;
        padding-top: 35px;
        text-align: center;
    }
    .m-btn li:hover {
        background-color: orange;
    }
    .m-tp-center {
        display: inline-block;
        //
        width: 50%;
        width: 80%;
        height: 100%;
    }
    .m-tp-right {
        display: inline-block;
        float: right;
        height: 100%;
        margin-right: 3%;
        //
        width: 200px;
        //
        padding-left: 20px;
    }
    .m-btn {
        position: relative;
    }
    .m-btn a {
        color: #fff;
    }
    .m-btn ul {
        padding: 0;
        list-style: none;
        margin: 0;
    }
    .m-btn li {
        display: inline;
        padding: 25px 32px 9px;
        border-left: 1px solid #fff;
    }
    .m-btn li:last-child {
        border-right: 1px solid #fff;
    }
    .burger {
        width: 25px;
        height: 25px;
        background-image: url(img/burger.png);
        position: absolute;
        top: 7px;
        right: 7px;
        display: none;
        color: #FFF;
    }
    @media only screen and (max-width:720px) {
        .burger {
            display: block;
        }
        .container-m-btn {
            min-height: 40px;
        }
        .m-btn ul {
            display: none;
            border-top: 1px #fff solid;
        }
        .m-btn li {
            display: block;
            border: none;
            padding: 16px 32px;
            border-bottom: 1px #fff solid;
        }
        .m-btn li:last-child {
            border-bottom: none;
        }
        .container-m-btn>img {
            display: none;
        }
    }
    .m-btn .visible {
        display: block;
    }
    .m-btn li:hover {
        background-color: orange;
    }
    .m-btn li:active {
        background-color: orange;
    }
    </style>
    </head>
    <body>
        <header>
            <div class="container-m-btn">
                <img src="http://i.stack.imgur.com/GRNPb.png" />
                <div class="m-btn">
                    <ul id="">
                        <li id="item1"><a href="#"><i class="fa fa-home f24"></i> Home</a></li>
                        <li id="item2"><a href="#">Item2</a></li>
                        <li id="item3"><a href="#">Item3</a></li>
                        <li id="item4"><a href="#">Item4</a></li>
                        <li id="item5"><a href="#">Item5</a></li>
                        <li id="item6"><a href="#">Item6</a></li>
                        <li id="item7"><a href="#">Item7</a></li>
                        <li id="item8"><a href="#">Item8</a></li>
                    </ul>
                    <div class="burger"></div>
                </div>
            </div>
        </header>
        <style>
            .m-btn #item7 {
                background-color: orange;
            }
        </style>
        <div class="container">
            <p>This is body</p>
        </div>
    </body>
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <script>
    $(document).ready(function() {
        $('.burger').click(function() {
            $('.m-btn ul').toggleClass("visible");
        });
    });
    </script>
    </html>
    

    【讨论】:

    • 感谢您的回答,但与其他答案相比,它没有任何额外内容。请查看问题中的屏幕截图。\
    【解决方案4】:

    如果我将顶部水平图像更改为弯曲的图像,菜单项的白色边框的高度将太短,我需要它们更高一点。 (不知道)

    //不清楚,你在找这个吗?

    //给@media li添加border-bottom,

    .menuitems li {
            display: block;
           border-left:0px;
            border-bottom:1px solid #fff;
        }
    

    在汉堡风格中,最后一项的宽度有点短。 (不知道为什么)

    // 将padding:0 添加到 UL 以删除第一个选项卡中的空白

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

    我需要使所有菜单项更宽一些。 (更改宽度不起作用)

     .menuitems li {
        display: inline-block;
        padding: 10px 15px 10px 35px;
        border-left: 1px solid #fff;
        width:80px;
    }
    

    【讨论】:

    • @Jack,编辑了我的答案,您是否也在寻找相同的答案?
    • 关于边框高度,我的意思是当屏幕为全尺寸时,您可以看到菜单上方的图像。我想要的是让菜单的高度高一点。这样,边界会更高。然后我会在距离菜单按钮仅 2px 的地方获得菜单项的文本。最后,图像应该与没有任何文本的菜单栏顶部重叠。
    • @Jack,你的 jsfiddle 中没有曲线图。您可以将高度添加到 UL 。如果你想让菜单高度高一点
    • 它确实解决了问题,将再试一次,谢谢。
    【解决方案5】:

    将这些行更新到您的样式中

    .m-btn ul {
      list-style: none;
      margin: 0;
      padding: 0;
    }
    

    它对我有用.....

    编辑

    或者试试这个

    @media only screen and (max-width: 480px) {
        .m-btn ul {
          padding: 0;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2010-12-28
      • 2014-08-27
      • 2015-07-05
      • 2010-11-09
      • 1970-01-01
      • 2016-04-01
      • 2011-01-31
      • 2021-06-20
      • 1970-01-01
      相关资源
      最近更新 更多