窗口上的CSS调整大小,列出菜单中的项目

时间:2013-07-11 15:51:27

标签: css twitter-bootstrap grid

img http://gyazo.com/63259876590cdf2353e3b9e759f9f8bf.png;

如果我要调整屏幕大小或进入小型计算机屏幕,会发生这种情况。

这就是应该的样子(我的桌面屏幕尺寸为100%):

img2 http://gyazo.com/dad037d3f638e5d98de61e34b5c363de.png;

为什么会这样?可能需要自动检查宽度和使用百分比? 我不确定..

这是我的代码。

HTML:

    <div id="menu">
        <ul id="menuitems">
            <li id="menu-active"><a href="#" >HOMEPAGE</a></li></a>
            <li><a href="#">PLAY NOW</a></li>
            <li><a href="#">COMMUNITY</a></li>
            <li><a href="#">HUNGER WIKI</a></li>
            <li><a href="#">HIGHSCORES</a></li>
            <li><a href="#">HELP</a></li>
            <li><div id="login"></div></li>
        </ul>
    </div>

CSS:

body {
    background-color: #1e1e1e;
    /*background-image: url("../img/background.png");*/
    background-repeat: no-repeat;
    background-position: center top;
    color: #fff;
    font-size: 14px;
}

#logo {
    background-image: url("../img/logo.png");
    background-repeat: no-repeat;
    width: 465px;
    height: 126px;
    margin-left: 24%;
    margin-top: 3%;
}

#menu { 
    background-image: url("../img/gradient-header.png");
    background-repeat: repeat;
    width: 100%;
    height: 56px;
    border: solid 1px #000;
    font-weight: bold;
}

#menuitems {
padding: 0;
margin: 0;
float: left;
}

#menuitems li {
    background-image: url("../img/gradient-header.png");
    background-repeat: repeat;  
    display: inline-block;
    width: 140px;
    height: 56px;
    background-color: white;
    float: left;
    border-right: solid 1px #44acbf;
    border-left: solid 1px #114a56;
    line-height: 56px;
    text-align: center;
    -webkit-transition: all 200ms ease-in-out;
        -moz-transition: all 200ms ease-in-out;
        -ms-transition: all 200ms ease-in-out;
        -o-transition: all 200ms ease-in-out;
        transition: all 200ms ease-in-out;      
}

#menuitems li:hover {
    background-image: url("../img/gradient-1.png");
    background-repeat: repeat;  
    border-right: solid 1px #2b6e81;
    cursor: pointer;
    -webkit-transition: all 200ms ease-in-out;
        -moz-transition: all 200ms ease-in-out;
        -ms-transition: all 200ms ease-in-out;
        -o-transition: all 200ms ease-in-out;
        transition: all 200ms ease-in-out;  
}

#menuitems li:active {
    background-image: url("../img/gradient-onClick-menu.png");
    background-repeat: repeat;  
}

#menuitems li:last-child {
    width: 88px;
    border-right: solid 0px transparent;
}

#menu-active {
    background-image: url("../img/gradient-1.png") !important;
    background-repeat: repeat !important;   
    border-right: solid 1px #2b6e81 !important;
}

#menuitems li:first-child {
    border-left: solid 0px transparent;
}

#login {
    background-image: url("../img/icon.png");
    background-repeat: no-repeat;
    margin-left: 32%;   
    margin-top: 20%;    
    width: 25px;
    height: 21px;
}

#menuitems a {
    width: 140px;
    height: 56px;
    color: #fff;
}

我通过bootstrap框架将.container用作容器。

1 个答案:

答案 0 :(得分:0)

菜单项上有一个固定的width。这意味着它们总是保持相同的大小,如果在一条线上没有足够的空间,它们将分成下一行