【问题标题】:How to fix the alignment of my sub-menu如何修复我的子菜单的对齐方式
【发布时间】: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>

这是一个活生生的例子

http://jsfiddle.net/B7a5f/

现场示例当然有点混乱,但大多数情况下担心的是它的位置太靠右了,而且比我喜欢的要高。

【问题讨论】:

标签: html css drop-down-menu alignment


【解决方案1】:
   ul.nav{
    text-decoration: none;
    display: table-cell;
        padding: 0px;
        margin:0;
        float:left;
    }

【讨论】:

  • @Cristian Rubini 它确实解决了问题,但有没有办法让文本居中对齐?
  • ul.nav{ text-decoration: none; display: table-cell; padding: 0px; list-style: ; margin:0; float:left; text-align:center; width:100%; } ul li.nav{ float: left; width: 100%; text-align: center; background:transparent; text-decoration: none; list-style-type: none; }
  • 虽然现在父级的大小增加了,但确实做到了。如果您只想告诉我要专门查看什么来修复它,那很好。很抱歉打扰您,感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 2015-12-24
  • 1970-01-01
  • 2013-12-10
  • 2021-11-08
  • 2014-07-20
  • 1970-01-01
  • 2013-02-13
  • 2021-01-07
相关资源
最近更新 更多