【发布时间】:2015-05-19 16:22:14
【问题描述】:
我试图将 UL 标记置于 DIV 中,但遇到了一些问题。我已经尝试了很多东西。代码附在下面。 UL 是一个水平列表。
<!-- Header -->
<div id="header">
<div class="container">
<!-- Nav -->
<nav id="nav">
<ul>
<li <?php if($currenturl == 'index.php') { ?>class="active"<?php } ?>><a href="index.php">Home</a></li>
<li <?php if($currenturl == 'limitededitions.php') { ?>class="active"<?php } ?>><a href="limitededitions.php">Limited Editions</a></li>
<li <?php if($currenturl == 'left-sidebar.php') { ?>class="active"<?php } ?>><a href="left-sidebar.php">Products</a></li>
<li <?php if($currenturl == 'services.php') { ?>class="active"<?php } ?>><a href="services.php">Services</a></li>
<li <?php if($currenturl == 'suppliers.php') { ?>class="active"<?php } ?>><a href="suppliers.php">Suppliers</a></li>
<li <?php if($currenturl == 'right-sidebar.php') { ?>class="active"<?php } ?>><a href="right-sidebar.php">About</a></li>
<li <?php if($currenturl == 'no-sidebar.php') { ?>class="active"<?php } ?>><a href="no-sidebar.php">Contact</a></li>
<li><a target="_blank" href="https://www.paypal.com/cgi-bin/webscr?cmd=_cart&business=WEM898SE24RZL&display=1">View Cart</a></li>
</ul>
</nav>
</div>
</div>
<!-- Header -->
/*********************************************************************************/
/* Header */
/*********************************************************************************/
#header
{
position: relative;
background: #FFF;
}
#header .container
{
position: relative;
padding: 3em 0em;
}
/*********************************************************************************/
/* Nav */
/*********************************************************************************/
#nav
{
position: relative;
top: 1em;
}
#nav > ul > li
{
float: left;
}
#nav > ul > li:last-child
{
padding-right: 0;
}
#nav > ul > li > a,
#nav > ul > li > span
{
display: block;
padding: 0.80em 1.2em;
letter-spacing: 0.06em;
text-decoration: none;
text-transform: uppercase;
font-size: 1.1em;
outline: 0;
color: #333;
}
#nav li.active a
{
background: #8B5A2B;
border-radius: 5px;
color: #FFF;
}
#nav > ul > li > ul
{
display: none;
}
任何帮助将不胜感激!谢谢。
【问题讨论】:
-
如何你想把这个居中?我在您的代码中没有看到任何
text-align:center或margin:0 auto属性。甚至没有<center>! -
我试过 margin-left: auto;边距右:自动;文本对齐:居中;边距:0 自动;左:50% 和左:-50%;都在很多地方。我是css的初学者这是我最差的技能哈哈。我只是很困惑,因为它是一个 div 中的一个 div,我已经认真尝试了两个小时,但不知道该放在哪里。
标签: html css class center centering