gpt4 book ai didi

html - 将下拉菜单居中对齐

转载 作者:行者123 更新时间:2023-11-28 10:26:55 24 4
gpt4 key购买 nike

我的下拉菜单的位置搞砸了。子元素未与父元素左侧对齐。我希望子元素的中心等于父元素的中心。

http://jsfiddle.net/H9L4G/

例如,对于测试 1,我希望它的子元素以测试 1 为中心。

<html>
<head>
<link href="test.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="navBar">
<ul id="nav">
<table width="100%">
<tr>
<td>
<li>
<a href="#">TEST</a>
<ul>
<li><a href="#"><table width="100%" ><tr>
<td width = "10%" align="center">1</td>
<td width = "60%" align="center">2</td>
<td width = "30%" align="center">3</td>
</tr></table></a></li>

</ul>
</li>
</td>

<td>
<li>
<a href="#">TEST2</a>
<ul>

<li><a href="#"><table width = "100%"><tr>
<td width = "10%" align="center">1</td>
<td width = "60%" align="center">2</td>
<td width = "30%" align="center">3</td>
</tr></table></a></li>

<li><a href="#"><table width = "100%"><tr>
<td width = "10%" align="center">4</td>
<td width = "60%" align="center">5</td>
<td width = "30%" align="center">6</td>
</tr></table></a></li>

<li><a href="#"><table width = "100%"><tr>
<td width = "10%" align="center">7</td>
<td width = "60%" align="center">8</td>
<td width = "30%" align="center">9</td>
</tr></table></a></li>

</ul>
</li>
</td>

<td>
<li>
<a href="#">TEST3</a>
</li>
</td>

</tr>
</table>
</ul>
</div><!--End of Navigation-->
</body>
</html>

#navBar {
width:100%
height: 100%
}

/*------------------------------------*\
NAV
\*------------------------------------*/
#nav{
list-style:none;
font-weight:bold;
margin-bottom:10 px;
/* Clear floats */
width:100%;
height:100%;
/* Bring the nav above everything else--uncomment if needed.
position:relative;
z-index:5;
*/
margin: 0 0 0 0;
padding: 0;
background-color: #f2f2f2;
border-bottom: 1px solid #ccc;
}
#nav li{
font-size:1em;
margin-right:10px;
position:relative;
width:100%;
}
#nav a{
text-align: center;
alignment-adjust: left;
display:block;
padding:2em;
color:#fff;
background:#333;
text-decoration:none;
}
#nav a:hover{
color:#fff;
background:#6b0c36;
text-decoration:underline;
}

/*--- DROPDOWN ---*/
#nav ul{
background:#fff; /* Adding a background makes the dropdown work properly in IE7+. Make this as close to your page's background as possible (i.e. white page == white background). */
background:rgba(255,255,255,0); /* But! Let's make the background fully transparent where we can, we don't actually want to see it if we can help it... */
list-style:none;
position:absolute;
left:-9999px; /* Hide off-screen when not needed (this is more accessible than display:none;) */
width:100%;

}
#nav ul li{
width: 100%;
padding-top:1px; /* Introducing a padding between the li and the a give the illusion spaced items */
float:none;
}
#nav ul a{

width: 100%;
white-space:nowrap; /* Stop text wrapping and creating multi-line dropdown items */
}
#nav li:hover ul{ /* Display the dropdown on hover */
border-left:0px;
left: 0; /* Bring back on-screen when needed */
}
#nav li:hover a{ /* These create persistent hover states, meaning the top-most link stays 'hovered' even when your cursor has moved down the list. */
background:#6b0c36;
text-decoration:underline;
}
#nav li:hover ul a{ /* The persistent hover state does however create a global style for links even before they're hovered. Here we undo these effects. */
text-decoration:none;
}
#nav li:hover ul li a:hover{ /* Here we define the most explicit hover states--what happens when you hover each individual link. */
background:#333;
}

最佳答案

左推来自 ul填充。只需添加 padding: 0到内部<ul> .宽度也由 width: 100% 扩展 anchor 。

http://jsfiddle.net/H9L4G/1/

关于html - 将下拉菜单居中对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23702777/

24 4 0