【发布时间】:2015-02-13 23:25:30
【问题描述】:
我有一个非常小的黑色字体的 div,当你将鼠标悬停在它上面时,div 的大小会增长到红色背景,理想情况下字体会变为白色并显示不同的文本。截至目前,我有黑色字体说“悬停我”,当你滚动它时,div 会增长,bgcolor 会变为红色,而白色字体会显示在其中。但是,黑色的 hover me 仍然在 div 中,而白色字体实际上已经在页面上,它只是随着 div 的大小变大并变为红色而变得可见,从而为白色字体提供了可以显示它的背景。
如何让我的 div 更改其字体颜色,更重要的是,当我将其悬停时更改其中的文本内容?
以下是我正在使用的代码,如果需要进一步探索,我可以将网站更新为 url
//html
<section class="box content">
<div id="tOne"></div>
<div class="container">
<h2>Title One</h2>
<p>This is where text goes </p>
<div class="someContent">
<p>hover me</p>
<p id="pWhite"><br>Lets check the overview of this content</p>
</div>
</div>
</section>
//css
section.box h2 {
padding-top: 0;
margin: -7px 0;
color: #D11010;
font-family: Tahoma;
font-size: 30px;
}
section.box p {
padding-top: 0;
margin-bottom: 20px;
color: black;
font-size: 20px;
font-family: cursive;
font-weight: 300;
}
section.box p:last-child {
margin-bottom: 300px;
}
section.box.content {
padding-top: 0;
padding-left: 40px;
padding-bottom: 40px;
height: 500px;
}
.someContent {
width: 30%;
margin-left: 100px;
border: 2px solid black;
border-radius: 10px;
text-align: left;
padding: 0px;
color: black;
height: 60px;
-webkit-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-ms-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
.highLight {
background: rgba(209, 16, 16, 1);
border: 2px solid black;
overflow: hidden;
color: white;
width: 80%;
height: 400px;
}
//悬停效果的jQuery
$(document).ready(function() {
$(".someContent").hover( function() {
$(this).toggleClass("highLight");
}
, function() {
$(this).toggleClass("highLight");
});
})
感谢您的帮助!
【问题讨论】:
-
CSS 和过渡可以做到这一点 codepen.io/anon/pen/gbvxVg ,这是你要找的吗?
-
我认为这正是我正在寻找的。当您将鼠标悬停在框上时,白色文本如何展开,但之前不可见
-
只有使用纯 CSS 才能实现,我想使用 jQuery hover 来练习。