将<li> </li>与导航栏菜单集对齐

时间:2016-12-27 02:41:18

标签: html css

我现在正在玩这个代码,并试图在此学习一些东西,我试图将我的<li></li>与标题菜单中的集合对齐,但突然间我失败了很多。有人能解释一下这方面的解决方案吗?

&#13;
&#13;
jQuery(document).on('click', '.mega-dropdown', function(e) {
  e.stopPropagation()
})
&#13;
@import url(http://fonts.googleapis.com/css?family=Open+Sans:400,700);
 body {
  font-family: 'Open Sans', 'sans-serif';
  background: #f4f4f4;
}
.navbar-default {
  background-color: #c42027;
}
h1,
.h1 {
  font-size: 36px;
  text-align: center;
  font-size: 5em;
}
.navbar-nav>li>.dropdown-menu {
  margin-top: 20px;
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
}
.navbar-default .navbar-nav>li>a {
  width: 130px;
  font-weight: bold;
  color: #ffffff;
}
.mega-dropdown {
  position: static !important;
  width: 100%;
}
.mega-dropdown-menu {
  padding: 20px 0px;
  width: 100%;
  box-shadow: none;
  -webkit-box-shadow: none;
}
.mega-dropdown-menu:before {
  content: "";
  border-bottom: 15px solid #fff;
  border-right: 17px solid transparent;
  border-left: 17px solid transparent;
  position: absolute;
  top: -15px;
  left: 285px;
  z-index: 10;
}
.mega-dropdown-menu:after {
  content: "";
  border-bottom: 17px solid #ccc;
  border-right: 19px solid transparent;
  border-left: 19px solid transparent;
  position: absolute;
  top: -17px;
  left: 283px;
  z-index: 8;
}
.mega-dropdown-menu > li > ul {
  padding: 0;
  margin: 0;
}
.mega-dropdown-menu > li > ul > li {
  list-style: none;
  color: #222;
}
.mega-dropdown-menu > li > ul > li > a {
  display: inline;
  padding: 3px 20px;
  clear: both;
  font-weight: normal;
  line-height: 1.428571429;
  color: #000000;
  white-space: normal;
}
.mega-dropdown-menu > li ul > li > a:hover,
.mega-dropdown-menu > li ul > li > a:focus {
  text-decoration: none;
  color: #ff3546;
  background-color: #f5f5f5;
}
.mega-dropdown-menu .dropdown-header {
  color: #ff3546;
  font-size: 18px;
  font-weight: bold;
}
.navbar-inverse .navbar-nav>li>a {
  color: white;
  background-color: #ffffff;
  margin: 0;
  padding: 0 15px;
  line-height: 50px;
  display: block;
}
.navbar-default .navbar-nav>li>a:hover {
  color: black;
  background-color: white;
}
.navbar-default .navbar-nav>.open>a:hover {
  color: black;
  background-color: white;
}
&#13;
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
  <nav class="navbar navbar-default">
    <div class="navbar-header">
      <button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".js-navbar-collapse">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">
        <img src="images/logo/conlins logo.jpg">
      </a>
    </div>
    <div class="collapse navbar-collapse js-navbar-collapse">
      <ul class="nav navbar-nav">
        <li class="dropdown mega-dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">Collection <span class="glyphicon glyphicon-chevron-down pull-right"></span></a>

          <ul class="dropdown-menu mega-dropdown-menu row">
            <li class="col-sm-4">
              <ul>
                <li class="dropdown-header">Dresses</li>
                <li><a href="#">Unique Features</a></li>
                <li><a href="#">Image Responsive</a></li>
                <li><a href="#">Auto Carousel</a></li>
                <li><a href="#">Newsletter Form</a></li>
                <li><a href="#">Four columns</a></li>
                <li class="divider"></li>
                <li class="dropdown-header">Tops</li>
                <li><a href="#">Good Typography</a></li>
              </ul>
            </li>
            <li class="col-sm-4">
              <ul>
                <li class="dropdown-header">Jackets</li>
                <li><a href="#">Easy to customize</a></li>
                <li><a href="#">Glyphicons</a></li>
                <li><a href="#">Pull Right Elements</a></li>
                <li class="divider"></li>
                <li class="dropdown-header">Pants</li>
                <li><a href="#">Coloured Headers</a></li>
                <li><a href="#">Primary Buttons & Default</a></li>
                <li><a href="#">Calls to action</a></li>
              </ul>
            </li>
            <li class="col-sm-4">
              <ul>
                <li class="dropdown-header">Accessories</li>
                <li><a href="#">Default Navbar</a></li>
                <li><a href="#">Lovely Fonts</a></li>
                <li><a href="#">Responsive Dropdown </a></li>
                <li class="divider"></li>
                <li class="dropdown-header">Newsletter</li>
              </ul>
            </li>
          </ul>
        <li><a href="#">Events</a></li>
        <li><a href="javascript:AlertIt();">Store</a></li>
        <li><a href="#">About us</a></li>
        <li><a href="#">Contact us</a></li>
        <li><a href="#">Career</a></li>
        <li>
          <div class="social_media">
            <a href="https://www.facebook.com/conlinscoffee/">
              <img src="images/social_media/facebook.png" height="20px" width="auto">&nbsp;&nbsp;&nbsp;</a>
            <a href="https://twitter.com/hashtag/conlinscoffee">
              <img src="images/social_media/twitter.png" height="20px" width="auto">&nbsp;&nbsp;&nbsp;</a>
            <a href="#">
              <img src="images/social_media/instagram.png" height="20px" width="auto">
            </a>
          </div>
        </li>
      </ul>
    </div>
    <!-- /.nav-collapse -->
  </nav>
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

如果我是对的,那么班级mega-dropdown就是使它达到全宽度的原因。所以,如果你拿走那个课程,那就行了。或者只删除width: 100%

jQuery(document).on('click', '.mega-dropdown', function(e) {
  e.stopPropagation()
})
@import url(http://fonts.googleapis.com/css?family=Open+Sans:400,700);
 body {
  font-family: 'Open Sans', 'sans-serif';
  background: #f4f4f4;
}
.navbar-default {
  background-color: #c42027;
}
h1,
.h1 {
  font-size: 36px;
  text-align: center;
  font-size: 5em;
}
.navbar-nav>li>.dropdown-menu {
  margin-top: 20px;
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
}
.navbar-default .navbar-nav>li>a {
  width: 130px;
  font-weight: bold;
  color: #ffffff;
}
.mega-dropdown {
  position: static !important;
  /* width: 100%; */
}
.mega-dropdown-menu {
  padding: 20px 0px;
  width: 100%;
  box-shadow: none;
  -webkit-box-shadow: none;
}
.mega-dropdown-menu:before {
  content: "";
  border-bottom: 15px solid #fff;
  border-right: 17px solid transparent;
  border-left: 17px solid transparent;
  position: absolute;
  top: -15px;
  left: 285px;
  z-index: 10;
}
.mega-dropdown-menu:after {
  content: "";
  border-bottom: 17px solid #ccc;
  border-right: 19px solid transparent;
  border-left: 19px solid transparent;
  position: absolute;
  top: -17px;
  left: 283px;
  z-index: 8;
}
.mega-dropdown-menu > li > ul {
  padding: 0;
  margin: 0;
}
.mega-dropdown-menu > li > ul > li {
  list-style: none;
  color: #222;
}
.mega-dropdown-menu > li > ul > li > a {
  display: inline;
  padding: 3px 20px;
  clear: both;
  font-weight: normal;
  line-height: 1.428571429;
  color: #000000;
  white-space: normal;
}
.mega-dropdown-menu > li ul > li > a:hover,
.mega-dropdown-menu > li ul > li > a:focus {
  text-decoration: none;
  color: #ff3546;
  background-color: #f5f5f5;
}
.mega-dropdown-menu .dropdown-header {
  color: #ff3546;
  font-size: 18px;
  font-weight: bold;
}
.navbar-inverse .navbar-nav>li>a {
  color: white;
  background-color: #ffffff;
  margin: 0;
  padding: 0 15px;
  line-height: 50px;
  display: block;
}
.navbar-default .navbar-nav>li>a:hover {
  color: black;
  background-color: white;
}
.navbar-default .navbar-nav>.open>a:hover {
  color: black;
  background-color: white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
  <nav class="navbar navbar-default">
    <div class="navbar-header">
      <button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".js-navbar-collapse">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">
        <img src="images/logo/conlins logo.jpg">
      </a>
    </div>
    <div class="collapse navbar-collapse js-navbar-collapse">
      <ul class="nav navbar-nav">
        <li class="dropdown mega-dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">Collection <span class="glyphicon glyphicon-chevron-down pull-right"></span></a>

          <ul class="dropdown-menu row">
            <li class="col-sm-4">
              <ul>
                <li class="dropdown-header">Dresses</li>
                <li><a href="#">Unique Features</a></li>
                <li><a href="#">Image Responsive</a></li>
                <li><a href="#">Auto Carousel</a></li>
                <li><a href="#">Newsletter Form</a></li>
                <li><a href="#">Four columns</a></li>
                <li class="divider"></li>
                <li class="dropdown-header">Tops</li>
                <li><a href="#">Good Typography</a></li>
              </ul>
            </li>
            <li class="col-sm-4">
              <ul>
                <li class="dropdown-header">Jackets</li>
                <li><a href="#">Easy to customize</a></li>
                <li><a href="#">Glyphicons</a></li>
                <li><a href="#">Pull Right Elements</a></li>
                <li class="divider"></li>
                <li class="dropdown-header">Pants</li>
                <li><a href="#">Coloured Headers</a></li>
                <li><a href="#">Primary Buttons & Default</a></li>
                <li><a href="#">Calls to action</a></li>
              </ul>
            </li>
            <li class="col-sm-4">
              <ul>
                <li class="dropdown-header">Accessories</li>
                <li><a href="#">Default Navbar</a></li>
                <li><a href="#">Lovely Fonts</a></li>
                <li><a href="#">Responsive Dropdown </a></li>
                <li class="divider"></li>
                <li class="dropdown-header">Newsletter</li>
              </ul>
            </li>
          </ul>
        <li><a href="#">Events</a></li>
        <li><a href="javascript:AlertIt();">Store</a></li>
        <li><a href="#">About us</a></li>
        <li><a href="#">Contact us</a></li>
        <li><a href="#">Career</a></li>
        <li>
          <div class="social_media">
            <a href="https://www.facebook.com/conlinscoffee/">
              <img src="images/social_media/facebook.png" height="20px" width="auto">&nbsp;&nbsp;&nbsp;</a>
            <a href="https://twitter.com/hashtag/conlinscoffee">
              <img src="images/social_media/twitter.png" height="20px" width="auto">&nbsp;&nbsp;&nbsp;</a>
            <a href="#">
              <img src="images/social_media/instagram.png" height="20px" width="auto">
            </a>
          </div>
        </li>
      </ul>
    </div>
    <!-- /.nav-collapse -->
  </nav>
</div>

预览

preview