html - CSS对角线分隔2个图像
问题描述
我的任务是用 html 和 css 重新创建这个模型。在过去的几个小时里,我一直在摆弄尝试使用剪辑路径和边框,但我无法实现模型的结果。
我已经获得了 2 个图像资源,并且图像不包含文本或按钮。
#index-custom-content {
height: 40rem;
padding-bottom: -20%;
}
#index-custom-content div:nth-of-type(1){
position: relative;
width: 100%;
}
#index-custom-content div:nth-of-type(2) {
clip-path: polygon(0 0, 100% 90%, 100% 100%, 0 10%);
background-color: black;
z-index: 1000;
position: relative;
top: -2em;
}
#index-custom-content div:nth-of-type(3){
position: relative;
top: -20%;
width: 100%;
z-index: -100;
}
<div id="content">
<div id="index-custom-content">
<div><img src="bare-rolig.jpg"></div>
<div>asd</div>
<div><img src="bestseller.gif"> </div>
</div>
</div>
我的问题是,当给定 2 个大小不等的图像(宽度和高度)时,如何实现分隔 2 个图像的对角线。它也可以调整大小,比例正确,线条的宽度也保持不变。
非常感谢任何建议或正确方向的观点!先感谢您!
解决方案
具有负边距的剪辑路径:
.first,
.second{
--s:100px;
height:300px;
}
.first {
background:red;
clip-path:polygon(0 0,100% 0,100% 100%,0 calc(100% - var(--s)));
}
.second {
background:green;
/* a little smaller than --s to create a gap */
margin-top: calc(var(--s) * -1 + 10px);
clip-path:polygon(0 0,100% var(--s),100% 100%,0 100%);
}
<div class="first"></div>
<div class="second"></div>
推荐阅读
- r - Rmarkdown 图片库
- google-kubernetes-engine - 无法使用 k8s 中的标签列出作业
- javascript - 如何在电子中创建一个带有阴影的透明窗口
- c# - ASP.NET Core MVC IFormFile 在 Post 请求中返回 null
- python - 如何循环遍历 Pandas df?
- ios - 为 iOS 模拟器构建,但链接和嵌入式框架“abc.framework”是为 iOS 构建的
- sql - 将查询包含 group by 子句的 SQL Server 中的 Row 值转换为 Column 值
- c# - Xamarin C# 使用 AVAsset Native IOS 将 .mov 转码为 .mp4
- python - 如何使用 selenium webdriver 减慢动态页面的滚动速度
- r - 我们如何获得gwr模型(spgwr包)的整体预测精度?