CSS和JQ两种方式实现图片层上显示文字
2015-09-17 11:20
786 查看
先看效果
HTML 代码:
<div id="outer" class="outer" style="background: url(IMG/thumb.jpg)">
<a href="#" class="now"><span>电 影 钢 的 琴</span> </a>
</div>
第一种(纯css代码实现),缺陷:不可以控制显示速度,--speed
.outer
{
height: 280px;
width: 500px;
margin: 0px auto;
position: relative;
}
.outer a
{
display: none;
text-decoration: none;
}
.outer:hover
{
cursor: pointer;
}
.outer:hover a.now
{
display: block;
}
.outer:hover a
{
display: block;
position: absolute;
bottom: 0;
left: 0;
text-decoration:none;
color:White;
font-weight:bolder;
z-index: 10;
width: 100%;
height: 9%;
line-height: 27px;
background:gray;
text-align: center;
}
第二种(jq方式实现)可以控制speed,效果较好
html代码:
<div id="outer" class="outer" style="background: url(IMG/thumb.jpg)">
<a href="#" class="secondWayCSS"><span>电影钢的琴</span> </a>
</div>
css代码:
.outer
{
height: 280px;
width: 500px;
margin: 0px auto;
position: relative;
}
.outer:hover
{
cursor:pointer;
}
.secondWayCSS
{
display: none;
position: absolute;
bottom: 0;
left: 0;
color: red;
z-index: 10;
width: 100%;
height: 9%;
line-height: 27px;
background:gray;
text-align: center;
}
jq代码:
$(function () {
$("#outer").hover(function () {
$(this).find("a").slideDown("normal");
}, function () {
$(this).find("a").slideUp("normal");
})
//实现的方式二;更简单的呀;
$("#outer").hover(function () {
$(this).find("a").slideToggle(300);
})
})
HTML 代码:
<div id="outer" class="outer" style="background: url(IMG/thumb.jpg)">
<a href="#" class="now"><span>电 影 钢 的 琴</span> </a>
</div>
第一种(纯css代码实现),缺陷:不可以控制显示速度,--speed
.outer
{
height: 280px;
width: 500px;
margin: 0px auto;
position: relative;
}
.outer a
{
display: none;
text-decoration: none;
}
.outer:hover
{
cursor: pointer;
}
.outer:hover a.now
{
display: block;
}
.outer:hover a
{
display: block;
position: absolute;
bottom: 0;
left: 0;
text-decoration:none;
color:White;
font-weight:bolder;
z-index: 10;
width: 100%;
height: 9%;
line-height: 27px;
background:gray;
text-align: center;
}
第二种(jq方式实现)可以控制speed,效果较好
html代码:
<div id="outer" class="outer" style="background: url(IMG/thumb.jpg)">
<a href="#" class="secondWayCSS"><span>电影钢的琴</span> </a>
</div>
css代码:
.outer
{
height: 280px;
width: 500px;
margin: 0px auto;
position: relative;
}
.outer:hover
{
cursor:pointer;
}
.secondWayCSS
{
display: none;
position: absolute;
bottom: 0;
left: 0;
color: red;
z-index: 10;
width: 100%;
height: 9%;
line-height: 27px;
background:gray;
text-align: center;
}
jq代码:
$(function () {
$("#outer").hover(function () {
$(this).find("a").slideDown("normal");
}, function () {
$(this).find("a").slideUp("normal");
})
//实现的方式二;更简单的呀;
$("#outer").hover(function () {
$(this).find("a").slideToggle(300);
})
})
相关文章推荐
- css3 box-sizing属性(规定尺寸)
- 怎样使用chrome调试前端html和css
- CSS让文本只显示一行,超出部分隐藏或以三个点结束
- DIV+CSS的经典翻页代码
- 使用CSS3实现百叶窗
- 基于CSS实现的4级下拉菜单效果代码
- html+css做页面如何不会乱
- CSS 符合习惯的代码规范
- css里面常用一些通用样式写法
- Word使用样式技巧:解决创建目录后出现的打印错误---超链接错误
- CSS样式小总结
- HTML&CSS Learning Notes 5
- css属性学习笔记
- 【搬运】CSS实现背景透明,文字不透明,兼容所有浏览器
- css中 outline 的使用
- css重点
- CSS hack方式
- 用CSS、HTML编写一个两列布局的网页,右侧宽度为200px,左侧自动扩展。
- CSS学习总结
- css 盒模型详解