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>
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;
}
Imagine that we have two layers of background.
The bottom layer is green <div class="green"></div>. For simplicity, let's assume it's just a color. But in my project, this layer contains a css animation.
And another layer of blue goes on top of it <div class="blue"></div>.
Now, I want to have another div that goes on top of both, and it reveals the green background (animation layer in my project).
The closest example I can think of is if you imagine a spotlight. Everything seems black, and the spotlight moves around and reveals the background.
Essentially, that's what I have:
<div class="green">
<div class="blue">
<div class="reveal"></div>
</div>
</div>
It will look something like this. Just remember, the green layer is an animation in my project.
QUESTION: how can I complete the .reveal styles to achieve the above behavior.
First div - draws .green background (animation)
Second dv - draws .blue background goes on top of it
Third/Fourth/... divs - Goes on top of both, but it reveals whatever the background First div draws
Note: First and Second div covers 100% of the available width and height.
.green {
background-color: #159c82;
width: 100vw;
height: 100vh;
}
.blue {
background-color: #1b4287;
// I could change this to a sibling div and use,
// position: absolute; but that seems unnecessary
width: 100%;
height: 100%;
}
.reveal {
margin-top: 10px;
margin-left: 10px;
width: 200px;
height: 50px;
// not sure what else to put here to make it work
}
<div class="green">
<div class="blue">
<div class="reveal"></div>
</div>
</div>
P.S. There is one approach I found that I did not like at all.
Use mask to create a hole and no need for the reveal div. You can later change the size and position to have the animation you want:
.green {
background: linear-gradient(45deg,#159c82,red);
height: 100vh;
}
.blue {
background:#1b4287;
height: 100%;
-webkit-mask:
/* you adjust this */
linear-gradient(#fff,#fff)
50px 50px/ /*left top*/
200px 20px, /*width height*/
/**/
linear-gradient(#fff,#fff);
-webkit-mask-repeat:no-repeat;
-webkit-mask-composite: destination-out;
mask:
/* you adjust this */
linear-gradient(#fff,#fff)
50px 50px/ /*left top*/
200px 20px, /*width height*/
/**/
linear-gradient(#fff,#fff);
mask-repeat:no-repeat;
mask-composite:exclude;
transition:.5s;
}
.blue:hover {
-webkit-mask-position:100px 100px,0 0;
mask-position:100px 150px,0 0;
-webkit-mask-size:300px 50px,auto;
mask-size:300px 50px,auto;
}
body {
margin: 0;
}
<div class="green">
<div class="blue">
</div>
</div>
You can also add as many mask as you want:
.green {
background: url(https://picsum.photos/id/1018/800/800) center/cover;
height: 100vh;
}
.blue {
background:#1b4287;
height: 100%;
-webkit-mask:
/* 3rd mask */
radial-gradient(farthest-side,#fff 99%,transparent)
top 50px right 50px/
100px 100px,
/**/
/* 2nd mask */
linear-gradient(#fff,#fff)
bottom 50px right 50px/
300px 20px,
/**/
/* 1st mask */
linear-gradient(#fff,#fff)
50px 50px/
200px 20px,
/**/
linear-gradient(#fff,#fff);
-webkit-mask-repeat:no-repeat;
-webkit-mask-composite: destination-out;
mask:
/* 3rd mask */
radial-gradient(farthest-side,#fff 99%,transparent)
top 50px right 50px/
100px 100px,
/**/
/* 2nd mask */
linear-gradient(#fff,#fff)
bottom 50px right 50px/
300px 20px,
/**/
/* 1st mask */
linear-gradient(#fff,#fff)
50px 50px/
200px 20px,
/**/
linear-gradient(#fff,#fff);
mask-repeat:no-repeat;
mask-composite:exclude;
transition:.5s;
}
.blue:hover {
-webkit-mask-position:
100px 100px,
bottom 100px left 50px,
top 50px right 50px,
0 0;
mask-position:
100px 100px,
bottom 100px left 50px,
top 50px right 50px,
0 0;
-webkit-mask-size:
150px 150px,
50px 50px,
300px 50px,
auto;
mask-size:
150px 150px,
50px 50px,
300px 50px,
auto;
}
body {
margin: 0;
}
<div class="green">
<div class="blue">
</div>
</div>
A techhnique that will work, with an even simpler layout, is box-shadow
.layer1 {
width: 100%;
height: 100%;
position: absolute;
background-image: linear-gradient(yellow, blue);
background-size: 200% 200%;
animation: bkg 2s infinite alternate;
background-origin: padding-box;
}
.layer2 {
width: 200px;
height: 200px;
position: absolute;
background: transparent;
border-radius: 30px;
left: 20px;
top: 40px;
box-shadow: 0px 0px 0px 10000px blue;
}
#keyframes bkg {
from {
background-position: 0 0;
}
to {
background-position: 100% 100%
}
}
<div class="layer1"></div>
<div class="layer2">
</div>
Also, you have a posibility to achieve this using blending.
The main disadvantage is that this uses hard-light , son the colors used in layer2 are limited to having 0 or 255 for the primary colors (red blue and green).
It will work for pure red (255, 0,0), green (0, 255, 0), blue (0, 0, 255), and also (255, 255, 0), (255, 0, 255), (0, 255, 255)
But it has the advantage that you can set severial divs to act as windows
.layer1 {
width: 100%;
height: 100%;
position: absolute;
background-image: linear-gradient(yellow, blue);
background-size: 200% 200%;
animation: bkg 2s infinite alternate;
background-origin: padding-box;
}
.layer2 {
width: 100%;
height: 100%;
position: absolute;
background: rgba(0, 255, 0);
mix-blend-mode: hard-light;
}
.layer3 {
width: 200px;
height: 200px;
position: absolute;
background: grey;
border-radius: 30px;
left: 20px;
top: 40px;
}
#keyframes bkg {
from {
background-position: 0 0;
}
to {
background-position: 100% 100%
}
}
<div class="layer1"></div>
<div class="layer2">
<div class="layer3"></div>
</div>
This will work also for multiple divs:
.layer1 {
width: 100%;
height: 100%;
position: absolute;
background-image: linear-gradient(yellow, blue);
background-size: 200% 200%;
animation: bkg 2s infinite alternate;
background-origin: padding-box;
}
.layer2 {
width: 100%;
height: 100%;
position: absolute;
background: rgba(0, 255, 0);
mix-blend-mode: hard-light;
}
.layer3 {
width: 200px;
height: 200px;
position: absolute;
background: grey;
border-radius: 30px;
left: 20px;
top: 40px;
}
.layer3:nth-child(2) {
left: 120px;
top: 80px;
}
#keyframes bkg {
from {
background-position: 0 0;
}
to {
background-position: 100% 100%
}
}
<div class="layer1"></div>
<div class="layer2">
<div class="layer3"></div>
<div class="layer3"></div>
</div>
Do you want to put the reveal div in this postion only, or show the green color from the bottom layer?
for only the positon you can add realtive position in your blue div and absolute position in your reveal div with top and left values.
.green {
background-color: #159c82;
width: 100vw;
height: 100vh;
}
.blue {
background-color: #1b4287;
width: 100%;
height: 100%;
position: relative;
}
.reveal {
position: absolute;
top: 10px;
left: 10px;
width: 200px;
height: 50px;
}
If I understand you correctly you probably should use a css variable.
https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties
Editing your example we get the following.
:root {
--bottom-layer-color: #159c82
}
.green {
background-color: var(--bottom-layer-color);
width: 100vw;
height: 100vh;
}
.blue {
background-color: #1b4287;
width: 100%;
height: 100%;
}
.reveal {
margin-top: 10px;
margin-left: 10px;
width: 200px;
height: 50px;
background-color: var(--bottom-layer-color)
}
<div class="green">
<div class="blue">
<div class="reveal"></div>
</div>
</div>
cheers,
to change the color with css:
/* Use a later css file to redeclare the root variable, */
/* this will override previously declared css. */
/* https://css-tricks.com/precedence-css-order-css-matters/ */
:root {
--bottom-layer-color: powderblue
}
to change the color with javascript:
const eStyle = document.documentElement.style
eStyle.setProperty('--top-bar-height', '263px');
You can change a lot of things with css variables. Not just background-colors.
For instance
root: {
--bottom-layer-color: #159c82
--bottom-layer-radius: 50%;
/* this would make the bottom layer a circle. And reaveal a circle. */
}
.green {
background-color: var(--bottom-layer-color)
border-radius: var(--bottom-layer-color)
width: 100vw;
height: 100vh;
}
.reveal {
background-color: var(--bottom-layer-color)
border-radius: var(--bottom-layer-color)
}
/* Set --bottom-layer-radius back to 0 to make both items square again. */
This is one of the easiest things to do in CSS
<Style>
.blue {
width: 100%;
height: 300px;
background-color: lightblue;
}
</style>
<div class="blue">
</div>
Hi i want effect like this on my div but only at the top:
I know there is css mask property but it's really complicated to me.
My solution is I created single circle svg and repeat it multiple times but i also need that left/right space.
.container {
margin: 20px 0;
height: 400px;
background: lightgray;
position: relative;
}
.svg {
background: url('../../assets/circle-gapped.svg');
height: 100%;
background-repeat: repeat-x;
position: absolute;
left: 0;
right: 0;
top: -30px;
}
<div class="container">
<div class="svg" />
</div>
I don't know how to upload assest to snippet, this is result of above code:
Like below:
.box {
width:300px;
height:200px;
background:red;
-webkit-mask: /* 20px = radius of circle 50px = 2*radius + 10px (distance between circles)*/
radial-gradient(circle 20px,transparent 97%, #fff 100%) bottom/50px 200%,
linear-gradient(#fff 0 0) left /20px 100% no-repeat, /* 20px of left border */
linear-gradient(#fff 0 0) right/20px 100% no-repeat; /* 20px of right border */
}
<div class="box"></div>
Or like below to have responsiveness:
.box {
height:200px;
background:red;
padding:0 50px;
-webkit-mask:
radial-gradient(circle 20px,#fff 97%, transparent 100%) bottom/50px 200% space content-box,
linear-gradient(#fff 0 0);
-webkit-mask-composite:destination-out;
mask-composite: exclude;
}
<div class="box"></div>
You can do this with a pseudo element on the gray div which has a repeating pattern of radial-gradient circles which are 50% radius gray and transparent for the outer 50%. Of course alter the dimensions and positions to give the exact look you want.
div.yellow {
background-color:yellow;
width: 100vw;
height: 80vh;
}
div.gray {
background-color: gray;
height: 20vh;
width: 100vw;
position: relative;
top: 0;
}
div.gray::after {
content:' ';
width: 100vw;
height: 10vh;
background-color: transparent;
position: absolute;
top: 15vh;
left: 0;
z-index: 2;
background-image: radial-gradient(gray,gray 50%,transparent 50%);
background-size: 10vh 10vh;
}
<div class="gray"></div>
<div class="yellow"></div>
I need to make the profile image corner should be blur border. But in my code I can't get exactly.
I need result should be like this:
But my code, blur border is repeated its self. Because, the non blur image also have the same corner. Seems the corner is repeated.
effet {
width: 400px;
height: 125px;
margin: 0 auto 50px auto;
}
.profile-box {
width: 150px;
height: 150px;
margin-left: 40px;
border: none !important;
padding: 19.5px 10px;
display: block;
}
.min_cir {
border-radius: 50%;
border-radius: 50%;
position: absolute;
top: 0;
}
.filtre--r {
-webkit-mask: -webkit-radial-gradient(center, closest-side, transparent 30%, black 80%);
-webkit-mask: radial-gradient(closest-side at center, transparent 50%, black 110%);
-webkit-filter: blur(2px);
mask: url('#mask-radial');
filter: blur(2px);
transform: scale(1.1);
position: absolute;
top: 0;
}
<div class="profile-box">
<div class="media">
<a class="pull-left" href="">
<div class="effet">
<img class="filtre filtre--r min_cir" src="http://i.imgur.com/oH1698V.jpg" />
<img class="min_cir" src="http://i.imgur.com/oH1698V.jpg">
</div>
</a>
</div>
</div>
I need to cut out the non-blur image as per the width of the blur corner.
The scale() method increases or decreases the size of an element (according to the parameters given for the width and height). I think you can achieve needed result by using different vertical and horizontal paramateres for scale() method. Currently you apply 1.1 magnitude for width and height. This is right for forms that have a shape of a square (equal width and height) whereas your image is rectangular( width and height are not equal). Therefore you can write scale() method for example like this : transform: scale(1.09, 1.13);
You can give following way:
Remove scaling first, because it will display like repeating the image.
Then put second image inside another div and give following css as per given in example. Here in example div is imgDiv
And parent div of second image i.e. imgDiv is overflow:hidden and give left and top value and give height and width is (image div - 50px(if want 15px blur)) do the trick.
And give same height and width of both image. Here i give same size as original image.
effet {
width: 400px;
height: 125px;
margin: 0 auto 50px auto;
}
.profile-box {
width: 150px;
height: 150px;
margin-left: 40px;
border: none !important;
padding: 19.5px 10px;
display: block;
}
.min_cir {
border-radius: 50%;
border-radius: 50%;
position: absolute;
top: -20px;
left: -20px;
}
.filtre--r {
-webkit-mask: -webkit-radial-gradient(center, closest-side, transparent 30%, black 80%);
-webkit-mask: radial-gradient(closest-side at center, transparent 50%, black 110%);
-webkit-filter: blur(4px);
mask: url('#mask-radial');
filter: blur(4px);
position: absolute;
top: 0;
left:0;
}
.imgDiv{
border-radius: 50%;
height: 266px;
left: 20px;
overflow: hidden;
position: absolute;
top: 20px;
width: 660px;
}
img{
width: 700px;
height: 306px;
}
<div class="profile-box">
<div class="media">
<a class="pull-left" href="">
<div class="effet">
<img class="filtre filtre--r min_cir" src="http://i.imgur.com/oH1698V.jpg" />
<div class="imgDiv">
<img class="min_cir" src="http://i.imgur.com/oH1698V.jpg">
</div>
</div>
</a>
</div>
</div>