Clip-path, z-index on 3 different items - html

I have a request from my client to do somehting like this (css only):
On the background, have a color, sectionned on the bottom
On the right side, have a text block, sectionned on top and bottom
Between them, show an image
As you can see here. But the problem, is that the bottom of the image should follow the sectionned part of the 1 layer.
As far as I know, it's not possible to achieve such thing because of how the css is working, because the image can't be "behind" the 1 layer and in front of the 3d.
So far, I have my 2nd layer working well (I used the clippy website to help me).
The when I try to apply the clippath 1 layer, it also clips the 2nd (as expected by clippath)
This is the html of the last try i've done
<div class="parent">
<div style="background: green">
<div class="left-content" style="background: green">
<p class="top-titre">title</p>
</div>
<div class="center-content" style="background: green">
<div>
<img src="..." alt="">
</div>
</div>
<div class="right-content">
<div class="clip-top" style="background: yellow"></div>
<div class="d-flex flex-column content" style="background: yellow">
<p>subtitle</p>
<p>description</p>
</div>
<div class="clip-bottom" style="background: yellow"></div>
</div>
</div>
<div class="clip-bottom" style="background: #000000"></div>
</div>
and the last css
.parent {
margin: auto;
display: flex;
flex-direction: column;
width: 85%;
> .clip-bottom {
width: 100%;
height: 100px;
clip-path: polygon(100% 0, 0 0, 0 70%);
}
> div {
position: relative;
padding: 0 120px 0 95px;
width: 100%;
display: flex;
//clip-path: polygon(0 0, 100% 0, 100% 85%, 0% 100%);
.left-content {
width: 20%;
display: flex;
position: relative;
z-index: 5;
p {
color: white;
font-size: 2em;
font-weight: bold;
}
}
.center-content {
width: 25%;
position: relative;
img {
position: absolute;
bottom: 0;
left: 100%;
transform: translateX(-50%);
z-index: 20;
}
}
.right-content {
position: relative;
z-index: 10;
width: 55%;
.content {
padding: 40px 50px 60px 300px;
.field--name-field-titre {
.field__item {
font-size: 1.5em;
font-weight: bold;
}
}
.field--name-field-description {
padding: 70px 0 90px;
}
}
.clip-top, .clip-bottom {
height: 100px;
}
.clip-top {
clip-path: polygon(100% 30%, 0 100%, 100% 100%);
}
.clip-bottom {
clip-path: polygon(100% 0, 0 0, 100% 70%);
}
}
}
}

Related

Is this elmement layout possible in CSS? Overlapping shapes with transparency in a specific arrangement

I'm trying to replicate a design using CSS, a simplified example of this is below:
The pink background should be 50% opacity, however the blue offset shadow/border should be 100% opacity.
I can do the general shapes but not in a way to achieve the desired transparency.
Here is an attempt I made:
.container {
position: relative;
margin: 0 auto;
width: 600px;
height: 200px;
}
.content-wrap {
position: relative;
z-index: 1;
filter: drop-shadow(13px 15px 0 rgb(0,255,255));
width: 60%;
height: 100%;
}
.content {
clip-path: polygon(0 0, 100% 0, 70% 100%, 0% 100%);
background: rgba(255,0,255, 0.5);
height: 200px;
}
.background {
z-index: 0;
position: absolute;
top: 20px;
left: 0;
background: black;
width: 500px;
height: 90px;
margin-top: 50px;
}
<div class="container">
<div class="content-wrap">
<!-- Blue -->
<div class="content">
<!-- Pink -->
</div>
</div>
<div class="background">
<!-- Black -->
</div>
</div>
A couple of aspects are not quite right:
The drop-shadow is visible through the pink, it should just be outside of the element.
The blue should extend to the left-hand edge.
The blue is transparent when I have not assigned it to be, it seems to be related to the child element's background being transparent.
Are there any CSS masters who can figure out a way to do this? The HTML can change if needed.
a box-shadow with skew transformation can do the job here. I am using pseudo-element for the sake of the demo but you can replace them with real elements
.box {
margin: 10px 0;
display: flex;
position: relative;
}
.box::before {
content: "";
position: absolute;
inset: 30% 0;
background: black;
}
.box::after {
content: "";
height: 200px;
width: 50%;
transform-origin: top;
transform: skew(-20deg);
background: rgb(255 0 255/80%);
box-shadow: 25px 25px 0 blue;
}
body {
margin: 0
}
<div class="box">
</div>

