“position:fixed”破坏了 CSS 网页中的下拉菜单

2024-04-03

我正在创建一个网页,当我将鼠标悬停在.Soccer部分,它将下拉并显示 Link1、Link2、Link3。

如果没有position: fixed;,代码工作得很好。 因为我希望标题位于网页顶部,所以我把position: fixed;

但一旦我穿上它,“足球”的下拉按钮就不起作用了。

html {
  background-image: url("Images/BackgroundImageI.jpg");
  background-repeat: no-repeat;
}

body {
  background-color: White;
  color: Black;
  margin-left: 0%;
  margin-right: 0%;
  margin-top: 40%;
  margin-bottom: 0%;
  border: 10px outset Gray;
}

h1 {
  font-family: Arial, Verdana, Geneva, sans-serrif;
  color: teal;
  text-align: center;
}

p {
  font-family: Arial, Verdana, Geneva, sans-serrif, serrif;
  font-size: 12px;
  font-style: normal;
  font-weight: normal;
  line-height: 24px;
}

ul {
  margin-left: 0%;
  margin-right: 0%;
  margin-top: 0%;
  list-style-type: none;
  margin: 0;
  padding: 0;
  top: 0;
  width: 100%;
  overflow: hidden;
  background-color: #333;
  position: fixed;
  /* Removing this makes the dropdown work */
}

li {
  float: left;
}

