如何将下拉菜单集中?

发布于 2025-01-24 07:08:25 字数 3775 浏览 4 评论 0原文

我一直在一个网站上工作,想知道如何将下拉列表集中, “这是图像” 我的代码作为代码笔为 codepen 这是CSS 我尝试了很多事情,包括将位置标记更改为不同的值,并在填充和其他间隙中添加

<nav class="navbar">
  <div class="logo">
    <a href=index.html>
      <img src="Addy Schroeders.png" width="60px" height="60px">
    </a>
  </div>
  <div class="menu">
    <li>
      <a href="/">
        Home
      </a>
    </li>
    <li>
      <a href="/">
        About
      </a>
    </li>
    <li>
      <a href="/">
        help and resources
      </a>
    </li>
    <li class="services">
      <a href="/">
        pages
      </a>
      <!-- DROPDOWN MENU -->
      <ul class="dropdown">
        <li>
          <a href="template.html">
            Dropdown 1
          </a>
        </li>
        <li>
          <a href="/">
            Dropdown 2
          </a>
        </li>
        <li>
          <a href="/">
            Dropdown 2
          </a>
        </li>
        <li>
          <a href="/">
            Dropdown 3
          </a>
        </li>
        <li>
          <a href="/">
            Dropdown 4
          </a>
        </li>
      </ul>
    <li>
      <a href="/">
        Contact
      </a>
    </li>
  </div>
  </ul>
