html - 背景图像缩放 html5 css3

标签 html css

我一直在搞乱一些 html5/css3 转换,在我的一生中,我无法在将鼠标悬停在文本上时放大背景图像,我做错了什么是这种方式吗?还是我完全偏离了路线

下面的代码......

<!doctype html>
<html>
<head>
<style>
* {
margin: 0;
padding: 0;
}
.img-holder {
width: 400px;
height: 298px;
overflow: hidden;
margin: 10px;
position: relative;
color:white;
transition: all 0.5s ease-in-out;
font-size:20px;
font-weight:bold;
}
.img-holder img {
transform: scale(1);
transition: all 0.5s ease-in-out;
}
.img-holder img:hover {
transform: scale(1.1);
transition: all 0.5s ease-in-out;
}
.texthover {
position: absolute;
padding: 20px;
bottom: 0;
left: 0;
display:-moz-box;
}
.img-holder:hover {
color:red;
transition: all 0.5s ease-in-out;
}
</style>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<div class="img-holder"><a href="#"><img src="http://image.shutterstock.com/display_pic_with_logo/516040/96143585/stock-photo-dj-mixes-the-track-in-nightclub-at-party-96143585.jpg"/></a>
  <div class="texthover">Here's some text!!</div>
</div>
</body>
</html>

非常感谢

最佳答案

您将重新排列 HTML 中的元素,并在将鼠标悬停在文本上时使用相邻的兄弟组合器选择后续的 img 元素 (.texthover:hover + img) .

EXAMPLE HERE

.img-holder img:hover, .texthover:hover + img {
    transform: scale(1.1);
    -webkit-transform: scale(1.1);
    -moz-transform: scale(1.1);
}

如果您希望在将鼠标悬停在文本上时发生转换,您只需使用:

EXAMPLE HERE

.texthover:hover + img {
    transform: scale(1.1);
    -webkit-transform: scale(1.1);
    -moz-transform: scale(1.1);
}

关于html - 背景图像缩放 html5 css3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21446016/

相关文章:

javascript - 如何隐藏JWPlayer 6 播放按钮?

html - 如何让div覆盖父div

html - 在数据库中显示html文本发生错误

javascript - 下拉菜单在移动设备上变形(Google Nexus 5)

javascript - JQuery 对话框显示 HTML 内容并防止在对话框关闭后删除 HTML?

html - 低延迟(< 2 秒)直播视频流 HTML5 解决方案?

html - 仅在循环中的对象下方显示复选框元素一次

javascript - Jquery 切换不适用于 slider

html - CGI C中处理html表单发送的POST数据

java - 将 HTML 和 CSS 样式应用于 Java Swing 组件