html - CSS滑动缩放效果与重叠元素
问题描述
我有一个带有两个 div 的标题。两个 div 紧挨着。为此,我正在使用带有弹性框的引导程序。我想在将鼠标悬停在 div 上时创建滑动效果(和缩放)。将鼠标悬停在左侧 div 上应该会改变左右 div 的宽度。
我遇到的棘手部分是我想添加一条与正确 div 颜色相同的对角线以创建漂亮的外观。我尝试在右侧 div 上使用伪之后创建它,但问题是悬停时它不会与 div 的其余部分一起移动。我不得不把它position: absolute
显示在正确的 div 之外。
也许我做错了什么,或者也许有更好的解决方案。这个我还没想通
JSfiddle
https://jsfiddle.net/aq9Laaew/235971/
.header {
z-index: 1;
height: 50vh;
position: relative;
overflow: hidden;
}
.header-img {
width: 60vw;
height: 50vh;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
background-image: url(asset_path("bgs/bg-1.jpg"));
transition: all 0.4s ease-in-out;
-webkit-transition: all 0.4s ease-in-out;
-moz-transition: all 0.4s ease-in-out;
-ms-transition: all 0.4s ease-in-out;
}
.header-img:hover {
transform: scale(1.1);
-webkit-transform: scale(1.1);
-moz-transform: scale(1.1);
-ms-transform: scale(1.1);
width: 80vw;
}
.header-content {
color: #000000;
background-color: #FFFFFF;
width: 40vw;
height: 50vh;
transition: all 0.4s ease-in-out;
-webkit-transition: all 0.4s ease-in-out;
-moz-transition: all 0.4s ease-in-out;
-ms-transition: all 0.4s ease-in-out;
overflow-x: visible;
}
.header-content:hover {
width: 80vw;
}
.overlay::after {
content: " ";
display: inline-block;
position: absolute;
width: 20%;
height: 100%;
left: 50%;
border-style: dashed;
border-width: 1em;
border-color: #000000;
}
<div class="header d-flex flex-row">
<div class="header-img"></div>
<div class="header-content">
<div class="overlay"></div>
<div class="d-flex justify-content-center">
<div class="mt-5">
<div class="text-center header-text">
<h2>Text</h2>
</div>
</div>
</div>
</div>
</div>
解决方案
经过一番调查,我修复了叠加层的滑动效果。我已经div.overlay
在标题内容中附加了内容并设置postion:relative
了.header-content
类。
.header {
z-index: 1;
height: 50vh;
position: relative;
overflow: hidden;
}
.header-img {
width: 60vw;
height: 50vh;
background-position: 75% 50%;
background-color: #EFEFEF;
transition: all 0.4s ease-in-out;
-webkit-transition: all 0.4s ease-in-out;
-moz-transition: all 0.4s ease-in-out;
-ms-transition: all 0.4s ease-in-out;
}
.header-img:hover {
transform: scale(1.1);
width: 100vw;
}
.header-content {
position: relative;
color: #000000;
background-color: #FFFFFF;
width: 40vw;
height: 50vh;
transition: all 0.4s ease-in-out;
-webkit-transition: all 0.4s ease-in-out;
-moz-transition: all 0.4s ease-in-out;
-ms-transition: all 0.4s ease-in-out;
overflow-x: visible;
}
.header-content:hover {
width: 80vw;
}
.content-text {
position: absolute;
left: -2%;
}
.overlay::after {
content: " ";
display: inline-block;
position: absolute;
width: 70%;
height: 200%;
left: -35%;
top: -60%;
background-color: #FFFFFF;
transform: rotate(10deg);
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="header d-flex flex-row">
<div class="header-img"></div>
<div class="header-content">
<div class="overlay"></div>
<div class="d-flex justify-content-center">
<div class="mt-2">
<div class="text-center content-text">
<h3>text</h3>
</div>
</div>
</div>
</div>
</div>
推荐阅读
- json - 播放框架 (Scala) - 获取包含数组的 json 子集
- reactjs - 作为道具传递的数组被接受为字符串
- android - 任务 ':app:compileDebugJavaWithJavac' 执行失败。适用于 Android 的 React Native 应用程序
- jquery - 当我单击同一父行时,如何添加/删除显示其父行详细信息的新行?
- session - 使用 Spring Boot 在哪里管理微服务架构中的会话
- c# - 响应重定向与图像插入冲突
- python - 无法创建 conda 环境
- wso2 - wso2 EI/ESB 可以设置杀毒软件吗?
- android - 如何在 WebView 定义中获取上下文?
- karate - 在空手道中,我们如何验证带有 where 条件的查询是否有两个结果?