在导航栏中向菜单添加文本会将按钮关闭。

时间:2014-05-19 08:19:51

标签: html css menu positioning navbar

这是我第一次发帖提问,所以希望我没有违反任何指挥官 - 这就是我的问题:

我为我的网站制作了一个导航栏,如下所示。但是,每当我添加文本时(请参阅:Home),它都会将菜单按钮从导航栏上移开。我试图修补边距和填充,但无济于事。如果需要,我会在下面的网站上添加完整的HTML。

谢谢大家!

编辑:我已经做了一个jsfiddle来更好地说明我的观点。

http://jsfiddle.net/6JK3E/

<div id="nav">

            <div class="menubutton">

                    <div class="menustyle">

                        <a href="#">

                            Home

                        </a>

                    </div>

                </a>

            </div>

            <div class="menubutton">

            </div>

            <div class="menubutton">

            </div>

            <div class="menubutton">

            </div>

            <div class="menubutton">

            </div>

            <div class="lastmenubutton">

            </div>

相关CSS:

    #wrapper
{
width:950;
height:100%;
margin:0px auto 0px auto;
-webkit-box-shadow: 0px 0px 16px 0px rgba(50, 50, 50, 0.75);
-moz-box-shadow:    0px 0px 16px 0px rgba(50, 50, 50, 0.75);
box-shadow:         0px 0px 16px 0px rgba(50, 50, 50, 0.75);
min-height: 1045px;
background-color: white;
}

#header
{
width: 950px;
margin: 0px auto 0px auto;
height: 200px;
}

#logo
{
width: 950px;
margin: 0px auto 0px auto;
height: 140px;
background-image: url("../img/logo.png");
background-repeat: no-repeat;
}

#bluebar1
{
width: 950px;
margin: 0px auto 0px auto;
height: 10px;
border-bottom: 1px solid rgba(86, 177, 255, 1);
background-color: rgba(103, 185, 255, 0.43);
}

#bluebar2
{
width: 950px;
margin: 0px auto 0px auto;
height: 10px;
border-top: 1px solid rgba(86, 177, 255, 1);
background-color: rgba(103, 185, 255, 0.43);
margin-top: -1px;
}

#bluebar3
{
width: 950px;
margin: 0px auto 0px auto;
height: 10px;
border-top: 1px solid rgba(86, 177, 255, 1);
background-color: rgba(103, 185, 255, 0.43);
margin-top: 1px;
}

#nav
{
width: 950px;
margin: 0px auto 0px auto;
height: 50px;
border-top: 1px solid rgba(177, 177, 177, 0.47);
}

.menubutton
{
width: 144px;
height: 48px;
background-color: white;
display: inline-block;
text-align: center;
padding-left: 5px;
padding-right: 5px;
border-right: 1px solid rgba(177, 177, 177, 0.47);
}

.lastmenubutton
{
width: 144px;
height: 48px;
background-color: white;
display: inline-block;
text-align: center;
padding-left: 5px;
padding-right: 5px;
}

/*** Menu Buttons ***/

.menustyle
{   
font-family: 'Bree Serif', serif;
font-size: 18px;
color: rgb(0, 54, 80);
}

/***                       ***/

完整网站HTML和CSS:

    <html>

    <title>BlueCloudGaming</title>

    <link rel="stylesheet" type="text/css" href="stylesheet/style.css"/>

    <meta charset="utf-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="description" content="">

    <meta name="author" content="">

    <link rel="shortcut icon" href="../img/favicon.ico">

    <!-- Google Fonts -->

    <link href='http://fonts.googleapis.com/css?family=Droid+Sans:400,700|Lora|Open+Sans|Bree+Serif' rel='stylesheet' type='text/css'>

<head>

</head>

<body>

