说明:这是网站的静态首页:
  
  问题:我编写了以下代码,除了子菜单不能很好地突出显示(不是全角)之外,其他所有功能都正常


任何帮助表示赞赏,谢谢。



$('.nav li > .sub-menu').parent().hover(function() {
  var submenu = $(this).children('.sub-menu');
  if ($(submenu).is(':hidden')) {
    $(submenu).slideDown('slow');
  } else {
    $(submenu).slideUp('slow');
  }
});

body {
  font-family: 'Roboto', sans-serif;
  font-weight: 300;
}

header {
  padding: 20px 0;
}

header .row,
footer .row {
  display: flex;
  align-items: center;
}

.nav li {
  text-decoration: none;
  list-style: none;
  padding: 5px 10px;
  color: black;
  width: auto;
}

.nav>li {
  float: left;
}

.nav .sub-menu {
  position: absolute;
  display: none;
  background-color: rgb(100, 100, 100);
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  padding: 0.5em 2em 0.5em 0.75em;
}

.sub-menu>li {
  display: block;
  float: none;
  padding: 10px 0;
  width: auto;
  white-space: nowrap;
  z-index: 9999;
}

.sub-menu li a {
  text-decoration: none;
  cursor: pointer;
  color: white;
  width: auto;
  text-align: left;
  white-space: nowrap;
  padding: 10px 0;
}

.sub-menu li a:hover {
  background: #e3e3e3;
}

header h1 {
  font-weight: 900;
  margin: 0;
}

header nav {
  position: relative;
  display: flex;
  justify-content: flex-end;
  z-index: 9999;
  overflow: visible;
}

header p {
  padding: 0 20px;
  margin: 0;
}

.jumbotron {
  position: relative;
  display: flex;
  align-items: center;
  background-image: url('https://s3.amazonaws.com/codecademy-content/projects/make-a-website/lesson-4/jumbotron.jpg');
  background-size: cover;
  color: #ffffff;
  height: 500px;
  text-shadow: 0.25px 0.25px 0.25px #000000;
  z-index: -9999;
}

.jumbotron h2 {
  font-size: 60px;
  font-weight: 900;
  margin: 0;
  color: #fff;
}

.jumbotron h3 {
  margin: 0 0 20px;
  color: #fff;
}

section .row img {
  margin: 0 0 30px;
  width: 100%;
}

.col-md-6 {
  margin: 0 0 30px;
}

.btn.btn-primary {
  border-radius: 2px;
  border: 0px;
  color: #fbd1d5;
  text-shadow: none;
  background-color: #ffffff;
  -webkit-transition: width 2s, height 2s;
  -webkit-transition-duration: 5s;
}

.btn.btn-primary:hover {
  width: 70px;
  height: 35px;
  text-align: center;
  line-height: 22.5px;
  color: #ffffff;
  background-color: #fbd1d5;
}

.btn-secondary {
  background-color: #E8DFE0;
  color: #ffffff;
  margin: 0 0 30px;
}

section .col-sm-6 img {
  border-radius: 6px;
}

section .col-sm-6 img:hover {
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}

footer {
  font-size: 12px;
  padding: 20px 0;
}

footer .col-sm-8 {
  display: flex;
  justify-content: flex-end;
}

footer ul {
  list-style: none;
}

footer li img {
  width: 32px;
  height: 32px;
}

<!DOCTYPE html>
<html>

<head>
  <title>Skillfair</title>
  <meta charset="utf-8" />
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
  <link href='https://fonts.googleapis.com/css?family=Roboto:300,400,700' rel='stylesheet' type='text/css'>
  <link rel="stylesheet" type="text/css" href="main.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>

</head>

<body>
  <header class="container">
    <div class="row">
      <h1 class="col-sm-4">Skillfair</h1>
      <nav class="col-sm-8 text-right">
        <ul class="nav">
          <li>
            <a href="#offers">OFFERS</a>
            <ul class="sub-menu">
              <li><a>buy 1 get 1</a></li>
              <li><a>buy 2 get 2</a></li>
              <li><a>buy 3 get 3</a></li>
            </ul>
          </li>
          <li><a href="#catalogue">CATALOGUE</a></li>
          <li><a href="#contact">CONTACT</a></li>
        </ul>
      </nav>
    </div>
  </header>
  <section class="jumbotron">
    <div class="container">
      <div class="row text-center">
        <h2>Homemade Goods</h2>
        <h3>This Year's Best</h3>
        <a class="btn btn-primary" href="#" role="button">See all</a>
      </div>
    </div>
  </section>
  <section class="container">
    <div class="row">
      <figure class="col-sm-6">
        <p>kitchen</p>
        <img src="https://s3.amazonaws.com/codecademy-content/projects/make-a-website/lesson-4/kitchen.jpg" />
      </figure>
      <figure class="col-sm-6">
        <p>woodwork</p>
        <img src="https://s3.amazonaws.com/codecademy-content/projects/make-a-website/lesson-4/woodwork.jpg" />
      </figure>
    </div>
    <div class="row">
      <figure class="col-sm-6">
        <p>gifts</p>
        <img src="https://s3.amazonaws.com/codecademy-content/projects/make-a-website/lesson-4/gifts.jpg" />
      </figure>
      <figure class="col-sm-6">
        <p>antiques</p>
        <img src="https://s3.amazonaws.com/codecademy-content/projects/make-a-website/lesson-4/antique.jpg" />
      </figure>
    </div>
  </section>
  <footer class="container">
    <div class="row">
      <p class="col-sm-4">
        &copy; 2017 Skillfair
      </p>
      <ul class="col-sm-8">
        <li class="col-sm-1"><img src="https://s3.amazonaws.com/codecademy-content/projects/make-a-website/lesson-4/twitter.svg"></li>
        <li class="col-sm-1"><img src="https://s3.amazonaws.com/codecademy-content/projects/make-a-website/lesson-4/facebook.svg"></li>
        <li class="col-sm-1"><img src="https://s3.amazonaws.com/codecademy-content/projects/make-a-website/lesson-4/instagram.svg"></li>
        <li class="col-md-1"><img src="https://s3.amazonaws.com/codecademy-content/projects/make-a-website/lesson-4/medium.svg"></li>
      </ul>
    </div>
  </footer>
  <script type='text/javascript' src='script.js'></script>
</body>

</html>

最佳答案

.nav .sub-menu {
    position: absolute;
    display: none;
    background-color: rgb(100, 100, 100);
    box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
    // padding: 0.5em 2em 0.5em 0.75em; // remove this
    padding: 0px;
}



.sub-menu li a {
    text-decoration: none;
    cursor: pointer;
    color: white;
    width: auto;
    text-align: left;
    white-space: nowrap;
    // padding: 10px 0; // remove this
    padding: 10px;
}

09-25 15:50