我想在我的下拉菜单中添加专栏,但我不知道我是如何尝试整合来自网络的现有内容但是他们不能工作。我希望将列部分放在三个单独的列中,这样就不会出现大的下拉列表,而是出现一个包含三列的框
/*Navigation Bar*/
.navbar {
overflow: hidden;
background-color: #000000;
font-family: "Century Gothic";
height: 40px;
margin-top: 3px;
}
.navbar a {
float: left;
font-size: 15px;
color: white;
text-align: center;
padding: 11px 13px;
text-decoration: none;
height: 40px;
}
.active {
background-color: #FB724C;
}
.dropdown {
float: left;
overflow: hidden;
height: 40px;
}
.dropdown .dropbtn {
font-size: 15px;
font-family: "Century Gothic";
border: none;
outline: none;
color: white;
padding: 11px 13px;
background-color: inherit;
height: 40px;
}
.navbar a:hover,
.dropdown:hover .dropbtn {
background-color: #B64321;
}
.dropdown-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;
}
.dropdown-content a {
font-size: 13px;
font-family: "Century Gothic";
float: none;
color: black;
padding: 11px 13px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #F4DDD0;
}
.dropdown:hover .dropdown-content {
display: block;
}

<div class="navbar">
<a class="active" href="Index.html">Home</a>
<div class="dropdown">
<button class="dropbtn">Tech
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a href="#">Apple <i class="fa fa-apple"></i></a>
<a href="#">Android <i class="fa fa-android"></i></a>
<a href="#">Computers <i class="fa fa-desktop"></i></a>
<a href="#">Drones <i class="fa fa-camera"></i></a>
<a href="#">Photography <i class="fa fa-camera"></i></a>
<a href="#">TVs <i class="fa fa-"></i></a>
</div>
</div>
<a href="Subscription.html">Subcription</a>
<a href="#news">About Us</a>
<a href="#news">Contact</a>
<a style="float:right" href="#Sign Up">Sign Up <i class="fa fa-user-plus" aria-hidden="true"></i></a>
<a style="float:right" href="#Log In">Log in <i class="fa fa-sign-in" aria-hidden="true"></i></a>
</div>
&#13;
答案 0 :(得分:2)
将此代码段放在您想要的下拉列表中。
<td class="dropdown">
<a>Dropdown Table</a>
<dev id="rows">
<tr><ul>
<li>link 1</li>
<li>link 2</li>
<li>link 3</li>
</ul></tr>
<tr><ul>
<li>link 1</li>
<li>link 2</li>
<li>link 3</li>
</ul></tr>
<tr><ul>
<li>link 1</li>
<li>link 2</li>
<li>link 3</li>
</ul></tr>
</dev>
</td>
/* CSS /*
.dropdown .rows {display:none}
.dropdown:hover .rows {display:block;}
答案 1 :(得分:0)
尝试添加到.dropdown-content
css属性:column-count: 3;
和max-height: 150px;
。
/*Navigation Bar*/
.navbar {
overflow: hidden;
background-color: #000000;
font-family: "Century Gothic";
height: 40px;
margin-top: 3px;
}
.navbar a {
float: left;
font-size: 15px;
color: white;
text-align: center;
padding: 11px 13px;
text-decoration: none;
height: 40px;
}
.active {
background-color: #FB724C;
}
.dropdown {
float: left;
overflow: hidden;
height: 40px;
}
.dropdown .dropbtn {
font-size: 15px;
font-family: "Century Gothic";
border: none;
outline: none;
color: white;
padding: 11px 13px;
background-color: inherit;
height: 40px;
}
.navbar a:hover,
.dropdown:hover .dropbtn {
background-color: #B64321;
}
.dropdown-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;
column-count: 3;
max-height: 150px;
}
.dropdown-content a {
font-size: 13px;
font-family: "Century Gothic";
float: none;
color: black;
padding: 11px 13px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #F4DDD0;
}
.dropdown:hover .dropdown-content {
display: block;
}
<div class="navbar">
<a class="active" href="Index.html">Home</a>
<div class="dropdown">
<button class="dropbtn">Tech
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a href="#">Apple <i class="fa fa-apple"></i></a>
<a href="#">Android <i class="fa fa-android"></i></a>
<a href="#">Computers <i class="fa fa-desktop"></i></a>
<a href="#">Drones <i class="fa fa-camera"></i></a>
<a href="#">Photography <i class="fa fa-camera"></i></a>
<a href="#">TVs <i class="fa fa-"></i></a>
</div>
</div>
<a href="Subscription.html">Subcription</a>
<a href="#news">About Us</a>
<a href="#news">Contact</a>
<a style="float:right" href="#Sign Up">Sign Up <i class="fa fa-user-plus" aria-hidden="true"></i></a>
<a style="float:right" href="#Log In">Log in <i class="fa fa-sign-in" aria-hidden="true"></i></a>
</div>
答案 2 :(得分:0)
我已经制作了一个带有flexbox的片段,让你的两个都比较,请随时查看!
优点是无论宽度或项目数量如何,柔印箱都会适应。如果给出正确的属性,它们会自动将元素居中!
不再向左或向右浮动,flexboxes很容易处理。
/*Navigation Bar*/
.navbar {
overflow: hidden;
background-color: #000000;
font-family: "Century Gothic";
height: 40px;
margin-top: 3px;
}
.navbar a {
float: left;
font-size: 15px;
color: white;
text-align: center;
padding: 11px 13px;
text-decoration: none;
height: 40px;
}
.dropdown {
float: left;
overflow: hidden;
height: 40px;
}
.dropdown .dropbtn {
font-size: 15px;
font-family: "Century Gothic";
border: none;
outline: none;
color: white;
padding: 11px 13px;
background-color: inherit;
height: 40px;
}
.navbar a:hover,
.dropdown:hover .dropbtn {
background-color: #B64321;
}
.dropdown-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;
}
.dropdown-content a {
font-size: 13px;
font-family: "Century Gothic";
float: none;
color: black;
padding: 11px 13px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #F4DDD0;
}
.dropdown:hover .dropdown-content {
display: block;
}
/* ======================================================= */
.navbar-2 {
display: flex;
flex-wrap: nowrap;
background-color: #000000;
font-family: "Century Gothic";
height: 40px;
margin-top: 50px;
}
.left, .right {
display: flex;
}
.active-2 {
background-color: #FB724C;
}
.navbar-2 a {
flex: 1 1 auto;
font-size: 15px;
color: white;
text-align: center;
text-decoration: none;
padding: 0 13px;
display: flex;
justify-content: center;
align-items: center;
}
.navbar-2 a:hover { opacity: 0.8; }
.dropdown-content-2 {
display: none;
position: absolute;
z-index: 1;
top: 100%;
background-color: #f9f9f9;
min-width: 400px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown-2 {
display: flex;
position: relative;
}
.spacer { flex: 1 1 auto; }
.dropdown-2:hover .dropdown-content-2 {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: stretch;
flex-direction: row;
}
.dropdown-content-2 a {
flex: 1 1 33%;
font-size: 13px;
font-family: "Century Gothic";
color: black;
padding: 11px 13px;
text-decoration: none;
text-align: left;
box-sizing: border-box
}
<div class="navbar">
<a class="active" href="Index.html">Home</a>
<div class="dropdown">
<button class="dropbtn">Tech
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a href="#">Apple <i class="fa fa-apple"></i></a>
<a href="#">Android <i class="fa fa-android"></i></a>
<a href="#">Computers <i class="fa fa-desktop"></i></a>
<a href="#">Drones <i class="fa fa-camera"></i></a>
<a href="#">Photography <i class="fa fa-camera"></i></a>
<a href="#">TVs <i class="fa fa-"></i></a>
</div>
</div>
<a href="Subscription.html">Subcription</a>
<a href="#news">About Us</a>
<a href="#news">Contact</a>
<a style="float:right" href="#Sign Up">Sign Up <i class="fa fa-user-plus" aria-hidden="true"></i></a>
<a style="float:right" href="#Log In">Log in <i class="fa fa-sign-in" aria-hidden="true"></i></a>
</div>
<!-- ===================================================================== -->
<div class="navbar-2">
<div class="left">
<a class="active-2" href="Index.html">Home</a>
<div class="dropdown-2">
<a href="#tech" class="dropdown-2">Tech</a>
<div class="dropdown-content-2">
<a href="#">Apple <i class="fa fa-apple"></i></a>
<a href="#">Android <i class="fa fa-android"></i></a>
<a href="#">Computers <i class="fa fa-desktop"></i></a>
<a href="#">Drones <i class="fa fa-camera"></i></a>
<a href="#">Photography <i class="fa fa-camera"></i></a>
<a href="#">TVs <i class="fa fa-"></i></a>
</div>
</div>
<a href="Subscription.html">Subcription</a>
<a href="#news">About Us</a>
<a href="#news">Contact</a>
</div>
<span class="spacer"></span>
<div class="right">
<a href="#Sign Up">Sign Up <i class="fa fa-user-plus" aria-hidden="true"></i></a>
<a href="#Log In">Log in <i class="fa fa-sign-in" aria-hidden="true"></i></a>
</div>
</div>