Невозможно переместить подменю (выпадающее меню) в родительское меню - PullRequest
0 голосов
/ 05 апреля 2020

У меня проблемы с выравниванием выпадающего меню / подменю в parent меню. Чтобы было понятно, я хочу, чтобы мое подменю показывалось, когда я наводил курсор на Службы . Я опубликую код, а также приложу фото, чтобы очистить.

Редактировать: Я обновил фрагмент! Я думаю, что сейчас все в порядке. Спасибо!

body {
  font-family: 'Poppins', sans-serif;
  background-color: -webkit-linear-gradient(to right, #2a5298, #1e3c72);
  background-color: linear-gradient(to right, #2a5298, #1e3c72);
  background-color: #1e3c72;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

button {
  font-family: 'Poppins', sans-serif;
}

header {
  display: flex;
  width: 100%;
  margin: auto;
  align-items: center;
}

nav {
  flex: 1;
  height: 10vh;
}

.nav-links ul {
  position: absolute;
  /* display: none; */
}

.nav-links li a {
  color: white;
  font-weight: 400;
  text-decoration: none;
  display: block;
  padding: 15px;
  font-size: 18px;
}

.nav-links li {
  transition: all .6s ease-out;
  border-radius: 40px;
  height: 70%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px 18px;
}

.nav-links li:hover {
  background-color: white;
  border-radius: 40px;
  height: 60%;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #1e3c72;
  -webkit-transition: all .6s ease;
  transition: all .6s ease;
  padding: 10px 18px;
}

.nav-links li:hover a {
  color: #1e3c72;
}

.nav-links img {
  height: 30px;
  width: 30px;
  filter: invert(100%);
  -webkit-filter: invert(100%);
  filter: brightness(0) invert(1);
  cursor: pointer;
}

.nav-links li i {
  padding: 0 10px;
}

.nav-links {
  display: flex;
  justify-content: space-around;
  list-style: none;
  align-items: center;
  width: 50%;
  height: 100%;
  margin-left: auto;
}
<nav>
  <ul class="nav-links">
    <li><a class="nav-link" href="index.html" id="active">Home</a></li>
    <li><a class="nav-link" href="#">Services</a>
      <ul>
        <li><a href="#">Quality Management</a></li>
        <li><a href="#">Project Management</a></li>
        <li><a href="#">Auditing</a></li>
      </ul>
    </li>
    <li><a class="nav-link" href="#">About</a></li>
    <li><a class="nav-link" href="#">Contact</a></li>
  </ul>
</nav>

1 Ответ

0 голосов
/ 05 апреля 2020

На ограниченном ресурсе, которым вы поделились, я полагаю, это то, что вам нужно?

* {
  margin: 0;
  padding: 0;
}

nav {
  height: 30px;
}

nav ul {
  display: block;
  position: relative;
  z-index: 100;
}

nav ul li {
  float: left;
  list-style: none;
  margin: 0;
  padding: 0;
}

nav ul li ul {
  display: none;
}

nav ul li a {
  width: 150px;
  height: 30px;
  display: block;
  text-decoration: none;
  text-align: center;
  line-height: 30px;
  background-color: black;
  color: white;
}

nav ul li a:hover {
  background-color: red;
}

nav ul li:hover ul {
  position: absolute;
  top: 30px;
  display: block;
  width: 100px;
}

nav ul li:hover ul li {
  display: block;
}
<nav>
  <ul class="nav-links">
    <li><a class="nav-link" href="index.html" id="active">Home</a></li>
    <li><a class="nav-link" href="#">Services</a>
      <ul>
        <li><a href="#">Quality Management</a></li>
        <li><a href="#">Project Management</a></li>
        <li><a href="#">Auditing</a></li>
      </ul>
    </li>
  </ul>

</nav>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...