html - 如何倾斜带有背景图像的div的底部边框
问题描述
我有一个简单的 div 设置为大约一个完整的视口的高度。这个 div 有一个背景图像和一行文本。我想倾斜这个 div 的底部边框,同时保持所有内容默认对齐(水平)。我尝试过使用变换旋转或倾斜,但这会旋转内容,并且由于旋转而使背景移出 div 的角落。有没有办法做到这一点?
编辑:这是我尝试使用旋转内容的示例:
<div class="backgrounddiv"><h1 class="title">Title</h1></div>
<style>
.title{
position:absolute;
bottom: 20px;
left:40%;
transform: translate(-50%, 0);
}
.backgrounddiv{
background:url('media/bgpic.png') scroll no-repeat center/cover;
transform: rotate(10deg);
}
解决方案
一种解决方案是使用伪元素作为掩码。您可以设置元素的位置和背景颜色,以便看起来我们正在从<div>
您的内容中切出一大块。
这是一个示例片段。运行它以查看结果。
将面具更改background-color
为红色(或任何颜色)并overflow: hidden
从容器中取出以更好地了解实际发生的情况。
.container {
width: 200px;
height: 200px;
background: url("https://homepages.cae.wisc.edu/~ece533/images/airplane.png");
background-size: cover;
font-size: 2rem;
position: relative;
overflow: hidden;
}
.container::before{
content: '';
width: 200%;
height: 50%;
position: absolute;
bottom: -10%;
left: -50%;
transform: rotate(-10deg);
background-color: white;
}
<div class="container">
<p>Some text</p>
</div>
推荐阅读
- nlp - 在 Mac 上使用 Conda 安装 Spacy
- javascript - 为什么我的 Google 表格功能这么慢?
- java - 从方法读取文件时出现无限循环
- erlang - 如何在列表与单个元素上进行模式匹配
- java - 如何使用preferenceChange更改所有活动的背景?
- javascript - XSS(跨站点脚本)与 HTML 注入
- java - 有没有办法将对象引用保存在数组列表中?
- python - 将整个列与列表中的值相乘
- sql - 错误:编译语句时出错:失败:ParseException 行 1:9 不匹配输入 'from' 期望 SET 在更新语句中的 'a' 附近
- angular - 我无法为我的 Angular 聊天机器人应用程序迁移指南中提供的 Dialogflow V2 实施身份验证设置?