image to take the all space of the container

attached a js fiddle to show my issue. I want the orange image to take all the top area of the card and not have padding on the top and sides. the image should show from the very top and takes all the sides with no space
link to fiddle
.pricing-card {
color: black;
width: 100%;
max-width: 330px;
max-height: 463px;
flex-flow: column;
background: #ffffff 0% 0% no-repeat padding-box;
box-shadow: 0px 10px 70px #2e231d1a;
border-radius: 50px;
opacity: 1;
min-height: 550px;
margin: auto;
}
#logo {
top: 50px;
position: absolute;
left: 50px;
}
#rectangle {
max-width: 330px;
}
<div class="price-container">
<div v-if="checkDomainTrial" class="price-text">
Get your entire first month free on us!
</div>
<div class="header">
<div id="wait">Wait! Don't go yet!</div>
</div>
<div class="pricing-card">
<div class="pricing-card-header">
<img id="rectangle" src="https://i.ibb.co/FVkvCv5/Rectangle-cancellation.png" alt="" />

Not able to show image in Diagonally split html page.Please check the code and let me know the issue [duplicate]

This question already has answers here:
two divs split with diagonal line - CSS
(1 answer)
Responsively Align Slanted Divs
(1 answer)
Closed 1 year ago.
I have created one HTML page which is diagonally split.I have put image in right side and some content and button in left.But i am facing 2 issue with my code
1- right side is not fixed and image is not coming properly.
2- The split is not happen for full page
code is here:-
HTML:-
body {
margin: 0;
font-size: 2em;
}
#landing-area {
width: 100vw;
height: 100vh;
display: flex;
}
#box-left {
width: 50%;
clip-path: polygon(0 0, calc(100% - 10vh) 0, 100% 100%, 0 100%);
-webkit-clip-path: polygon(0 0, calc(100% - 10vh) 0, 100% 100%, 0 100%);
margin-right: -4.2vh;
padding: 5px 11vh 5px 5px;
background-color: #F4FCFF;
text-align: center;
}
#box-right {
width: 50%;
clip-path: polygon(0 0, 100% 0, 100% 100%, calc(0% + 10vh) 100%);
-webkit-clip-path: polygon(0 0, 100% 0, 100% 100%, calc(0% + 10vh) 100%);
margin-left: -4.2vh;
padding: 5px 5px 5px 11vh;
text-align: center;
}
#middle-text {
height: 200px;
width: 400px;
position: fixed;
top: 50%;
left: 25%;
margin-top: -100px;
margin-left: -200px;
}
<body>
<div id="landing-area">
<div id="box-left">
<div id="middle-text">
<img src="images/logo.png">
<h>Header goes here</h>
<p>4 line paragraph goes here</p>
<button>Button name</button></div>
</div>
<div id="box-right">
<img src="images/landingPage.png">
</div>
</div>
</body>
Image:-
I want the page should be look like below
I suggest a slightly different approach because you want to be sure that your text etc within the left block will fit whatever the viewport width. One way of ensuring this is to have the left hand block at width 50% less 10vh. i.e. not try the complicaed business of getting text to fit within a sloping side.
This snippet gives the whole page the pale background color, the left block sized as above and the right block it gives width 50% plus 10vh and clips it (polygon is slightly altered to make it correct for this width).
body {
margin: 0;
font-size: 2em;
}
#landing-area {
width: 100vw;
height: 100vh;
background-color: #F4FCFF;
position: relative;
}
#box-left {
width: calc(50% - 10vh);
padding: 5px 11vh 5px 5px;
text-align: center;
display: inline-block;
height: 100%;
box-sizing: border-box;
}
#box-right {
width: calc(50% + 10vh);
clip-path: polygon(10vh 0, 100% 0, 100% 100%, 0 100%);
padding: 5px 5px 5px 11vh;
text-align: center;
background-image: url(https://picsum.photos/id/131/1024/768?blur=2);
background-size: cover;
background-position: center center;
display: inline-block;
height: 100%;
position: absolute;
box-sizing: border-box;
}
#middle-text {
height: 200px;
width: 400px;
position: fixed;
top: 50%;
left: 25%;
margin-top: -100px;
margin-left: -200px;
}
<div id="landing-area">
<div id="box-left">
<div id="middle-text">
<img src="images/logo.png">
<h>Header goes here</h>
<p>4 line paragraph goes here</p>
<button>Button name</button></div>
</div>
<div id="box-right">
</div>
</div>
Note: you'd need to make your px dimensions currently used for the text into relative ones so that the whole thing is responsive (this is true whether you use the method here or some other method).
You can see the code from codepen. Visit https://codepen.io/chris22smith/pen/vvYBGY
HTML:-
<body>
<div class="view">
<div class="left">
<div class="sun"></div>
</div>
<div class="divider"></div>
<div class="right">
<div class="moon"></div>
</div>
</div>
</body>
CSS:-
body {
overflow:hidden;
}
.view {
bottom:0;
left:0;
position:absolute;
right:0;
top:0;
transform:skew(-10deg);
}
.left,
.right {
bottom:0;
overflow:hidden;
position:absolute;
top:0;
}
.left {
left:-5%;
right:50%;
}
.divider {
background-color:#fc0;
border-left:solid 2px #000;
border-right:solid 2px #000;
bottom:-5%;
left:50%;
position:absolute;
right:50%;
top:-5%;
z-index:1;
}
.right {
left:50%;
right:-5%;
}
.sun,
.moon {
bottom:-5%;
left:-5%;
position:absolute;
right:-5%;
top:-5%;
transform:skew(5deg);
}
.sun {
background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/71829/sun.jpg);
background-position:center center;
background-size:cover;
}
.moon {
background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/71829/moon.jpg);
background-position:center center;
background-size:cover;
}

