如何在"菜单边框内移动菜单"

时间:2014-07-26 16:47:28

标签: html css menu position

正如标题所说,我正试图在边框菜单中移动菜单。我是新手,因为他们理论上是链接,我认为它会是这样的。 a {position:absolute然后我会选择我希望他们去的地方。除此之外,还有一个我需要随之移动的子菜单。有任何想法吗?谢谢!我想将菜单移到边框内的右下角。

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" type="text/css" href="videos.css" />
<link rel="stylesheet" type="text/css" href="vines.css" />
<title>Puppy Power</title>
</head>
<body>
        <div id="page">
<header></header>
        <div id="dog logo">
    </div>

<ul id="navigation">
        <li><a href="index.html">Home</a></li>
        <li><a href="videos.html">Videos</a>
            <ul class="sub">
                <li><a href="vines.html">Vines</a></li>
                <li><a href="#">Pugs</a></li>
                <li><a href="#">Failing Dogs</a></li>
                <li><a href="#">Crazy Dogs</a></li>
                <li><a href="#">Funny Dogs</a></li>

            </ul>
        </li>


        <li><a href="#">Photographs</a></li>    
        <li><a href="#">Articles</a></li>
        <li><a href="#">Contact</a></li>
    </ul>

<div id="hero"><h1><b>HERO</b></h1></div>


<div id="topvideo"><h1><b>TOP VIDEO</b></h1></div>

<div id="topphoto"><h1><b>TOP PHOTO</b></h1></div>

<div id="toparticles"><h1><b>TOP ARTICLE</b></h1></div>

<div id="content"><h1><b>CONTENT</b></h1></div>

<div id="footer"><h1><b>FOOTER</b></h1></div>

</body>
</html>

#page {
    max-width: 850px;
    min-width: 840px;
    min-height: 1550px;
    max-height: 1600px;
} 

* {
    margin: 0px;
    padding: 0px;
}



#navigation {
    border: 1px solid #89cFF0;
    width: 813px;
    height: 187px;
    margin-left: 5px;

}



ul #navigation, .sub {
    list-style-type: none;


}

ul #navigation li {
    border: 1px solid #89cFF0;
    width: 125px;
    text-align: center;
    position: relative;
    float: left;
    list-style-type: none;
}

ul #navigation a {
    text-decoration: none;
    display: block;
    width: 125px;
    height: 25px;
    line-height: 25px;
    border: 1px solid #89cFF0;
}

ul #navigation li:hover > a {
    background-color: #89cFF0;
}



#hero {
    width: 813px;
    height: 408px;
    border-top: 1px solid #89cff0;
    border-bottom: 1px solid #89cff0;
    border-left: 1px solid #89cff0;
    border-right: 1px solid #89cff0;
    display: inline-block;
    margin: 5px 0px 0px 0px;
    text-align: center;
    color: red;

}

#topvideo {
    width: 267px;
    height: 370px;
    border-top: 1px solid #89cff0;
    border-bottom: 1px solid #89cff0;
    border-left: 1px solid #89cff0;
    border-right: 1px solid #89cff0;
    display: inline-block;
    vertical-align:top;
    text-align: center;
    margin: 5px 0px 5px 0px;



}

#topphoto {
    width: 267px;
    height: 370px;
    border-top: 1px solid #89cff0;
    border-bottom: 1px solid #89cff0;
    border-left: 1px solid #89cff0;
    border-right: 1px solid #89cff0;
    display: inline-block;
    vertical-align:top;
    text-align: center;
    margin: 5px 0px 5px 0px;

}

#toparticles {
    width: 267px;
    height: 370px;
    border-top: 1px solid #89cff0;
    border-bottom: 1px solid #89cff0;
    border-left: 1px solid #89cff0;
    border-right: 1px solid #89cff0;
    display: inline-block;
    vertical-align:top;
    text-align: center;
    margin: 5px 0px 5px 0px;
}

#content {
    width: 813px;
    height: 310px;
    border-top: 1px solid #89cff0;
    border-bottom: 1px solid #89cff0;
    border-left: 1px solid #89cff0;
    border-right: 1px solid #89cff0;
    margin: 0px 0px 0px 0px;
    text-align: center;
}

