html - 带有 CSS 过渡的背景缩放不起作用
问题描述
我正在尝试添加一个 css 过渡,因此当用户将鼠标悬停在 div 上时,背景会像这样https://codepen.io/mrsalami/pen/EpLZMe放大。但是,转换延迟不起作用。
我的 HTML:
<div class="what-we-do" id="home-block" style="background: url('http://www.intrawallpaper.com/static/images/1968081.jpg') center center no-repeat;">
<div class="home-box-text">
<h1>What We Do</h1>
</div>
</div>
我的 CSS:
#home-block {
width: 100%;
transition-delay: 2s;
-moz-transition-delay: 2s;
-ms-transition-delay: 2s;
-webkit-transition-delay: 2s;
-o-transition-delay: 2s;
height: calc((100vh - 133px)/ 3);
-webkit-background-size: 100%;
background-size: 100%;
margin-bottom: 20px;
display: flex;
align-items: center;
justify-content: center;
}
#home-block:hover {
background-size: 150% !important;
}
#home-block .home-box-text {
margin: 0;
}
#home-block .home-box-text h1 {
font-size: 30px;
text-transform: uppercase;
}
#scroll-body {
padding-left: 35px;
}
我的问题的codepen是https://codepen.io/mrsalami/pen/WKJRjr
解决方案
您必须在一个 CSS 声明中添加背景图片。因此,无需在 inline 语句中添加背景图像,添加如下。
#home-block {
background: url('http://www.intrawallpaper.com/static/images/1968081.jpg') center no-repeat;
width: 100%;
height: 200px;
color:#86A3B1;
background-size: 100%;
transition: all 3s ease;
-moz-transition: all 3s ease;
-ms-transition: all 3s ease;
-webkit-transition: all 3s ease;
-o-transition: all 3s ease;
margin-bottom: 20px;
display: flex;
align-items: center;
justify-content: center
}
#home-block:hover {
background-size: 150%;
}
和你做的 HTML 部分。
<body>
<div class="what-we-do" id="home-block">
<div class="home-box-text">
<h1>What We Do</h1>
</div>
这对我来说很好。:)
推荐阅读
- python-3.x - Python:使用 CP2102 模块通过 UART 与设备通信
- webstorm - 在 WebStorm 中显示上下文操作的快捷方式不起作用
- python - 如何从 XPATH 中使用 Selenium 检索变量(如计数)
- c++ - 从输入到输出的哈希表
- python - 调用外部函数时使用导入的正确方法
- python-3.x - 计算非 gensim 主题模型的连贯性
- django - 如何在 GitHub 操作中使用 django selenium 测试?
- javascript - Discord.js 冷却时间从几毫秒到几小时和几分钟
- node.js - Eslint:如何使用全局安装的 eslint-plugin-vue
- c - 无限循环是否被认为是“运行时错误”?(C)