在另一个div上盘旋时显示div

时间:2013-12-20 14:20:35

标签: css html hover

我为此搜索了很多,我找不到答案。 我希望当将鼠标悬停在div subTopicNav1上时显示div SubTopicInfo1。我需要它只是CSS。

这就是我所拥有的:

Fiddle

HTML:

<div id="NavBar">

                <div id="Mainbutton">
                <center><h2 style="margin-top: 7px;"> Main </h2></center>
                </div>

                <div id="topic1button">
                <center><h2 style="margin-top: 7px;"> Skiing </h2></center>
                </div>

                <div id="topic2button">
                <center><h2 style="margin-top: 12px;"> Movies </h2></center>
                </div>


        </div>

        <div id="Main">

                <div id="IntroImage">

                </div>

                <div id="Title">
                        <h2 id="Titlemain"> TYLER POTTS</h2>
                </div>

                <div id="SubTopicNav">

                        <div id="subTopicNav1">
                                <center><h2>About Me</h2></center>
                        </div>

                        <div id="subTopicNav2">
                                <center><h2>Skiing</h2></center>
                        </div>

                        <div id="subTopicNav3">
                                <center><h2>Movies</h2></center>
                        </div>

                </div>

                <div id="SubTopicInfo">

                        <div id="SubTopicInfo1">
                        <h1> Test </h1>
                        </div>

                        <div id="SubTopicInfo2">

                        </div>

                        <div id="SubTopicInfo3">

                        </div>

                </div>

                <div id="Footer">

                </div>

        </div>

CSS:

#NavBar
{
width: 750px;
height: 40px;
background-color: white;
margin: 0 auto;
border-top: 5px solid #FFD640;
border-bottom: 5px solid #FFD640;
}


#topic2button
{
width: 100px;
height: 45px;
margin-top:-50px;
margin-left: 215px;
float:left;
}

#topic2button:hover
{
background-color: #FFD640;
}

#Mainbutton
{
width: 100px;
height: 45px;
margin-top:;
margin-left: 315px;
float:left;
}

#Mainbutton:hover
{
background-color: #FFD640;
}

#topic1button
{
width: 100px;
height: 45px;
float: left;
}

#topic1button:hover
{
background-color: #FFD640;
}

#Main
{
width: 750px;
height: 1000px;
margin: 0 auto;
background-color: white;
}

#IntroImage
{
width: 750px;
height: 150px;
background-image:url("http://skiersedgeproshop.com/wp/wp-content/uploads/2013/11/snow-mountain-ski1.jpg")
}

#IntroImage:hover
{
opacity: 0.8;
}

#Title
{
width: 500px;
height: 40px;
border-top: 5px solid #FFD640;
border-bottom: 5px solid #FFD640;
margin:0 auto;
margin-top: 10px;
}

#Titlemain
{
margin-left: 170px;
margin-top: 6px; 
}

#SubTopicNav
{
width: 150px;
height: 400px;
border-top: 5px solid #FFD640;
border-bottom: 5px solid #FFD640;
margin-top: 25px;
float:left;
}

#subTopicNav1
{
margin-top: 60px;
width: 150px;
height: 50px;
}

#subTopicNav2
{
margin-top: 60px;
width: 150px;
height: 50px;
}

#subTopicNav3
{
margin-top: 60px;
width: 150px;
height: 50px;
}

#subTopicNav1:hover 
{
margin-top: 60px;
width: 150px;
height: 50px;
background-color: #FFD640;
}

#subTopicNav2:hover
{
margin-top: 60px;
width: 150px;
height: 50px;
background-color: #FFD640;
}

#subTopicNav3:hover
{
margin-top: 60px;
width: 150px;
height: 50px;
background-color: #FFD640;
}

#SubTopicInfo
{
width: 600px;
height: 400px;
border-top: 5px solid #FFD640;
border-bottom: 5px solid #FFD640;
margin-top: 25px;
float: left;
}

#SubTopicInfo1
{
display:none;
background-color: #FFD640;
}

#subTopicNav1:hover + #SubTopicInfo1
{
display: block;
}

感谢。

3 个答案:

答案 0 :(得分:1)

在你的情况下,你只能用CSS做到这一点。

#subTopicNav1:hover + #SubTopicInfo1 {}

如果#SubTopicInfi1位于(#subTopicInfo1结束标记之后)容器旁边,则工作。

在这里解释:

How to affect other elements when a div is hovered

所以你可能应该用Jquery / javascript查看解决方案!

答案 1 :(得分:0)

请尝试这样的事情:

(默认情况下隐藏额外信息面板,然后将其显示在:悬停如下)

<style>
.link {
        display: block;
}

.link:hover p{
        visibility: visible;
}
.info{
        visibility: hidden;
}

</style>

<body>
        <div class="link">
                <a href="#"> Text Here </a>
                <p class="info"> Info Here</p>
        </div>
</body>

答案 2 :(得分:0)

以下是工作演示http://jsfiddle.net/H9fGP/1/ 也许它不是确切的例子。但我希望它有所帮助:)

主要是子信息具有绝对位置

我重新安排了html并添加了一些CSS。

.container
{
 border-top: 5px solid #FFD640;

 margin-top: 25px;
}

#SubTopicNav 
{
  position:relative;
}
#SubTopicNav > div > div
{
  position:absolute;
  left:200px;
  top:0px;
  display:none;
  width: 600px;
  height: 400px;
  margin-top: 25px;
  float: left;
}
#SubTopicInfo
{
  display:none;
  background-color: #FFD640;
}

#SubTopicNav > div:hover >div
{
 display: block;
}