I want to have an image align left with the text in the <h1> tags below but am trouble finding a solution

I need to have a second image align left of the text but layered on top of the background image. I am having some trouble figuring out what css I need to make this work. Currently everything I have tried messes with the text positioning or the background image.
Luckily, this is a personal project so there is no timeline but I would appreciate any help that could be given.
I just started learning web development this past year so it all still feels a little new to me.
.hero-full-container {
height: 100vh;
position: relative
}
.background-image-container {
background-size: cover;
background-repeat: no-repeat;
background-position: 50%
}
.white-text-container h1 {
color: #fff
}
.overlay-gradient {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-image: -webkit-linear-gradient(top, rgba(0, 0, 0, .3), transparent);
background-image: -o-linear-gradient(top, rgba(0, 0, 0, .3) 0, transparent 100%);
background-image: linear-gradient(180deg, rgba(0, 0, 0, .3) 0, transparent);
background-repeat: repeat-x;
filter: progid: DXImageTransform.Microsoft.gradient(startColorstr="#4D000000", endColorstr="#00000000", GradientType=0)
}
.container {
margin-right: auto;
margin-left: auto;
padding-left: 15px;
padding-right: 15px
}
.row {
margin-left: -15px;
margin-right: -15px
}
.col-xs-12 {
position: relative;
min-height: 1px;
padding-left: 15px;
padding-right: 15px
}
.col-md-7 {
width: 58.33333%
}
.col-md-offset-1 {
margin-left: 8.33333%
}
.hero-full-wrapper .text-content {
padding-top: 30%
}
<div class="hero-full-container background-image-container white-text-container" style="background-image:url('./assets/images/home_01.jpg')">
<div class="overlay-gradient"></div>
<div class="container">
<div class="row">
<div class="col-xs-12 col-md-7 col-md-offset-1">
<div class="hero-full-wrapper">
<div class="text-content">
<h1>William</h1>
<h1>Mark</h1>
<h1>Derichsweiler</h1>
<!--<p>Lorem ipsum</p>-->
</div>
</div>
</div>
</div>
</div>
</div>
I don't undestand very well your question, but if you want to have a background image and another image above this image, you can do this creating more div. Once you insert a background image, you can insert another div inside this div, e.g. :
<div class="main-container">
<div class="second-image">
<img src="link_to_your_image">
</div>
<div class="text-area">
<h1>William</h1>
<h1>Mark</h1>
<h1>Derichsweiler</h1>
</div>
</div>
and the for css, you can use flex property, setting the direction to flex-direction: row, e.g. :
*{
margin: 0;
padding: 0;
}
html, body {
height: 100%;
}
.main-container {
width: 100%;
height: 100%;
background-image: url('link_to_your_image');
background-color: red;
display: flex;
flex-direction: row;
align-items: center;
}
.second-image, .text-area {
margin-left: 50px;
}
I hope this can help you, have a nice day.

