悬停背景(放大),前面的文字没有放大
Hover background (scale up) with text in front not getting scale up
当用户将鼠标悬停在图像上时,图像会变大。但是我也有一些信息要显示在图像前面。
这是我到目前为止所做的:
.home-about-link {
overflow: hidden;
width: 100%;
}
.home-about {
background: url(https://dummyimage.com/600x400/000/fff) no-repeat center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
text-align: center;
height: 300px;
width: 100%;
opacity: 0.8;
}
.home-about:hover {
opacity: 1;
transform: scale(1.1);
-moz-transform: scale(1.1);
-webkit-transform: scale(1.1);
-o-transform: scale(1.1);
-ms-transform: scale(1.1);
/* IE 9 */
-ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=1.1, M12=0, M21=0, M22=1.1, SizingMethod='auto expand')";
/* IE8 */
filter: progid:DXImageTransform.Microsoft.Matrix(M11=1.1, M12=0, M21=0, M22=1.1, SizingMethod='auto expand');
/* IE6 and 7 */
}
h2 {
color: #fff;
}
<div class="home-about-link">
<div class="home-about">
<h2>ABOUT US</h2>
</div>
</div>
代码的作用是当用户将鼠标悬停在图像上时,信息(ABOUT US文本)也会变大。我想要得到的是信息字体和之前一样,只是背景放大了。有什么办法可以做到这一点吗?
所以你不想让h2
与背景一起缩放。
一种方法是用比例因子1/1.1 = 0.909对h2
进行反向缩放
.home-about:hover h2{
transform: scale(0.909);
}
让我知道你对此的反馈。干杯!
.home-about-link {
overflow: hidden;
width: 100%;
}
.home-about {
background: url(https://dummyimage.com/600x400/000/fff) no-repeat center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
text-align: center;
height: 300px;
width: 100%;
opacity: 0.8;
}
.home-about:hover {
opacity: 1;
transform: scale(1.1);
-moz-transform: scale(1.1);
-webkit-transform: scale(1.1);
-o-transform: scale(1.1);
-ms-transform: scale(1.1);
/* IE 9 */
-ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=1.1, M12=0, M21=0, M22=1.1, SizingMethod='auto expand')";
/* IE8 */
filter: progid: DXImageTransform.Microsoft.Matrix(M11=1.1, M12=0, M21=0, M22=1.1, SizingMethod='auto expand');
/* IE6 and 7 */
}
h2 {
color: #fff;
}
.home-about:hover h2 {
transform: scale(0.909);
}
<div class="home-about-link">
<div class="home-about">
<h2>ABOUT US</h2>
</div>
</div>
这是您期望的结果吗?检查jsbin
中的输出只是减少
的值-webkit-transform: scale(1.1)
-webkit-transform: scale(1);
Jsbin联系css
.home-about-link{
overflow: hidden;
width: 100%;
}
.home-about{
background: url(https://dummyimage.com/600x400/000/fff) no-repeat center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
text-align: center;
height: 300px;
width: 100%;
opacity: 0.8;
}
.home-about:hover {
opacity: 1;
transform: scale(1);
-moz-transform: scale(1.1);
-webkit-transform: scale(1);<!----check the changes-------->
-o-transform: scale(1.1);
-ms-transform: scale(1.1); /* IE 9 */
-ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=1.1, M12=0, M21=0, M22=1.1, SizingMethod='auto expand')"; /* IE8 */
filter: progid:DXImageTransform.Microsoft.Matrix(M11=1.1, M12=0, M21=0, M22=1.1, SizingMethod='auto expand'); /* IE6 and 7 */
}
h2{
color: #fff;
}
html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div class="home-about-link">
<div class="home-about">
<h2>ABOUT US</h2>
</div>
</div>
</body>
</html>
相关文章:
- 添加文字和评论功能更新Div
- UIAutomation放大图像
- 如何计算对象文字中的键
- 如何在d3上的图形中添加放大和缩小按钮
- I'我想放下画布上的文字.帮帮我
- 如何使用javascript onmouseover缓慢放大图像
- 点击放大图片.JavaScript、CSS和HTML
- 对象文字方法上的Javascript绑定不起作用
- 鼠标悬停时如何居中放大背景图像
- 以ECMAScript 5及更高版本为目标时,八进制文字不可用
- 查找仅适用于原始图像的图像放大算法的名称
- ES6 模板文字是否比 eval 更安全
- addEventListener的Javascript代码不工作!?(单击时打开放大的img)
- 放大弹出生成“;找不到文件”;YouTube视频的错误
- 是索引数组文字的好做法
- 从多行文字中获取第一个修剪的字符串
- 谷歌地图完全放大
- 如何在只接受字符串值/文字的HTML属性中调用函数
- 使用angular缩放大图像以适应屏幕宽度
- 悬停背景(放大),前面的文字没有放大