html - 带有背景图像的 CSS 三角形形状部分
问题描述
我需要创建这样的布局:
如您所见,我需要在每个部分上设置三角形并设置背景图像
我尝试使用剪辑路径并且我设法制作了形状,但我无法统一由此产生的分离,第一个代码是用剪辑路径实现的(我想可能是 css-grid 和 grid-areas工作,但我没有尝试过喷气式飞机)
main {
display: grid;
grid-template-columns: repeat(1, 1fr);
position: relative;
}
.service {
height: 100vh;
display:flex;
justify-content:center;
align-items:center;
}
.service-1 {
background-color: blue;
clip-path: polygon(0 34%, 100% 0, 100% 100%, 0 65%);
top: 5px;
left: 5px;
right: 0;
bottom: 0;
}
.service-2 {
background-color: pink;
clip-path: polygon(0 0, 100% 34%, 100% 65%, 0 100%);
top: 0;
left: 0;
right: 5px;
bottom: 5px;
}
.service-3 {
background-color: yellow;
clip-path: polygon(0 34%, 100% 0, 100% 100%, 0 65%);
top: 5px;
left: 5px;
right: 0;
bottom: 0;
}
<main>
<div class="service service-1">
<h2>Service 1</h2>
</div>
<div class="service service-2">
<h2>Service 2</h2>
</div>
<div class="service service-3">
<h2>Service 3</h2>
</div>
</main>
另外,我尝试使用 SVG,但结果相同
main {
display: grid;
grid-template-columns: repeat(1, 1fr);
position: relative;
}
.service {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.service-1 {
background-color: blue;
position: relative;
}
.service-1 .custom-shape-divider-top-1624638189 {
position: absolute;
top: 0;
left: 0;
width: 100%;
overflow: hidden;
line-height: 0;
}
.service-1 .custom-shape-divider-top-1624638189 svg {
position: relative;
display: block;
width: calc(100% + 1.3px);
height: 150px;
transform: rotateY(180deg);
}
.service-1 .custom-shape-divider-top-1624638189 .shape-fill {
fill: #ffffff;
}
.service-1 .custom-shape-divider-bottom-1624638504 {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
overflow: hidden;
line-height: 0;
transform: rotate(180deg);
}
.service-1 .custom-shape-divider-bottom-1624638504 svg {
position: relative;
display: block;
width: calc(100% + 1.3px);
height: 150px;
}
.service-1 .custom-shape-divider-bottom-1624638504 .shape-fill {
fill: #ffffff;
}
.service-2 {
background-color: pink;
position: relative;
}
.service-2 .custom-shape-divider-top-1624638774 {
position: absolute;
top: 0;
left: 0;
width: 100%;
overflow: hidden;
line-height: 0;
}
.service-2 .custom-shape-divider-top-1624638774 svg {
position: relative;
display: block;
width: calc(100% + 1.3px);
height: 150px;
}
.service-2 .custom-shape-divider-top-1624638774 .shape-fill {
fill: #ffffff;
}
.service-2 .custom-shape-divider-bottom-1624638661 {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
overflow: hidden;
line-height: 0;
transform: rotate(180deg);
}
.service-2 .custom-shape-divider-bottom-1624638661 svg {
position: relative;
display: block;
width: calc(100% + 1.3px);
height: 150px;
transform: rotateY(180deg);
}
.service-2 .custom-shape-divider-bottom-1624638661 .shape-fill {
fill: #ffffff;
}
.service-3 {
background-color: yellow;
position: relative;
}
.service-3 .custom-shape-divider-top-1624638189 {
position: absolute;
top: 0;
left: 0;
width: 100%;
overflow: hidden;
line-height: 0;
}
.service-3 .custom-shape-divider-top-1624638189 svg {
position: relative;
display: block;
width: calc(100% + 1.3px);
height: 150px;
transform: rotateY(180deg);
}
.service-3 .custom-shape-divider-top-1624638189 .shape-fill {
fill: #ffffff;
}
.service-3 .custom-shape-divider-bottom-1624638504 {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
overflow: hidden;
line-height: 0;
transform: rotate(180deg);
}
.service-3 .custom-shape-divider-bottom-1624638504 svg {
position: relative;
display: block;
width: calc(100% + 1.3px);
height: 150px;
}
.service-3 .custom-shape-divider-bottom-1624638504 .shape-fill {
fill: #ffffff;
}
<main>
<div class="service service-1">
<div class="custom-shape-divider-top-1624638189">
<svg
data-name="Layer 1"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 1200 120"
preserveAspectRatio="none"
>
<path
d="M1200 120L0 16.48 0 0 1200 0 1200 120z"
class="shape-fill"
></path>
</svg>
</div>
<h2>Service 1</h2>
<div class="custom-shape-divider-bottom-1624638504">
<svg
data-name="Layer 1"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 1200 120"
preserveAspectRatio="none"
>
<path
d="M1200 120L0 16.48 0 0 1200 0 1200 120z"
class="shape-fill"
></path>
</svg>
</div>
</div>
<div class="service service-2">
<div class="custom-shape-divider-top-1624638774">
<svg
data-name="Layer 1"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 1200 120"
preserveAspectRatio="none"
>
<path
d="M1200 120L0 16.48 0 0 1200 0 1200 120z"
class="shape-fill"
></path>
</svg>
</div>
<h2>Service 2</h2>
<div class="custom-shape-divider-bottom-1624638661">
<svg
data-name="Layer 1"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 1200 120"
preserveAspectRatio="none"
>
<path
d="M1200 120L0 16.48 0 0 1200 0 1200 120z"
class="shape-fill"
></path>
</svg>
</div>
</div>
<div class="service service-3">
<div class="custom-shape-divider-top-1624638189">
<svg
data-name="Layer 1"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 1200 120"
preserveAspectRatio="none"
>
<path
d="M1200 120L0 16.48 0 0 1200 0 1200 120z"
class="shape-fill"
></path>
</svg>
</div>
<h2>Service 3</h2>
<div class="custom-shape-divider-bottom-1624638504">
<svg
data-name="Layer 1"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 1200 120"
preserveAspectRatio="none"
>
<path
d="M1200 120L0 16.48 0 0 1200 0 1200 120z"
class="shape-fill"
></path>
</svg>
</div>
</div>
</div>
</main>
解决方案
推荐阅读
- email - 带有 content_type (text/html) 和附件标签的 Oozie 电子邮件操作正在以普通文本/纯格式发送邮件
- ios - 对于 React-Native iOS XCode 版本 12.5 的旧项目,构建失败
- python - Plotly px.choropleth 不从 json 文件中绘制数据
- php - 我想对 order_id 不同的 bill_amount 列求和。其实我想得到应有的金额
- php - 使用 Helium 的 Shopyfy 中未显示语言菜单
- python-3.x - 如何使用 PCA 和 python 进行特征选择
- javascript - 使用 JavaScript 设置锯齿权限
- elasticsearch - 如何从弹性搜索中提取“消息”值?(DSL)
- spartacus-storefront - Spartacus 在多站点上运行 dev:ssr 未从 NgExpressEngineDecorator 传递 requestOrigin
- php - Laravel + Pusher 期望参数 2 是一个数组,在线聊天中给出的字符串