css:在html5中调整窗口大小时如何使导航列表居中

时间:2014-09-05 09:16:06

标签: css html5

这是我在css中的代码:

*
{
    box-sizing:border-box;  
}
div,body,html,h1,nav,article,footer,header{display:block;}
body
{
    margin:0;
    padding:0;  
    font-family:Arial;
    font-size:14px;
    background-color:#fff;
}
#wrapper
{
    margin-left: auto;
    margin-right: auto;
}
.title p
{
    text-align:center;
    color:  darkgray;
}
img
{
    vertical-align:middle;  
    margin:0;
}
#slideshow {
    position: relative;
    overflow: hidden;
    height: 100px;
}
 #fixme
{    
    height : 175px;
    position: relative;
    overflow : hidden;
}
#animate-area 
{ 
    height: 122%;
    width: 2538px;
    position: absolute;
    left: 0;
    top: -15px;
    background-image: url('../img/banner.png');
    background-repeat: repeat-x;
    -ms-animation: animatedBackground 40s linear infinite;
    -moz-animation: animatedBackground 40s linear infinite;
    -webkit-animation: animatedBackground 30s linear infinite;
}
    /* Put your css in here */
    @keyframes animatedBackground {
        from { left: 0; }
        to { left: -1269px; }
    }
    @-webkit-keyframes animatedBackground {
        from { left: 0; }
        to { left: -1269px; }
    }
    @-moz-keyframes animatedBackground {
        from { left: 0; }
        to { left: -1269px; }
 }
#logo img
 {
    position:absolute;  
    z-index:999;
    vertical-align:middle;
 }   
 h1
 {  
    text-align:center;
    text-align: center;
    font-size: 35px;
    font-weight: 100;
    margin-top:25px;
    margin-bottom: inherit;
 }
 .header-pgf
{
    width: 67%;
    font-size: 15px;
    font-family: verdana;
    margin: auto;   
    margin-top:15px;
}
.nav
{       
    background: -webkit-gradient(linear, left top, left bottom, from(#b9b9b9), to(#000));
    background: linear-gradient(0deg, red, yellow);
    margin-top:40px;
    height:45px;
}
.nav ul li
{
    display:inline-block;
    text-align:center;
}
.nav > ul li:first-child a
{
    background-color:Red;
}
.nav > ul li:first-child a:hover
{
    text-decoration:underline;
}
.nav li:hover a 
{
    background-color: red;
}
.nav li a 
{
    color: #000;
    display: block;
    padding: 14px 25px;
    text-decoration: none;
}

HTML5:

<nav class="nav">
<ul>
<li><a href="#">HOME</a></li>
<li><a href="#">COMPANY</a></li>
<li><a href="#">MARKETS/SOLUTIONS</a></li>
<li><a href="#">PRODUCTS/SERVICES</a></li>
<li><a href="#">BUSINESSES</a></li>
<li><a href="#">INVESTERS</a></li>
</ul>
</nav>

我的页面看起来像这样(调整大小时):http://s14.postimg.org/jggi59co1/Untitled_1_copy.png

正如我在图像中标记的那样,在调整窗口大小时,列表需要放置中心。有人可以帮我解决这个问题吗?

提前致谢。

2 个答案:

答案 0 :(得分:0)

text-align适用于内联和内联块子元素
您正尝试将此属性设置为元素本身

尝试将文本对齐设置为导航。

这有用吗?

答案 1 :(得分:0)

将其添加到ultext-align: center

由于您的li设置为display: inline-block,因此您应将其直接父text-align设置为center,即ul < / p>