<div id="wrapper">

    <div id="header">

        <div id="bluebar1">

        </div>

        <div id ="logo">

        </div>

        <div id="nav">

            <div class="menubutton">

                    <div class="menustyle">

                        <a href="#">

                            Home

                        </a>

                    </div>

                </a>

            </div>

            <div class="menubutton">

                <a href="#">

                    Home

                </a>

            </div>

            <div class="menubutton">

            </div>

            <div class="menubutton">

            </div>

            <div class="menubutton">

            </div>

            <div class="lastmenubutton">

            </div>

        </div>

        <div id="bluebar2">

        </div>

    </div>

    <div id="content">

        <div id="servertitlewrap">

            <div class="servertitle">

                <a href="#"><div class="servertitlefont">

                    Trouble in Terrorist Town

                </div>

                <div class="serverp">

                    Click to connect!

                </div></a>

            </div>

                <div class="servertitlediv">

                </div>

            <div class="servertitle">

                <a href="#"><div class="servertitlefont">

                    DarkRP v.3.1.6b

                </div>

                <div class="serverp">

                    Click to connect!

                </div></a>

            </div>

                <div class="servertitlediv">

                </div>

            <div class="servertitle">

                <a href="#"><div class="servertitlefont">

                    Starbound

                </div>

                <div class="serverp">

                    Click to connect!

                </div></a>

            </div>

        </div>

        <div id="textwrapper">

            <div class="textblock">

                <div class="servertextstyle">
                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas a massa turpis. Vestibulum quis odio a sapien suscipit congue eget ut justo. Phasellus lectus ligula, egestas ac leo sed, lacinia convallis mi. Nam dapibus, purus a iaculis vulputate. Nam dapibus, purus.
                </div>

            </div>

                <div class="blockdivider">

                </div>

            <div class="textblock">

                <div class="servertextstyle">
                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas a massa turpis. Vestibulum quis odio a sapien suscipit congue eget ut justo. Phasellus lectus ligula, egestas ac leo sed, lacinia convallis mi. Nam dapibus, purus a iaculis vulputate. Nam dapibus, purus.
                </div>

            </div>

                <div class="blockdivider">

                </div>

            <div class="textblock">

                <div class="servertextstyle">
                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas a massa turpis. Vestibulum quis odio a sapien suscipit congue eget ut justo. Phasellus lectus ligula, egestas ac leo sed, lacinia convallis mi. Nam dapibus, purus a iaculis vulputate. Nam dapibus, purus.
                </div>

            </div>

        </div>

        <div id="serverwrapper">

            <div class="serverblock">

                <div class="borderadius"><img src="img/server1.png">

                </img></div>

            </div>

                <div class="blockdivider">

                </div>

            <div class="serverblock">

                <div class="borderadius"><img src="img/server2.png">

                </img></div>

            </div>

                <div class="blockdivider">

                </div>

            <div class="serverblock">

                <div class="borderadius"><img src="img/server3.png">

                </img></div>

            </div>

        </div>

        <div id="bannerpic">

        </div>

    </div>

    <div id="footer">

        <div id="servers">

        </div>

            <div id="footdivider">

            </div>

        <div id="footlogo">

        </div>

    </div>

    <div id="bluebar3">

        </div>

</div>

</body>

</html>

该网站的完整CSS:

    html
{
height: 100%;
}

body
{
height: 100%;
background-color: white;
margin: 0px 0px 0px 0px;
background-image: url("../img/sky2.jpg");
}

a
{
text-decoration:none;
}

#wrapper
{
width:950;
height:100%;
margin:0px auto 0px auto;
-webkit-box-shadow: 0px 0px 16px 0px rgba(50, 50, 50, 0.75);
-moz-box-shadow:    0px 0px 16px 0px rgba(50, 50, 50, 0.75);
box-shadow:         0px 0px 16px 0px rgba(50, 50, 50, 0.75);
min-height: 1045px;
background-color: white;
}

#header
{
width: 950px;
margin: 0px auto 0px auto;
height: 200px;
}

#logo
{
width: 950px;
margin: 0px auto 0px auto;
height: 140px;
background-image: url("../img/logo.png");
background-repeat: no-repeat;
}

#bluebar1
{
width: 950px;
margin: 0px auto 0px auto;
height: 10px;
border-bottom: 1px solid rgba(86, 177, 255, 1);
background-color: rgba(103, 185, 255, 0.43);
}

#bluebar2
{
width: 950px;
margin: 0px auto 0px auto;
height: 10px;
border-top: 1px solid rgba(86, 177, 255, 1);
background-color: rgba(103, 185, 255, 0.43);
margin-top: -1px;
}

#bluebar3
{
width: 950px;
margin: 0px auto 0px auto;
height: 10px;
border-top: 1px solid rgba(86, 177, 255, 1);
background-color: rgba(103, 185, 255, 0.43);
margin-top: 1px;
}