#footer {

    width: 813px;
    height: 100px;
    border-top: 1px solid #89cff0;
    border-bottom: 1px solid #89cff0;
    border-left: 1px solid #89cff0;
    border-right: 1px solid #89cff0;
    margin: 5px 0px 0px 0px;
    text-align: center;
}

1 个答案:

答案 0 :(得分:0)

你的CSS的问题在你的选择器中,你继续将#navigation置于不应该去的地方,这会破坏你的CSS。例如,您的li的规则是:

ul #navigation li {
    border: 1px solid #89cFF0;
    width: 125px;
    text-align: center;
    position: relative;
    float: left;
    list-style-type: none;
}

HTML就是这样:

<ul id="navigation">
        <li><a href="index.html">Home</a></li>
        <li><a href="videos.html">Videos</a>
            <ul class="sub">
                <li><a href="vines.html">Vines</a></li>
                <li><a href="#">Pugs</a></li>
                <li><a href="#">Failing Dogs</a></li>
                <li><a href="#">Crazy Dogs</a></li>
                <li><a href="#">Funny Dogs</a></li>

            </ul>
        </li>


        <li><a href="#">Photographs</a></li>    
        <li><a href="#">Articles</a></li>
        <li><a href="#">Contact</a></li>
    </ul>

您的CSS正在尝试设置<li>的样式,该<ul>是#navigation的子项,它是#navigation li { border: 1px solid #89cFF0; width: 125px; text-align: center; float: left; list-style-type: none; } 的子项,没有,因为ul是#navigation。你应该这样选择它:

#page {
    max-width: 850px;
    min-width: 840px;
    min-height: 1550px;
    max-height: 1600px;
} 

* {
    margin: 0px;
    padding: 0px;
}



#navigation {
    border: 1px solid #89cFF0;
    width: 813px;
    height: 187px;
    margin-left: 5px;

}



#navigation , .sub {
    list-style-type: none;


}

#navigation li {
    border: 1px solid #89cFF0;
    width: 125px;
    text-align: center;
    float: left;
    list-style-type: none;
}

#navigation   a {
    text-decoration: none;
    display: block;
    width: 125px;
    height: 25px;
    line-height: 25px;
    border: 1px solid #89cFF0;
}

#navigation   li:hover > a {
    background-color: #89cFF0;
}



#hero {
    width: 813px;
    height: 408px;
    border-top: 1px solid #89cff0;
    border-bottom: 1px solid #89cff0;
    border-left: 1px solid #89cff0;
    border-right: 1px solid #89cff0;
    display: inline-block;
    margin: 5px 0px 0px 0px;
    text-align: center;
    color: red;

}

#topvideo {
    width: 267px;
    height: 370px;
    border-top: 1px solid #89cff0;
    border-bottom: 1px solid #89cff0;
    border-left: 1px solid #89cff0;
    border-right: 1px solid #89cff0;
    display: inline-block;
    vertical-align:top;
    text-align: center;
    margin: 5px 0px 5px 0px;



}

#topphoto {
    width: 267px;
    height: 370px;
    border-top: 1px solid #89cff0;
    border-bottom: 1px solid #89cff0;
    border-left: 1px solid #89cff0;
    border-right: 1px solid #89cff0;
    display: inline-block;
    vertical-align:top;
    text-align: center;
    margin: 5px 0px 5px 0px;

}

#toparticles {
    width: 267px;
    height: 370px;
    border-top: 1px solid #89cff0;
    border-bottom: 1px solid #89cff0;
    border-left: 1px solid #89cff0;
    border-right: 1px solid #89cff0;
    display: inline-block;
    vertical-align:top;
    text-align: center;
    margin: 5px 0px 5px 0px;
}

#content {
    width: 813px;
    height: 310px;
    border-top: 1px solid #89cff0;
    border-bottom: 1px solid #89cff0;
    border-left: 1px solid #89cff0;
    border-right: 1px solid #89cff0;
    margin: 0px 0px 0px 0px;
    text-align: center;
}

#footer {

    width: 813px;
    height: 100px;
    border-top: 1px solid #89cff0;
    border-bottom: 1px solid #89cff0;
    border-left: 1px solid #89cff0;
    border-right: 1px solid #89cff0;
    margin: 5px 0px 0px 0px;
    text-align: center;
}

JSFiddle Demo

更新了CSS:

{{1}}