gpt4 book ai didi

html - 尝试使用倾斜的 div 为背景图像提供两种不同的色调

转载 作者:行者123 更新时间:2023-11-28 03:28:02 24 4
gpt4 key购买 nike

我是学习 HTML 和 CSS 的新手,我正在尝试为背景图像提供两个带有倾斜 div 的倾斜色调。我不明白该怎么做才能使倾斜仅在图像的中间而不是在图像的边缘。到目前为止,这是我尝试过的方法。

.tinted-image {

width: 100vw;
height: 100vh;

background: url(https://static.pexels.com/photos/175941/pexels-photo-175941.jpeg);
background-size: cover;
filter: grayscale(100%);
display: flex;
overflow: hidden;
}

#one{
background: linear-gradient(rgba(0,0,0,0.85), rgba(0,0,0, 0.85));
tranform-origin: bottom-left;
transform: skewX(10deg);
/* margin-left: 1em; */
}
#two{
background: linear-gradient(rgba(255, 255, 255, .45), rgba(255, 255, 255, .45));
transform: skewX(10deg);
}
#one, #two{
height: 100vh;
width: 50vw;
display: flex;
justify-content: center;
align-items: center;
font-family:'Nova Mono', monospace;
font-size: 5rem;
}

#one h1 {
color: #eee;
margin-left: auto;
margin-right: 1rem;
}

#two h1 {
color: #222;
margin-right: auto;
margin-left: 1rem;
}
<main class="tinted-image">
<link href="https://fonts.googleapis.com/css?family=Nova+Mono" rel="stylesheet">
<div id = "one"><h1>WEB</h1></div>
<div id = "two"><h1>DEV</h1></div>
</main>

最佳答案

我可以通过使用 negative margin 获得预期的效果在左侧 margin-left: -200px; 和一个相同数量的正左填充 padding-left: 200px; 来抵消它。

我将这两个添加到您的选择器 #one 以及 overflow: hidden;tidy things up

工作示例:

.tinted-image {
width: 100vw;
height: 100vh;
background: url(https://static.pexels.com/photos/175941/pexels-photo-175941.jpeg);
background-size: cover;
filter: grayscale(100%);
display: flex;
overflow: hidden;
}

#one {
background: linear-gradient(rgba(0, 0, 0, 0.85), rgba(0, 0, 0, 0.85));
tranform-origin: bottom-left;
margin-left: -200px;
padding-left: 200px;
overflow: hidden;
transform: skewX(10deg);
/* margin-left: 1em; */
}

#two {
background: linear-gradient(rgba(255, 255, 255, .45), rgba(255, 255, 255, .45));
transform: skewX(10deg);
}

#one,
#two {
height: 100vh;
width: 50vw;
display: flex;
justify-content: center;
align-items: center;
font-family: 'Nova Mono', monospace;
font-size: 5rem;
}

#one h1 {
color: #eee;
margin-left: auto;
margin-right: 1rem;
}

#two h1 {
color: #222;
margin-right: auto;
margin-left: 1rem;
}
<main class="tinted-image">
<link href="https://fonts.googleapis.com/css?family=Nova+Mono" rel="stylesheet">
<div id="one">
<h1>WEB</h1>
</div>
<div id="two">
<h1>DEV</h1>
</div>
</main>

关于html - 尝试使用倾斜的 div 为背景图像提供两种不同的色调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44879428/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com