【发布时间】:2014-05-22 22:19:15
【问题描述】:
我正在尝试完善导航栏,目前唯一的错误是下拉菜单的对齐方式。无论如何都可以将它相对于它所在的 td 定位而不重新执行我的所有代码?如果不是,我将如何从菜单中降低子菜单。
这是我的 CSS
ul.nav{
text-decoration: none;
display: table-cell;
padding: 0px;
list-style: ;
}
ul li.nav{
float: left;
width: 100%;
text-align: center;
background:transparent;
text-decoration: none;
list-style-type: none;
}
ul li.nav:hover{
float: left;
width: 100%;
text-align: center;
background-color:transparent;
text-decoration: none;
list-style-type: none;
}
ul li.nav2{
float: left;
width: 70%;
text-align: left;
background:#313131;
text-decoration: none;
list-style-type: none;
}
ul li a{
display: block;
padding: 0px 0px;
color: white;
background:#313131;
text-decoration: none ;
}
ul li a.nav:hover{
text-align: left;
color: white;
background:transparent;
}
ul li ul.nav{
width: 25%;
display: none ;
}
ul li.nav:hover ul{
float: center;
opacity: .87;
position: absolute;
display: block; /* display the dropdown */
}
td.nav:hover{
background-color:#703f70;
color: #703f70;
}
a:link {
color: white;
background-color: transparent;
}
a:hover {
color: #5be5e5 ;
background-color: #703f70;
}
a.amber:hover {
color: ;
background-color: transparent ;
}
input {
font: 13.5pt arial;
color: #5be5e5;
margin: 0px;
padding-top: 5px;
padding-left: 5px;
padding-bottom: 5px;
display: ;
background: #703f70;
border-color: #b266b2;
font-weight:bold;
}
input:hover {
color: #5be5e5;
background: #b266b2;
border-color: #703f70;
}
</style>
这是我的 HTML
<table width="95%" align="center" valign="bottom"
<tr>
<td width="11%" bgcolor="#313131">
</td>
<td class="nav" bordercolor="#313131" bgcolor="#313131" align="center" valign="bottom" width="12.25%">
<ul class="nav"><li class="nav">
<a href="homepage.html"><font size="3"><b>
<img src="graphics/homeicon1.png" width="25" height="25">
<br>
Home Page
</b></font></a>
</li></ul>
</td>
<td class="nav" bordercolor="#313131" bgcolor="#313131" align="center" valign="bottom" height="1" width="12.25%">
<ul class="nav">
<li class="nav"><a href="contentpage.html"> <img src="graphics/contenticon1.PNG" width="20" height="25"> <br> <font size="3"><b> <img src="graphics/dropdownarrowlefticon1.PNG" width="10" height="10"> Content Page <img src="graphics/dropdownarrowrighticon1.PNG" width="10" height="10"> </b></font> </a>
<ul class="nav">
<li class="nav2"><a href="interactivewebsitespage.html"><font size="5"><b> <img src="graphics/interactiveicon1.png" width="20" height="20"> Interactive </b></font></a></li>
<li class="nav2"><a href="noninteractivewebsitespage.html"><font size="5"><b> <img src="graphics/noninteractiveicon1.png" width="20" height="20"> Noninteractive </b></font></a></li>
<li class="nav2"><a href="videogamespage.html"><font size="5"><b> <img src="graphics/videogamesicon1.png" width="20" height="15"> Video Games</b></font></a></li>
<li class="nav2"><a href="youtubevideospage.html"><font size="5"><b> <img src="graphics/youtubevideosicon1.png" width="20" height="20"> Youtube Videos</b></font></a></li>
</li class="nav">
</ul class="nav">
</td>
<td class="nav" bordercolor="#313131" bgcolor="#313131" align="center" valign="bottom" width="12.25%">
<ul class="nav">
<li class="nav">
<a href="infopage.html"><font size="3"><b>
<img src="graphics/infoicon1.PNG" width="25" height="25">
<br>
Info Page
</b></font></a>
</li></ul>
</td>
<td class="nav" bordercolor="#313131" bgcolor="#313131" align="center"valign="bottom" width="12.25%">
<ul class="nav"><li class="nav">
<a href="pollpage.html"><font size="3"><b>
<img src="graphics/pollicon1.PNG" width="25" height="25">
<br>
Poll Page
</li></ul>
</b></font></a></li>
</td>
<td width="11%" bgcolor="#313131">
</td>
</tr>
</table>
这是一个活生生的例子
现场示例当然有点混乱,但大多数情况下担心的是它的位置太靠右了,而且比我喜欢的要高。
【问题讨论】:
-
请不要对表格进行布局......这是 1980 年代。
-
@Paulie_D 没问题。让我们使用 div。
-
老兄,使用 html 和 css。它可以在 10 行中完成
标签: html css drop-down-menu alignment