【发布时间】:2023-03-19 02:44:01
【问题描述】:
我试图倾斜一个 div 但不是它的内容,无论它是应该垂直的图像还是文本。
我已经解决了许多与堆栈错误相关的问题,例如
Create a slanted edge to a div,
How to skew element but keep text normal (unskewed)
在我看来,似乎没有任何帮助。
我已将图像放在左侧,将文本放在右侧,它们都应该是倾斜的。但是当我像将图像放在右侧(反之亦然)一样翻转它们时,它应该证明自己是合理的。
这是一张鼓舞人心的图片。
这是我为它工作过的Fiddle。
<div class="container">
<div class="partial-section">
<div class="section-inner">
<div id="parallelogram">
<div class="image"></div>
</div>
</div>
</div>
<div class="partial-section">
<h1> This is some heading on the right partial section.</h1>
<p>Some random text that should be appeared on the right side of the partial section. This should be below the heading the partial section has and should fill the empty space that it has.</p>
</div>
</div>
body {
margin: 0;
padding: 0;
font-family: Arial;
}
* {
box-sizing: border-box;
}
.container {
max-width: 1160px;
margin: 0 auto;
background-color: green;
height: 450px;
}
.partial-section {
width: 50%;
background-color: red;
height: inherit;
display: inline;
float: left;
border: 2px solid lightgrey;
padding: 20px;
}
.partial-section h1 {
font-size: 40px;
}
.partial-section p {
font-size: 20px;
}
.section-inner {
height: inherit;
}
#parallelogram {
width: 100%;
height: inherit;
transform: skew(-40deg);
position: relative;
top: 0;
overflow: hidden;
}
.image {
background: url(http://placekitten.com/601/301);
background-size: cover;
position: absolute;
top: 0;
background-repeat: no-repeat;
-webkit-transform: skew(-20deg);
-moz-transform: skew(-20deg);
-o-transform: skew(-20deg);
height: inherit;
width: 100%;
transform: skew(40deg);
}
如果有人能帮我解决这个问题,我会很高兴。
提前致谢。
【问题讨论】:
-
也检查一下post。
-
你能抽出一些时间来帮助我吗?
-
好的。您应该与
overflow hidden有共同的父母。在左列将有没有任何转换的图像,在右列将有没有任何背景和转换的文本。在具有全高和背景的右列上使用伪元素,并将倾斜变换应用于此伪元素。你明白了吗? -
以防万一有人想要 jsFiddle,这里是链接:jsfiddle.net/83pdLum5