Html 如何删除菜单中的间距
我正在使用我在这个网站上找到的一个菜单示例。这是。该示例显示页面的背景色和菜单栏的另一种背景色。在我的网站上,颜色将是相同的。但当颜色相同时,总和菜单项显示在主菜单项下方太远。有人能解释一下我如何删除这个空间,这样子项,比如Splash任务,就在主项的正下方,比如Splash模式吗 下面是正在使用的代码:Html 如何删除菜单中的间距,html,css,Html,Css,我正在使用我在这个网站上找到的一个菜单示例。这是。该示例显示页面的背景色和菜单栏的另一种背景色。在我的网站上,颜色将是相同的。但当颜色相同时,总和菜单项显示在主菜单项下方太远。有人能解释一下我如何删除这个空间,这样子项,比如Splash任务,就在主项的正下方,比如Splash模式吗 下面是正在使用的代码: <style> @font-face { font-family: "Yeezy"; src: url("../static/yeezy.t
<style>
@font-face {
font-family: "Yeezy";
src: url("../static/yeezy.ttf");
}
* {
font-family: "Yeezy";
font-weight: bold;
color: #dbdbdb !important;
}
html,
body {
height: 900px;
background-size: cover;
background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.4) 0%, rgba(0, 0, 0, 0.4) 100%), url("https://i.imgur.com/pxYxnOn.jpg");
}
.navbar {
overflow: hidden;
background-color: rgba(0, 0, 0, 0.2);
}
/* Links inside the navbar */
.navbar a {
float: left;
font-size: 15px;
color: rgba(0, 0, 0, 0.4);
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
/* The dropdown container */
.dropdown {
float: left;
overflow: hidden;
}
/* Dropdown button */
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: rgba(0, 0, 0, 0.2);
padding: 17px 13px;
background-color: inherit;
font-family: inherit;
/* Important for vertical align on mobile phones */
margin: 0;
/* Important for vertical align on mobile phones */
}
/* Add a red background color to navbar links on hover */
.navbar a:hover,
.dropdown:hover .dropbtn {
}
/* Dropdown content (hidden by default) */
.dropdown-content {
display: none;
position: absolute;
min-width: 160px;
box-shadow: 0px 0px 16px -20px rgba(0, 0, 0, 0.1);
z-index: 1;
}
/* Links inside the dropdown */
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
/* Add a grey background color to dropdown links on hover */
.dropdown-content a:hover {
background-color: rgba(0, 0, 0, 0.2);
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
</style>
<body>
<div class="navbar navbar-default">
<a href="#home">Home</a>
<div class="dropdown">
<button class="dropbtn">Splash Mode</button>
<div class="dropdown-content">
<a href="splashtasks">Splash Tasks</a>
<a href="h2splash">How to use Product Mode</a>
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Product Mode</button>
<div class="dropdown-content">
<a href="producttasks">Product Tasks</a>
<a href="h2product">How to use Product Mode</a>
</div>
</div>
</div>
</body>
这将删除下拉菜单中第一个元素顶部的填充
在css中,您在此处为下拉元素提供空间:
.dropdown-content a {
...
padding: 12px 16px;
...
什么空间。。。非常感谢。这很有帮助。但是我需要控制主菜单的高度。我只希望它和文本一样高,没有填充。那是什么控制的?你几乎回答了你的问题,说没有填充。。。因此,基本上只有填充来控制案例中的高度->检查选择器“.dropdown.dropbtn”和.navbar a。您的问题很简单,我建议您检查MDN页面和CSS技巧以了解更多信息。
.dropdown-content a {
...
padding: 12px 16px;
...