【发布时间】:2019-03-07 20:49:39
【问题描述】:
我正在处理倾斜的 div,但对如何处理堆叠/重叠有疑问。
我有 3 个 div; - Div1 具有简单的背景颜色并且没有倾斜 - Div2 顶部倾斜并有背景图像(背景颜色设置为与 Div1 相同) - div3 是具有不同背景图像的 div2 的重复。
问题是,div3 的倾斜部分具有 div1 背景颜色 - 我希望它显示 div2 的背景图像。
这有意义吗?
This is what it looks like right now - i want to get rid of the red and show the image instead.
谢谢!
HTML 和 CSS
/* 8. Sections */
section {
width: 100%;
height: 100vh;
}
/* Homepage - Hero */
section.hero {
position: relative;
overflow: hidden;
width: 100%;
background-color: #E2004B;
}
/* Homepage - VWEAR */
section.vwear {
position: relative;
overflow: hidden;
width: 100vw;
background-image: url("https://drive.google.com/uc?id=1oaThTzD6dpXolbB0OSxDMMTC52VF1A0f");
background-size: cover;
background-position: center;
}
section.vwear:before {
content: '';
position: absolute;
width: 100%;
height: 100%;
bottom: 100%;
left: 0;
transform: skewY(-3deg);
transform-origin: right;
background: #E2004B;
}
/* Homepage - VGEAR */
section.vgear {
position: relative;
overflow: hidden;
width: 100vw;
background-image: url("https://drive.google.com/uc?id=1-WIqMPtFY1I6WyDYFnSyhvkYqVNqdR9o");
background-size: cover;
background-position: center;
}
section.vgear:before {
content: '';
position: absolute;
width: 100%;
height: 100%;
bottom: 100%;
left: 0;
transform: skewY(-3deg);
transform-origin: right;
background: #E2004B;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="stacking_div_skew.css">
</head>
<body>
HTML
<!-- start Hero Section-->
<section class="hero" data-section-name="hero" id="hero">
<div class="txt-container">
<div class="hero-txt">BIG HEADLINE TEXT<br><br>SMALLER SUBTITLE</div>
</div>
</section>
<!-- end Hero Section -->
<!-- start V:WEAR Section-->
<section class="vwear" data-section-name="vwear" id="vwear">
<div class="txt-container">
<div class="hero-txt">BIG HEADLINE TEXT<br><br>SMALLER SUBTITLE</div></div>
</div>
</section>
<!-- end V:WEAR Section -->
<!-- start V:GEAR Section-->
<section class="vgear" data-section-name="vgear" id="vgear">
<div class="txt-container">
<div class="hero-txt">BIG HEADLINE TEXT<br><br>SMALLER SUBTITLE</div></div>
</div>
</section>
</body>
</html>
【问题讨论】:
-
div2 和 div 3 在 div1 内吗?
-
否 - div 是按部分堆叠的
-
在此处分享您的 HTML 和 CSS
-
添加了html和css
-
是的,没错,因为我复制了 css 并在 div2 和 div3 中添加了背景图像。