</nav>
body {
  font-family: opendyslexic, sans-serif;
  text-align: center;
  font-size: 24px;
  line-height: 1.2;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

a {
  text-decoration: none;
  color: #f7abff /* pink */;
}

li {
  list-style: none;
}

.navbar {
  display: flex; /* stops the logo being on top of everything else */
  align-items: center; /* centres them vertically */
  justify-content: space-between; /* puts navbar at right */
  padding: 20px; /* adds space at the top */
  background-color: rgb(85, 96, 255)/* blue */; /* the background color */
}

.services {
  position: relative;
  float: right;
}

.dropdown {
  background-color: #5560ff/* pink */; /* this makes the dropdown menu colored */
  padding: 1em 0;
  position: absolute;
  display: none;
  border-radius: 8px;
  top: 30px;
  padding-right: 20px;
  padding-left: 20px;

}

.services:hover .dropdown {
  display: block;
}

.image{
  border-radius: 50%;
}

    body {
  font-family: opendyslexic, sans-serif;
  text-align: center;
  font-size: 24px;
  line-height: 1.2;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

a {
  text-decoration: none;
  color: #f7abff /* pink */;
}

li {
  list-style: none;
}

.navbar {
  display: flex; /* stops the logo being on top of everything else */
  align-items: center; /* centres them vertically */
  justify-content: space-between; /* puts navbar at right */
  padding: 20px; /* adds space at the top */
  background-color: rgb(85, 96, 255)/* blue */; /* the background color */
}

.services {
  position: relative;
  float: right;
}

.dropdown {
  background-color: #5560ff/* pink */; /* this makes the dropdown menu colored */
  padding: 1em 0;
  position: absolute;
  display: none;
  border-radius: 8px;
  top: 30px;
  padding-right: 20px;
  padding-left: 20px;

}

.services:hover .dropdown {
  display: block;
}

.image{
  border-radius: 50%;
}

我一直在查找许多其他问题并遇到了很多问题需要与答案有关 如果我只能拥有CSS代码以及对它所做的少量描述,那么将会非常感谢

I have been working on a site and am wondering how I can center this dropdown, here is the image
My code as a code pen is codepen
here is the css
I have tried many things including changing the position tag to different values and adding in padding and other gaps

<nav class="navbar">
  <div class="logo">
    <a href=index.html>
      <img src="Addy Schroeders.png" width="60px" height="60px">
    </a>
  </div>
  <div class="menu">
    <li>
      <a href="/">
        Home
      </a>
    </li>
    <li>
      <a href="/">
        About
      </a>
    </li>
    <li>
      <a href="/">
        help and resources
      </a>
    </li>
    <li class="services">
      <a href="/">
        pages
      </a>
      <!-- DROPDOWN MENU -->
      <ul class="dropdown">
        <li>
          <a href="template.html">
            Dropdown 1
          </a>
        </li>
        <li>
          <a href="/">
            Dropdown 2
          </a>
        </li>
        <li>
          <a href="/">
            Dropdown 2
          </a>
        </li>
        <li>
          <a href="/">
            Dropdown 3
          </a>
        </li>
        <li>
          <a href="/">
            Dropdown 4
          </a>
        </li>
      </ul>
    <li>
      <a href="/">
        Contact
      </a>
    </li>
  </div>
  </ul>
</nav>
body {
  font-family: opendyslexic, sans-serif;
  text-align: center;
  font-size: 24px;
  line-height: 1.2;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

a {
  text-decoration: none;
  color: #f7abff /* pink */;
}

li {
  list-style: none;
}

.navbar {
  display: flex; /* stops the logo being on top of everything else */
  align-items: center; /* centres them vertically */
  justify-content: space-between; /* puts navbar at right */
  padding: 20px; /* adds space at the top */
  background-color: rgb(85, 96, 255)/* blue */; /* the background color */
}

.services {
  position: relative;
  float: right;
}

.dropdown {
  background-color: #5560ff/* pink */; /* this makes the dropdown menu colored */
  padding: 1em 0;
  position: absolute;
  display: none;
  border-radius: 8px;
  top: 30px;
  padding-right: 20px;
  padding-left: 20px;

}

.services:hover .dropdown {
  display: block;
}

.image{
  border-radius: 50%;
}

    body {
  font-family: opendyslexic, sans-serif;
  text-align: center;
  font-size: 24px;
  line-height: 1.2;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

a {
  text-decoration: none;
  color: #f7abff /* pink */;
}

li {
  list-style: none;
}

.navbar {
  display: flex; /* stops the logo being on top of everything else */
  align-items: center; /* centres them vertically */
  justify-content: space-between; /* puts navbar at right */
  padding: 20px; /* adds space at the top */
  background-color: rgb(85, 96, 255)/* blue */; /* the background color */
}

.services {
  position: relative;
  float: right;
}

.dropdown {
  background-color: #5560ff/* pink */; /* this makes the dropdown menu colored */
  padding: 1em 0;
  position: absolute;
  display: none;
  border-radius: 8px;
  top: 30px;
  padding-right: 20px;
  padding-left: 20px;

}

.services:hover .dropdown {
  display: block;
}

.image{
  border-radius: 50%;
}

I have been looking up many other things and gone through heaps of questions but as a begginer I dont know what I need to do with the answers
If i can just have the CSS code and where it goes with a small description of what it does that will be greately appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ペ泪落弦音 2025-01-31 07:08:25

@AmauryHanser给了我答案
我添加了

.dropdown { 
  left: -50%; }

它已经修复了它,并将其移动一点,我可以算起数字,直到它起作用

@amauryHanser gave me the answer
I added this

.dropdown { 
  left: -50%; }

it has fixed it and moves it left a bit, I can ajust the numbers until it works

简单 2025-01-31 07:08:25
.services {
    position: relative;
}

.dropdown {
    background-color: #5560ff/* pink */;
    padding: 1em 0;
    position: absolute;
    border-radius: 8px;
    top: 2rem;
    padding-right: 20px;
    padding-left: 20px;
    left: 50%;
    transform: translateX(-50%);
}

尝试一下:d

.services {
    position: relative;
}

.dropdown {
    background-color: #5560ff/* pink */;
    padding: 1em 0;
    position: absolute;
    border-radius: 8px;
    top: 2rem;
    padding-right: 20px;
    padding-left: 20px;
    left: 50%;
    transform: translateX(-50%);
}

Try this :D

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文