在子元素悬停时隐藏/显示正文中的文本

时间:2013-09-09 03:38:49

标签: html css hover

我想最初在我的身体中隐藏文字,但是一旦孩子div中的元素悬停在上面就显示出来。所以在这种情况下,我希望它们最初都以display: none开始,但是当我将鼠标悬停在字母“H”上时,我想要显示“文字A”。当我将鼠标悬停在字母“E”上时,我想要显示“文字B”。我不想把我的#content元素放在我的#word元素中。我想把它们作为单独的div。

任何想法?

(见下面的小提琴)

HTML:

<div id="word">
    <h1><a id="h" class= "letter" href=#>H</a></h1>
    <h1><a id="e" class= "letter" href=#>E</a></h1>
    <h1><a id="l" class= "letter" href=#>L</a></h1>
    <h1><a id="l2"class= "letter" href=#>L</a></h1>
    <h1><a id="o" class= "letter" href=#>O</a></h1> 
</div>

<div id="content">
    <div id="textA">Text A</div>
    <div id="textB">Text B</div>
</div>

CSS:

 body {
    font-family: 'Chango', cursive;
    font-size: 115px;
    color: white;
    text-shadow: 5px 5px 5px #000;

    width: 100%;
    height: 100%;
    margin: 0px;
    background: black;
    }

    #name {
    position:absolute; 
    height:100%; 
    width: 70%;
    display: table;
    padding: 0 15% 0 15%;
    background: black;
    }

    h1 {
    display: table-cell;
    vertical-align: middle;
    text-align:center;
    height: 1em;

    }

    a {
    /*border: 1px solid black;*/
    display: inline-block;
    line-height: 89%;
    overflow: hidden;

    }

    a:visited, a:active {
    text-decoration: none;
    color: white;
    /*color: #E8E8E8;*/

    }

    a:link {
    text-decoration: none;
    color: white;
    text-shadow: 3px -3px 0px black, -2px 2px 5px #0056b2;

    }

    a:hover {
    text-shadow: 5px 5px 5px #000;
    color: white;
    }

小提琴: http://jsfiddle.net/ADfhj/1/

PS-我试过以下的CSS无济于事:

#textA {
display: none;
}

#word:hover #textA {
display: block;
}

1 个答案:

答案 0 :(得分:6)

无法仅使用css实现它。但是你可以尝试简单的javascript / jquery。

 $('.letter').mouseover(function(){
    var cont = $(this).attr('id');
    $('#content>div').hide();
    $('#text_'+cont).fadeIn();
});

检查Fiddle

相关问题