Invert colored text related background

I want to invert text color based on the background of the text, like in this image: .
So I've tried the following code, but it didn't work:
#warp,
#text,
#tri {
position: absolute;
top: 0;
left: 0;
width: 150px;
height: 150px;
z-index: 1;
}
#warp {
background-color: orange;
}
#text {
text-align: center;
z-index: 3;
}
#text h1 {
margin: 0;
line-height: 150px;
mix-blend-mode: difference;
}
#tri {
background-color: black;
clip-path: polygon(0 0, 0 100%, 99.8% 150px);
-webkit-clip-path: polygon(0 0, 0 100%, 99.8% 150px);
z-index: 2;
}
<div id="warp">
<div id="text">
<h1>TEXT</h1>
</div>
<div id="tri"></div>
</div>
I found some results about background-image & inverted text, but I don't know how to do it with DIVs.
You can avoid clip-path by using linear-gradient as background and the mix-blend-mode will work perfectly:
#text {
width: 150px;
height: 150px;
z-index: 1;
}
#text {
text-align: center;
background: linear-gradient(to top right, black 50%, orange 51%);
}
#text h1 {
margin: 0;
line-height: 150px;
mix-blend-mode: difference;
color: #fff;
}
<div id="text">
<h1>TEXT</h1>
</div>
If you just add the same text to the tri layer, it works:
Edit: In order to allow selecting the text, I've added another transparent layer that wraps all the text as one unit. It does, however, makes updates more repetitive. As a solution, I've added the attached JavaScript code (which isn't necessary).
var text = "TEXT";
var textElements = document.getElementsByTagName("h1");
for (var i=0; i<textElements.length; i++) {
textElements[i].innerHTML = text;
}
#warp,
#text,
#tri,
#selectable {
position: absolute;
top: 0;
left: 0;
width: 150px;
height: 150px;
}
#warp {
background-color: orange;
}
#text {
text-align: center;
z-index: 1;
}
h1 {
margin: 0;
line-height: 150px;
mix-blend-mode: difference;
}
#tri {
background-color: black;
clip-path: polygon(0 0, 0 100%, 99.8% 150px);
-webkit-clip-path: polygon(0 0, 0 100%, 99.8% 150px);
z-index: 2;
color: blue;
text-align: center;
}
#selectable {
text-align: center;
z-index: 5;
color: transparent;
}
<div id="warp">
<div id="text">
<h1>TEXT</h1>
</div>
<div id="tri">
<h1>TEXT</h1>
</div>
<div id="selectable">
<h1>TEXT</h1>
</div>
</div>