html - 如何在导航栏中的下拉菜单中删除透明度,使其仅使用 CSS 不显示其后面的页面文本
问题描述
我是编码新手,我的大学向我们提交了一项作业,我需要帮助transparency
从drop-down menu
. 当您向下滚动时,您可以看到后面的页面正文navbar
。No opacity
已设置。此外,当我使用透明导航栏向下滚动时,光标无法越过正文开始的位置。
感谢您的任何帮助!
我附上了 CSS 和 HTML 的代码片段:
body {
background-color: rgb(255, 255, 255);
font-family: Arial, Helvetica, sans-serif;
}
nav {
text-align: center;
}
ul {
margin: 0%;
padding: 0px;
list-style: none;
display: inline-block;
}
ul li {
float: left;
width: 300px;
height: 35px;
background-color: rgb(211, 211, 211);
line-height: 35px;
text-align: center;
font-size: 18px;
}
ul li a {
text-decoration: none;
color: rgb(0, 0, 0);
display: block;
}
ul li a:hover {
background-color: rgb(180, 180, 180);
}
ul li ul li {
display: none;
}
ul li:hover ul li {
display: block;
}
.html logo {
height: auto;
width: auto;
max-width: 50px;
max-height: 50px;
padding-left: 2%;
}
.font-element {
font-family: 'Courier New', Courier, monospace;
}
h1 {
font-family: Arial, Helvetica, sans-serif;
font-weight: lighter;
}
h2 {
font-family: Arial, Helvetica, sans-serif;
font-weight: lighter;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The <b> Element </title>
<link href="styles.css" rel="stylesheet">
</head>
<body>
<header>
<a href="index.html"><img class="html logo" src="images/logo.png" alt="HTML&CSS"></a>
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a>HTML 5</a>
<ul>
<li><a href="belement.html"><b> Element</a></li>
<li><a href="element2.html">Element 2</a></li>
<li><a href="element3.html">Element 3</a></li>
<li><a href="element4.html">Element 4</a></li>
<li><a href="element5.html">Element 5</a></li>
<li><a href="element6.html">Element 6</a></li>
<li><a href="element7.html">Element 7</a></li>
<li><a href="element8.html">Element 8</a></li>
<li><a href="element9.html">Element 9</a></li>
<li><a href="element10.html">Element 10</a></li>
</ul>
</li>
<li><a>CSS</a>
<ul>
<li><a href="css1.html">CSS 1</a></li>
<li><a href="css2.html">CSS 2</a></li>
<li><a href="css3.html">CSS 3</a></li>
</ul>
<li><a href="contact.html">Contact</a></li>
</ul>
</nav>
</header>
<h1>The <<span class="font-element">b</span>> Element</h1>
<p>The b element represents a span of text to which attention is being drawn for utilitarian purposes without conveying any extra importance and with no implication of an alternate voice or mood, such as key words in a document abstract, product names
in a review, actionable words in interactive text-driven software, or an article lede.
<h2>Example Code:</h2>
This is some <b>really bold text </b>.
<h2>The result:</h2>
This is some <b>really bold text</b>.
<p>You can find more information on the official W3C specification by clicking here.</p>
</body>
</html>
解决方案
Just comment on these two lines on your CSS file
ul li {
position: relative;
float: left;
width: 300px;
/* height: auto; */
/* background-color: rgb(211, 211, 211); */
line-height: 35px;
text-align: center;
font-size: 18px;
}
推荐阅读
- reactjs - React native:删除 node_modules 后出现 npm start 问题
- php - Laravel 8 SQLSTATE [42S02]:未找到基表或视图:1146 表,即使我正在尝试创建此表
- unity3d - Unity WorldToScreenPoint 返回巨大的值
- c++ - 如何在 c++ (winapi) 上获取用户的个人资料图片路径
- swiftui - 如何在 SwiftUI 的 Wrapper 中滚动定位 UIScrollView?
- swift - 如何删除文本字段中所选文本的选项窗口,Swift
- python - 无法使用 Airflow 2.1.2 DAG 中的 HiveOperator 连接到 Hive
- django - get() 返回多个指定 -- 它返回 4
- python - 无法显示数据框的列
- javascript - 组织多个 Firebase 触发器