li a,
.dropbtn {
  display: inline-block;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

li a:hover,
.Soccer:hover .dropbtn {
  background-color: teal;
}

li.Soccer {
  display: inline-block;
}

.Soccer-content {
  display: none;
  position: absolute;
  background-color: #f9f9f9;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  z-index: 1;
}

.Soccer-content a {
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  text-align: left;
}

.Soccer-content a:hover {
  background-color: teal
}

.Soccer:hover .Soccer-content {
  display: block;
}
<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>Test</title>
  <link rel="stylesheet" href="testeditor.css" type="text/css">
</head>

<body>

  <ul>
    <li><a href="brokenlink.html">Home</a></li>
    <li><a href="#brokenlink.html">News</a></li>
    <li class="Soccer">
      <a href="javascript:void(0)" class="dropbtn">Soccer</a>
      <div class="Soccer-content">
        <a href="#">Link 1</a>
        <a href="#">Link 2</a>
        <a href="#">Link 3</a>
      </div>
    </li>
  </ul>

  <h3>Soccer Menu inside a Navigation Bar</h3>
  <p>Hover over the "Soccer" link to see the Soccer menu.</p>

</body>

</html>

如果您不明白我正在尝试做的事情的概念,请询问我。如果你明白的话,请帮助我。

这是我的第一篇文章,因此与其他文章相比可能有点偏差。


你有一个overflow: hidden在你的ul元素。因此没有显示下拉菜单。删除它会使下拉菜单再次出现。

html {
  background-image: url("Images/BackgroundImageI.jpg");
  background-repeat: no-repeat;
}

body {
  background-color: White;
  color: Black;
  margin-left: 0%;
  margin-right: 0%;
  margin-top: 40%;
  margin-bottom: 0%;
  border: 10px outset Gray;
}

h1 {
  font-family: Arial, Verdana, Geneva, sans-serrif;
  color: teal;
  text-align: center;
}

p {
  font-family: Arial, Verdana, Geneva, sans-serrif, serrif;
  font-size: 12px;
  font-style: normal;
  font-weight: normal;
  line-height: 24px;
}

ul {
  margin-left: 0%;
  margin-right: 0%;
  margin-top: 0%;
  list-style-type: none;
  margin: 0;
  padding: 0;
  top: 0;
  width: 100%;
  background-color: #333;
  position: fixed;
}

li {
  float: left;
}

li a,
.dropbtn {
  display: inline-block;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

li a:hover,
.Soccer:hover .dropbtn {
  background-color: teal;
}

li.Soccer {
  display: inline-block;
}

.Soccer-content {
  display: none;
  position: absolute;
  background-color: #f9f9f9;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  z-index: 1;
}

.Soccer-content a {
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  text-align: left;
}

.Soccer-content a:hover {
  background-color: teal
}

.Soccer:hover .Soccer-content {
  display: block;
}
<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>Test</title>
  <link rel="stylesheet" href="testeditor.css" type="text/css">
</head>

<body>

  <ul>
    <li><a href="brokenlink.html">Home</a></li>
    <li><a href="#brokenlink.html">News</a></li>
    <li class="Soccer">
      <a href="javascript:void(0)" class="dropbtn">Soccer</a>
      <div class="Soccer-content">
        <a href="#">Link 1</a>
        <a href="#">Link 2</a>
        <a href="#">Link 3</a>
      </div>
    </li>
  </ul>

  <h3>Soccer Menu inside a Navigation Bar</h3>
  <p>Hover over the "Soccer" link to see the Soccer menu.</p>

</body>

</html>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

“position:fixed”破坏了 CSS 网页中的下拉菜单 的相关文章

  • 如何正确使用 z-index?

    请在此处查看此页面 http www blakearchive org blake public exhibits canterburySpecial html http www blakearchive org blake public
  • 替换javascript中字符串中的多个字符

    我得到了这段不错的代码 但我不知道为什么不起作用 出于兼容性目的 它应该获取文本输入的值并用 HTML 代码替换每个给定的国家字符 但是 当我单击按钮时 该函数返回字符串而不进行任何更改 任何想法 jsfiddle http jsfiddl
  • 导航时 Internet Explorer 9 中的图像闪烁白色

    我正在使用 XHTML 1 1 CSS 3 0 开发一个网站 但 Internet Explorer 9 出现问题 每次我将页面从 主页 更改为 功能 时 各种图像在填充之前都会闪烁 白色 出现这种 白色闪烁 每次页面更改时 我见过很多堆栈
  • 加载 HTML 格式的大型视频文件

    这是我的问题 我想播放存储在 S3 存储桶中的大型视频文件 3 6Gb 但该文件似乎太大 并且加载 30 秒后页面崩溃 这是我播放视频的代码 var video document getElementById video const med
  • 如何在 Popup div 中加载 iframe 内容?

    如何在 Popup div 中加载 iframe 内容 单击每个链接时将打开弹出 div 从每个链接 页面 url 将加载到弹出 div 内的 iframe href document ready function openpop clic
  • 如何在 Angular 应用程序中动态更改 CSS 类名称?

    我有两个 CSS 类名 如下所示 icon heart color bdbdbd icon heart red color a6b7d4 我的 HTML 包含一个心形图标 div class icon heart div
  • 强制应用媒体查询

    我有这个 html 和 css 代码 div class wrapper div class a div div class b div div media all and max width 400px max height 300px
  • 如何使用 file:///F:/foldername 访问 ajax 中的本地文件夹?但它适用于 http://

    在这里 我使用以下代码使用 AJAX jQuery 动态创建文件名列表 window load function var fileExt csv document ready function ajax url file F foldern
  • 设置绝对仓位和保证金

    我想设置一个元素的position to absolute并有一个margin bottom 但似乎margin bottom没有效果 HTML div div CSS container border 1px solid red posi
  • Rails 上的 SASS 无效 CSS 错误

    我正在尝试使用http startbootstrap com stylish portfolio http startbootstrap com stylish portfolio但是 在我的 Rails 应用程序中 我在 vintage
  • 移动设备上的剩余悬停效果

    我一整天都在努力做这个JSFiddle http jsfiddle net gsamaras q2w4jjyt 4 也适用于手机 但我所有的尝试都没有效果 在桌面上 当用户将鼠标悬停在箭头上时 它会变成红色 在移动设备上 当用户触摸 为了单
  • 通过 beautiful soup python 找到所有字体大小大于最常见字体的跨度样式

    我了解如何从特定的位置获取文本div or span这个问题的风格 如何找到最常见的跨度样式 https stackoverflow com questions 40762692 is there a way to find the mos
  • 如何选择一个元素但排除其子元素

    我明白 div hover not class 作品 但是 如何实现 LI 元素的 悬停 效果 但排除鼠标悬停在LI内的某个 DIV 上时的悬停效果 E G li Hello div Bye div li 我想获得 li 的悬停效果 li
  • 角度材质表-表内边框

    I am using Angular material table and I want to set border inside the table Using CSS I was able to set border Normal ca
  • 如何实现Contenteditable属性的Ctrl+A功能?

    我正在尝试为用户显示带有一些示例代码的 div 我希望他们能够在 div 内部进行选择并使用 Ctrl A 选择所有示例代码 但我不希望他们能够编辑实际文本 以免意外删除一点 然后它不会工作 我现在通过 div 上的 contentedit
  • Ace Editor 自动完成和多种语言

    如何为 Ace 编辑器创建自动完成功能以及如何突出显示 php 中的 html javascript 和 csshttp ace ajax org http ace ajax org
  • 设置引导工具提示上的箭头样式[重复]

    这个问题在这里已经有答案了 我正在尝试使用以下方式设置工具提示样式 tooltip inner 但我遇到了麻烦 因为我找不到如何设置工具提示小箭头的样式 如屏幕截图所示 工具提示的箭头是黑色的 我想在其上添加新颜色 any suggesti
  • 如何使弹出窗口溢出:在溢出内可见:自动上下文

    我有一个 div 列表 如果超过父框 overflow x 应该滚动 并且在悬停时 我想看到一个弹出窗口 我的问题是 如果我将鼠标悬停在任何子 div 上 弹出窗口将被考虑用于溢出计算 但我只想让它在所有内容之上可见 而不是使其扩展滚动区域
  • 无法使用python和beautifulsoup抓取网页中的某些href

    我目前正在使用 Python 3 4 和 bs4 爬取网页 以收集塞尔维亚在里约 2016 年的比赛结果 所以网址here http rio2016 fivb com en volleyball women teams srb serbia
  • Firefox -moz-border-radius 不会裁剪图像?

    如果设置了图像的边框半径 有谁知道如何让 Firefox 裁剪角 它包含的元素可以正常工作 但我会发现丑陋的角落伸出来 有什么方法可以解决此问题 而无需将图像设置为背景图像或在将其放在网站上之前对其进行处理吗 解决方法 将图像设置为容器元素

随机推荐