CSS导航栏UL不居中

问题描述 投票:0回答:4

我正在学习如何根据http://www.hongkiat.com/blog/responsive-web-nav/教程制作响应式网站

我遇到了一个问题:我无法在NAV中找到合适的UL,并且仍然保留在屏幕上的UL中心。出于某种原因,即使

ul{display:inline-block;} 

nav{text-align:center;} 

链接#pull会将UL推向左侧,而不再使其居中。我想在NAV中将一个登录表格浮动到NAV的右边,其中#pull现在就在我的生活中我不知道如何在保持UL完全居中于屏幕的同时做到这一点,无论如何在UL的右边似乎推动了UL,尽管它应该始终居中。

我确定它只是一个基本的CSS定位问题,我无法弄清楚,因为我是新手,但我只需要更多的内容,我无法弄清楚如何。

的jsfiddle

html css css3 css-float
4个回答
2
投票

一种简单的方法是使用position css属性将“Menu”按钮放在UL上。确保使用position:relative属性设置nav标记,然后按菜单按钮并设置以下内容:

position:absolute;
top:0;
right:0;

这应该使菜单按钮保持在右上角,特别是在响应式网页设计的情况下。

见小提琴:http://jsfiddle.net/p3tK5/


1
投票

尝试添加

position:relative;
left: 8vw;

你的导航ul。 See this有关vw和vh等的更多信息。


0
投票

您在响应式设计中使用px而不是使用%

更新的CSS //所有宽度(%)

nav{
    height:50px;
    width:100%;
}

nav ul{
    padding:0;
    margin: 0 auto;     /*No Y-axis margin, Only an Auto X-axis margin, making the ul centered*/
    width:80%;  
}

nav li{
    list-style:none; /*display:inline; also gets rid of the list styles*/ 
    float:left;      /*Floating the menu list items to the left so they will be
                  displayed horizontally side by side, but floating an element
                      will also cause their parent to collapse*/
    dislay: inline-block;
    min-width: 23%;
}

#navaside {
    height:50px;
    width:15%;                          /* Takes up 100% of the parent's width, 
}

#navaside a#pull{

    color:#fff;                 /* Color of the link */
    display:inline-block;       /* display:block (also)--Allows the width and line height to actually take affect */
    width:100%;                /* 5 elements at 140px = 700px, the width of the 
}

检查http://jsfiddle.net/raunakkathuria/aF3Pd/7/

您可以根据您的要求设置样式或者li,我刚刚修复了一些css以使其响应


0
投票

只需在您的UL上添加display:table; margin: 0 auto即可。

© www.soinside.com 2019 - 2024. All rights reserved.