#nav
{
width: 950px;
margin: 0px auto 0px auto;
height: 50px;
border-top: 1px solid rgba(177, 177, 177, 0.47);
}

.menubutton
{
width: 144px;
height: 48px;
background-color: white;
display: inline-block;
text-align: center;
padding-left: 5px;
padding-right: 5px;
border-right: 1px solid rgba(177, 177, 177, 0.47);
}

.lastmenubutton
{
width: 144px;
height: 48px;
background-color: white;
display: inline-block;
text-align: center;
padding-left: 5px;
padding-right: 5px;
}

/*** Menu Buttons ***/

.menustyle
{   
font-family: 'Bree Serif', serif;
font-size: 18px;
color: rgb(0, 54, 80);
}

/***                       ***/

#content
{
width:950px;
height:600px;
margin-top:10px;
}

#textwrapper
{
width: 950px;
height: 250px;
background-color: white;
text-align: center;
}

#serverwrapper
{
width: 950px;
height: 220px;
background-color: white;
text-align: center;
}

.textblock
{
display: inline-block;
height: 200px;
width: 250px;
background-color: azure;
margin-top: 25px;
border:1px solid rgba(177, 177, 177, 0.47);
overflow:hidden;
border-radius:5px;
}

.blockdivider
{
width:40px;
display:inline-block;
}

/* ----------------- */

#servertitlewrap
{
width: 950px;
height: 100px;
background-color: rgb(213, 213, 213);
text-align: center;
border-bottom: 1px solid rgba(177, 177, 177, 0.77);
}

.servertitle
{
display: inline-block;
height: 50px;
width: 250px;
background-color: rgba(166, 214, 255, 1);
margin-top: 25px;
border: 1px solid rgba(255, 255, 255, 1);
overflow: hidden;
border-radius: 5px;
box-shadow: 0px 0px 2px 0px rgba(50, 50, 50, 0.75);
}

.servertitlediv
{
width:40px;
display:inline-block;
}

.servertitlefont
{
font-family: 'Bree Serif', serif;
font-size:18px;
margin-top:4px;
color: rgb(0, 54, 80);
}

.serverp
{
font-family: 'Droid Sans', sans-serif;
font-size:12px;
color: dimgray;
}

/* ----------------- */

.serverblock
{
display: inline-block;
height: 160px;
width: 250px;
background-color: azure;
margin-top: 25px;
border: 1px solid rgba(107, 107, 107, 1);
overflow: hidden;
border-radius: 5px;
box-shadow: 0px 0px 10px 0px rgba(50, 50, 50, 0.75);
}

#bannerpic
{
width:950px;
height:100px;
border-top: 1px solid rgba(177, 177, 177, 0.47);
border-bottom: 1px solid rgba(177, 177, 177, 0.47);
}

#footer
{
height: 152px;
width: 950px;
margin-top:70px;
}

#servers
{
width: 300px;
height: 150px;
background-color: rgba(166, 214, 255, 1);
border-right: 1px solid rgba(177, 177, 177, 0.47);
margin-top: 3px;
display: inline-block;
}

#footlogo
{
width: 300px;
height: 150px;
background-color: rgba(166, 214, 255, 1);
border-left: 1px solid rgba(177, 177, 177, 0.47);
margin-top: 3px;
display: inline-block;
}

#footdivider
{
width: 340px;
height: 150px;
display: inline-block;
}

.servertextstyle
{
padding: 15px;
text-align: justify;
font-family: 'Open Sans', sans-serif;
font-size: 14px;
}

.borderadius
{
border-radius:5px;
}

3 个答案:

答案 0 :(得分:0)

您有一个额外的结束</a>标记。删除它。

您还应该有DOCTYPE声明,标题等详细信息应该在head-tag中。

..而且img没有结束标记。

答案 1 :(得分:0)

THIS你要做的是什么?我更改并添加了一些 CSS 。 我把display:inline-block放在导航

#nav{
display:inline-block;
}

并添加

.menubutton{
float:left;
}

答案 2 :(得分:0)

vertical-align: top添加到.menubutton或删除高度,然后添加line-height以使文本垂直居中,(注意:行高只适用于一行文字,否则它将是一团糟)