【发布时间】:2021-03-16 11:57:42
【问题描述】:
https://jsfiddle.net/9gqbne6j/1/
<div class="row">
<div class="row-inner">
<div class="row-background"><div class="row-background-inner">
</div></div>
<div class="row-content">
<section class="first-section">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Circle-icons-flame.svg/1024px-Circle-icons-flame.svg.png" class="icon">
<h2 class="section-heading">
Some Heading
</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ullamcorper justo a neque mollis iaculis.
</p>
<button class="read-more">Read More</button>
</section>
</div>
</div>
</div>
html,
body {
background-color: grey;
color: white;
position: relative;
}
*, *::before, *::after {
box-sizing: border-box;
}
body::after {
content: "";
position: absolute;
background-image: url(data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllciAxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzMjAuNSA2MDQwLjEiPjxkZWZzPjxzdHlsZT4uY2xzLTF7ZmlsbDojMjMxZjIwO29wYWNpdHk6MC43O308L3N0eWxlPjwvZGVmcz48cG9seWdvbiBjbGFzcz0iY2xzLTEiIHBvaW50cz0iMzIwLjUgMjQ0OC45MiAwIDYwNDAuMSAwIDYwNDAuMSAwIDAgMzIwLjUgMjQ0OC45MiIvPjwvc3ZnPg==);
top: 0;
left: 0;
right: 0;
bottom: 0;
background-repeat: no-repeat;
background-size: 29.66%;
background-position: right 3% top 40%;
}
.row-inner {
position: relative;
clip-path: polygon(-38% 50%,128% 110%,128% -10%)
}
.row-background-inner {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-image: url(https://i0.wp.com/www.wagpets.com/wp-content/uploads/2020/04/pembroke-welsh-corgi-appearance-and-vital-stats.jpeg?resize=1429%2C956&ssl=1);
background-size: cover;
background-repeat: no-repeat;
}
.row-content {
position: relative;
display: flex;
justify-content: flex-end;
}
.first-section {
padding: 2em 1em;
display: flex;
flex-flow: column;
align-items: center;
max-width: 33%;
z-index: 9;
}
.section-heading {
margin-bottom: 0.5em;
}
.icon {
width: 50px;
height: 50px;
}
.read-more {
padding: 0.5em 1em;
background-color: steelblue;
color: white;
border: 0;
}
以上是我正在尝试解决的问题的一个最小示例。它是从一个更大的页面中提取的,所以我希望可以通过 CSS 进行修复,而不是完全重新组织 DOM。
所以,.row-inner 元素上有一个剪辑路径。如果启用了剪辑路径,则 .first-section 文本显示在 body::after 背景下方,但如果禁用剪辑路径,则文本显示在 body::after 背景上方。
有没有办法让 .first-section 出现在 body::after 背景之上,并且仍然启用剪辑路径?
我从之前的问题中读到它与剪辑路径改变元素的渲染顺序有关,但在这种情况下我找不到解决问题的方法,我还没有尝试过。
如果仅通过 CSS 无法修复,那么重新排序 DOM 以修复它的最简单方法是什么?
谢谢
【问题讨论】:
-
寻求代码帮助的问题必须包括在问题本身中重现它所需的最短代码,最好是在堆栈片段中。尽管您提供了一个链接,但如果它变得无效,那么您的问题对于未来遇到同样问题的其他 SO 用户将毫无价值。见Something in my website/example doesn't work can I just paste a link。
-
我给了你答案。这是你想要的结果吗?
-
是的。我现在已将其标记为已接受的答案。感谢您的帮助。
-
@floodlitworld,没问题。
标签: html css position z-index clip-path