【发布时间】:2023-03-23 05:24:01
【问题描述】:
我正在准备一个带有倾斜元素的新布局,应该以任何方式响应。 我目前在默认桌面和移动设备上看起来不错,但如果屏幕更大,布局就会被破坏:例如在我的 32" 屏幕上,文本从容器元素之外开始,就在倾斜元素之前。这不应该发生。
main {
font-family: Arial;
}
.content_nocolor {
padding: 60px 40px 40px 40px;
}
.content__slant1 {
position: relative;
padding: 40px 40px 120px 40px;
overflow: hidden;
filter: drop-shadow(0px 40px 0px #f2f2f2);
}
.content__slant1:before {
content: "";
display: block;
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
width: 100%;
height: 100%;
background: #004B4F;
-webkit-transform: skewY(-3deg);
-moz-transform: skewY(-3deg);
-ms-transform: skewY(-3deg);
-o-transform: skewY(-3deg);
transform: skewY(-3deg);
transform-origin: top left;
}
.content__slant1 h1, .content__slant1 p {
position: relative;
color: #ffffff;
}
.content__slant1 h1 a, .content__slant1 p a {
color: inherit;
}
.content__slant2 {
position: relative;
padding: 120px 40px 40px 40px;
overflow: hidden;
filter: drop-shadow(0px calc(-1*40px) 0px #f2f2f2);
}
.content__slant2:before {
content: "";
display: block;
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #F89300;
/* background-image: linear-gradient(#ff9d2f, #ff6126); */
-webkit-transform: skewY(-3deg);
-moz-transform: skewY(-3deg);
-ms-transform: skewY(-3deg);
-o-transform: skewY(-3deg);
transform: skewY(-3deg);
transform-origin: bottom right;
}
.content__slant2 h1, .content__slant2 h3, .content__slant2 p {
position: relative;
color: #000000;
}
.content__slant2 h1 a, .content__slant2 h3 a, .content__slant2 p a {
color: inherit;
}
.content__slant3 {
position: relative;
padding: 0 40px 140px 40px;
overflow: hidden;
filter: drop-shadow(0px 40px 0px #f2f2f2);
}
.content__slant3:before {
content: "";
display: block;
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #F89300;
/* background-image: linear-gradient(#ff9d2f, #ff6126); */
-webkit-transform: skewY(3deg);
-moz-transform: skewY(3deg);
-ms-transform: skewY(3deg);
-o-transform: skewY(3deg);
transform: skewY(3deg);
transform-origin: bottom right;
}
.content__slant3 h1, .content__slant3 h3, .content__slant3 p {
position: relative;
color: #000000;
}
.content__slant3 h1 a, .content__slant3 h3 a, .content__slant3 p a {
color: inherit;
}
<main class="content">
<div class="content__slant1">
<h1>Office ipsum</h1>
<p>That's great, but we need to add this 2000 line essay make it original, for can it handle a million in one go, yet it needs to be the same, but totally different this looks perfect. Just Photoshop out the dog, add a baby, and make the curtains blue we exceed the clients' expectations this is just a 5 minutes job.</p>
<p>
What you've given us is texty, we want sexy something summery; colourful make it look like Apple. Can you make it faster? the animation does not work, when i print the page or can you punch up the fun level on these icons give us a complimentary logo along with the website, nor thanks for taking the time to make the website, but i already made it in wix.
</p>
</div>
<div class="content_nocolor">
<p>There is too much white space why is a 15mb gif on the startpage a bad idea?!, yet you can get my logo from facebook. </p>
<p>
That's great, but we need to add this 2000 line essay it needs to be the same, but totally different so there are more projects lined up charge extra the next time.
</p>
</div>
<div class="content__slant2">
<h1>... continues ...</h1>
<p>
We try your eye, but can you change everything? submit your meaningless business jargon to be used on the site!, but that will be a conversation piece this red is too red can you pimp this powerpoint, need more geometry patterns I have an awesome idea for a startup, i need you to build it for me. The flier should feel like a warm handshake. The animation does not work, when i print the page you might wanna give it another shot, or can you turn it around in photoshop so we can see more of the front can you make the blue bluer? jazz it up a little, can you please send me the design specs again?
</p>
<p>
I know somebody who can do this for a reasonable cost. Anyway, you are the designer, you know what to do can you make the logo bigger yes bigger bigger still the logo is too big can you use a high definition screenshot, in an ideal world. Remember, everything is the same or better in an ideal world can you please send me the design specs again?
</p>
<h3>Thats not what i saw in my head at all!!</h3>
</div>
<div class="content__slant3">
<h1>... and so it ends.</h1>
</div>
</main>
【问题讨论】:
-
顺便说一句,你有没有更好的选择来构建这样的布局?
-
您可以使用 clip-path 并最终引入 CSS var() 和 calc() 来匹配剪辑坐标和填充,而不是布置伪。快速示例jsfiddle.net/hz7y30pu
-
clamp() 也是一个选项codepen.io/gc-nomade/pen/YzVvRLG
-
很好的例子,谢谢。对于所有给定的版本,我确实对彩色元素的不透明度有疑问。 v1 有双透明的“边框”,其他的根本就不是半透明的。必须详细检查并检查不同的浏览器。