How to split page background with vertical polyline? - html

I found how to split page with vertical line - see jsfiddle:
The code is below -
body {
background-color: white;
}
#background {
position: fixed;
top: 0px;
left: 0px;
width: 50%;
height: 100%;
background-color: black;
z-index: 1;
}
#content {
position: relative;
z-index: 2;
padding: 30px;
text-align: center;
font-weight: bold;
color: red;
font-family: Arial, sans-serif;
}
Now I would like to replace vertical line with polyline to get something like this:
How can I do it with CSS?
P.S. I can not use background image, since polyline can be different (the points will have different coordinates).

You can consider multiple background to achieve this but it may be tricky to find the different values depending on the shape. It's basically a combination of triangle shape and rectangle shape above each other to create the final layer (changing the colors will help you identify each one)
body {
margin:0;
}
.box {
height:100vh;
background:
linear-gradient(to bottom right,#000 49.8%,transparent 50%) 0 0/70% 120%,
linear-gradient(to top right,#000 49.8%,transparent 50%) 0 0/60% 70%,
linear-gradient(#000,#000) 0 100%/50% 31%,
linear-gradient(to bottom right,#000 49.8%,transparent 50%) 55.3% 100%/10% 30.2%;
background-repeat:no-repeat;
}
<div class="box">
</div>
You can also consider clip-path within a pseudo element and it will be easier (https://bennettfeely.com/clippy/)
body {
margin:0;
}
.box {
height:100vh;
position:relative;
}
.box:before {
content:"";
position:absolute;
top:0;
left:0;
bottom:0;
right:20%;
background:#000;
-webkit-clip-path: polygon(0 0, 72% 0, 59% 33%, 68% 62%, 47% 100%, 0 100%);
clip-path: polygon(0 0, 72% 0, 59% 33%, 68% 62%, 47% 100%, 0 100%);
}
<div class="box">
</div>

Related

How to make a curved shape with gradient?

I have to create image like this using CSS:-
If not possible then how can I use this with minimum image size? Like in below code I have used two images but this is also not working...
<div style="background:url('https://i.stack.imgur.com/veeS8.png') no-repeat top center, url('https://i.stack.imgur.com/2i7ed.png') repeat-y top 50px center; widhth:100%; height:800px; background-size:100%;">
</div>
Also possible with masking without using image. This is more flexible. You can control easily the slope by changing the variable.
.container {
--slope: 100px;
width: 100%;
height: 500px;
--mask: radial-gradient(farthest-side, #000 99%, transparent 100%) 50% 0 / 150% calc(var(--slope) * 2) no-repeat,
linear-gradient(#000, #000) 0 100% / 100% calc(100% - var(--slope)) no-repeat;
-webkit-mask: var(--mask);
mask: var(--mask);
background: linear-gradient(90deg, rgba(133, 132, 242, 1) 0%, rgba(35, 136, 253, 1) 50%, rgba(127, 237, 226, 1) 100%);
}
<div class='container'></div>
something like this would work:
div.cont:before {
content: '';
background-image: url(https://i.stack.imgur.com/2i7ed.png);
background-size: 100% auto;
position: absolute;
top: 44px;
left: 0;
right: 0;
bottom: 0;
}
<div class="cont" style="width: 100%;height:800px;background-image: url(https://i.stack.imgur.com/veeS8.png);background-size: 100% auto;background-repeat: no-repeat;position: relative;">
</div>
a trivial task using clip-path
.container {
height: 400px;
background: linear-gradient(90deg, rgba(133,132,242,1), rgba(35,136,253,1), rgba(127,237,226,1));
clip-path:ellipse(90% 100% at bottom); /* simply adjust the 90% */
}
<div class='container'></div>
To have the same curvature on resize use pixel value
.container {
height: 400px;
max-width:800px;
background: linear-gradient(90deg, rgba(133,132,242,1), rgba(35,136,253,1), rgba(127,237,226,1));
clip-path:ellipse(600px 100% at bottom);
}
<div class='container'></div>
.element {
width: 200px;
height: 200px;
border-radius: 100% 100% 0 0 / 20% 20% 0 0;
background-image: linear-gradient(to right, #8684F2 0%, #1BEEE3 100%);
}
You can use CSS Gradient to get this kind of result. You can also use some tools online to generate some gradients like this one:
https://cssgradient.io/
.container {
width: 500px;
height: 500px;
background: rgb(133,132,242);
background: linear-gradient(90deg, rgba(133,132,242,1) 0%, rgba(35,136,253,1) 50%, rgba(127,237,226,1) 100%);
}
<div class='container'>
</div>

Cut off Border effect

I am trying to achieve a cut off border on two points of the browser. top left and top right. I am trying to get the black borders not to scale. Meaning the parts always remain the same width / height while also leaving the extra 7% vh at the bottom. currently I am using a clip-path. Im trying to do this without using svg Thanks!
body {
margin: 0;
padding: 0;
}
.section2 {
background: white;
height: 100vh;
width: 100vw;
clip-path: polygon(1px 9px, 99% 1px, 100% 99%, 1% 100%);
}
.section1 {
background: black;
height: 93vh;
width: 100vw;
}
header {
padding: 10px;
}
<div class="section1">
<div class="section2">
<header>
Zebra
</header>
</div>
</div>
You can try mulitple background like below:
.box {
margin:10px;
height:300px;
background:
linear-gradient(to top left,transparent 47%,#000 50%) top /100% 10px,
linear-gradient(to bottom left,transparent 47%,#000 50%) left /10px 100%,
linear-gradient(to top right,transparent 47%,#000 50%) right /10px 100%;
background-repeat:no-repeat;
padding:10px;
}
<div class="box"> some text </div>
With clip-path it can be done like below
.box {
margin:10px;
height:300px;
padding:10px;
position:relative;
z-index:0;
}
.box::before {
content:"";
position:absolute;
z-index:-1;
top:0;
left:0;
right:0;
bottom:0;
border:10px solid #000;
clip-path:polygon(0 0,100% 0,100% 100%,calc(100% - 10px) 1px,1px 10px,10px 100%, 0 100%);
}
<div class="box"> some text </div>

Creating angled DIV for hero

There's a lot of questions similar to this but they're for edges or have answers incompatible with some browsers. I'd thought of using a gradient image for the background but can achieve the same effect using a background gradient and I'd guess this may be easier to implement with minimal code.
I currently have this, which has flat edges;
.top {
min-width: 100%;
min-height: 400px;
background: linear-gradient(45deg, #FF0000, #00FF00);
}
.main {
min-width: 100%;
min-height: 600px;
background: #0000FF;
}
<div class="top"></div>
<div class="main"></div>
It uses minimal code but I'd be aiming for an angled edge either on the bottom of one and on the top of the other or just the bottom of the top one so that the DIVs match up.
I'd be aiming for something like this…
Of course I could rotate the DIV but then there's overflow. I want something clean so that both DIVs match up. Something using clip-path: polygon could work but I can't figure out the angles or implementation. Any ideas or resources for where to start would be apprecited.
UPDATE
I've figured out how to angle both so that they match up but the DIVs need to be touching for it to look proper.
.top {
min-width: 100%;
min-height: 400px;
background: linear-gradient(45deg, #FF0000, #00FF00);
clip-path: polygon(0 0, 100% 0, 100% 100%, 0 80%);
}
.main {
min-width: 100%;
min-height: 600px;
background: #0000FF;
clip-path: polygon(0 0, 100% 20%, 100% 100%, 0 100%);
}
<div class="top"></div>
<div class="main"></div>
UPDATE 1
Would this work? I added position: relative; and top: -150px; to move it up.
.top {
min-width: 100%;
min-height: 400px;
background: linear-gradient(45deg, #FF0000, #00FF00);
clip-path: polygon(0 0, 100% 0, 100% 100%, 0 80%);
}
.main {
min-width: 100%;
min-height: 600px;
background: #0000FF;
clip-path: polygon(0 0, 100% 20%, 100% 100%, 0 100%);
position: relative;
top: -120px;
}
<div class="top"></div>
<div class="main"></div>

Splitting full page into div triangles and shapes and putting text into them

I'm making a website and I need to split the page in 3 or more "triangles" and center the info in them.
I have tried this:
https://codepen.io/anon/pen/YBZOoy
CSS:
* {
margin: 0;
padding: 0;
}
.clipboard{
-webkit-clip-path: polygon(80% 0, 100% 0, 100% 100%, 20% 100%);clip-path: polygon(80% 0, 100% 0, 100% 100%, 20% 100%);
position: absolute;
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
background-color: #d3d0c9;
background-size: cover;
background-position: center center;
}
.clipboard1 {
-webkit-clip-path: polygon(0 0, 50% 50%, 20% 100%, 0 100%);
clip-path: polygon(0 0, 50% 50%, 20% 100%, 0 100%);
position: absolute;
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
background-color: red;
background-size: cover;
background-position: center center;
}
HTML
<div class="clipboard">
</div>
<div class="clipboard1">
<div class="text">
<h1>testasdd</h1>
</div>
I would like to have info in each "triangle". The text should be formatting according to the shapes.
You can easily do this consider a background layer then place the text where you want:
body {
margin:0;
height:100vh;
background:
linear-gradient(to bottom left ,transparent 49.5%,red 50%),
linear-gradient(to bottom right,transparent 49.5%,#ccc 50%);
}
.first {
font-size:30px;
text-align:center;
}
.second,
.third{
display:inline-block;
width:50%;
text-align:center;
line-height:80vh;
font-size:30px;
}
<div class="first">
some text
</div>
<div class="second">
some text
</div><div class="third">
some text
</div>
You can also try like below:
body {
margin:0;
height:100vh;
background:
linear-gradient(to bottom left,transparent 49.5%,blue 50%) right bottom/50.1% 50.1%,
linear-gradient(to bottom right,transparent 49.5%,blue 50%) left bottom/50.1% 50.1%,
linear-gradient(to bottom left ,transparent 49.5%,red 50%),
linear-gradient(to bottom right,transparent 49.5%,#ccc 50%);
background-repeat:no-repeat;
}
.first,
.fourth{
font-size:30px;
text-align:center;
}
.second,
.third{
display:inline-block;
width:50%;
text-align:center;
line-height:80vh;
font-size:30px;
}
<div class="first">
some text
</div>
<div class="second">
some text
</div><div class="third">
some text
</div>
<div class="fourth">
some text
</div>

Border corner shape scoop doesn't work

I want to achieve the below shape using border-corner-shape property. But it doesn't work.
My code is available below:
.left-1 {
background-color: #3498DB;
border-corner-shape: scoop;
border-radius: 30px;
width: 200px;
height: 200px;
}
<div class="left-1"></div>
Why does it not work?
Using Radial Gradients:
Here is another alternative method to achieve the border corner scoop effect using radial gradients. In this method, we use multiple radial gradients and position them at the corners.
.border-scoop {
height: 300px;
width: 300px;
background: -webkit-radial-gradient(0% 100%, circle, transparent 15%, steelblue 15%) no-repeat, -webkit-radial-gradient(100% 0%, circle, transparent 15%, steelblue 15%) no-repeat, -webkit-radial-gradient(0% 0%, circle, transparent 15%, steelblue 15%) no-repeat, -webkit-radial-gradient(100% 100%, circle, transparent 15%, steelblue 15%) no-repeat;
background: radial-gradient(circle at 0% 100%, transparent 15%, steelblue 15%) no-repeat, radial-gradient(circle at 100% 0%, transparent 15%, steelblue 15%) no-repeat, radial-gradient(circle at 0% 0%, transparent 15%, steelblue 15%) no-repeat, radial-gradient(circle at 100% 100%, transparent 15%, steelblue 15%) no-repeat;
background-position: 0% 100%, 100% 0%, 0% 0%, 100% 100%;
background-size: 75% 75%;
}
body {
background: -webkit-linear-gradient(90deg, crimson, indianred, purple);
background: linear-gradient(90deg, crimson, indianred, purple);
}
<div class="border-scoop"></div>
Using Clip Path:
Scooped border corner effect can also be achieved using clip-path. Pure CSS version supports only basic shapes (circle, polygon, ellipse etc) and does not support a path or combination of shapes but SVG (inline/external) can be used.
.border-scoop {
width: 200px;
height: 200px;
background-color: #3498DB;
-webkit-clip-path: url(#scoop);
clip-path: url(#scoop);
}
body {
background: -webkit-linear-gradient(90deg, crimson, indianred, purple);
background: linear-gradient(90deg, crimson, indianred, purple);
}
<svg width='0' height='0'>
<defs>
<clipPath id='scoop' clipPathUnits='objectBoundingBox'>
<path d='M0.2,0 A0.2,0.2 0 0,1 0,0.2
L0,0.8 A0.2,0.2 0 0,1 0.2,1
L0.8,1 A0.2,0.2 0 0,1 1,0.8
L1,0.2 A0.2,0.2 0 0,1 0.8,0z' />
</clipPath>
</defs>
</svg>
<div class='border-scoop'></div>
Transparent scoop with Box Shadow:
The below snippet is a variant of GCyrillus' answer which needs an extra element but would work even if the background of the page is not a solid color. This method however still has the same fixed and known size limitation that is mentioned in the other answer.
It must be noted that box shadow has much better browser support than radial gradients.
.border-scoop{
height: 300px;
width: 300px;
position: relative;
overflow: hidden;
}
.inner{
position: absolute;
top: 0px; left: 0px;
height: 100%;
width: 100%;
}
.border-scoop:before, .border-scoop:after, .inner:after, .inner:before{
position: absolute;
content: '';
height: 30%; width: 30%;
border-radius: 50%;
background: transparent;
box-shadow: 0px 0px 0px 210px steelblue;
}
.border-scoop:before{
top: -15%; left: 85%;
}
.border-scoop:after{
top: -15%; left: -15%;
}
.inner:after{
top: 85%; left: 85%;
}
.inner:before{
top: 85%; left: -15%;
}
body{
background: -webkit-linear-gradient(90deg, crimson, indianred, purple);
background: linear-gradient(90deg, crimson, indianred, purple);
}
<div class="border-scoop">
<div class="inner"></div>
</div>
This feature (border-corner-shape : curve | scoop | bevel | notch) has not been implemented (it is experimental) yet so it is not applicable in any of the existing browsers.
If the box has known and fixed size, you can fake it with one pseudo-element and box-shadow, and even draw curved borders :
DEMO
HTML :
<div class="scoop">
<p>another single div shaped</p>
</div>
<div class="scoop border">
<p>another single div shaped</p>
</div>
CSS:
.scoop {
position:relative;
height:200px;
width:200px;
overflow:hidden;
}
body {
background:#F3F3F3;/* color reused in pseudo element */
}
.scoop:before{
content:'';
position:absolute;
left:0;
margin:-20px;
height:40px;
width:40px;
border-radius:100%;
background:#F3F3F3;
box-shadow:200px 0 0 #F3F3F3,
0 200px 0 #F3F3F3,
200px 200px 0 #F3F3F3,
0 0 0 500px #2798DE;/* here we draw background-color of parent */
}
div > * {
margin:auto;
position:relative;/* to draw on top of shadowed pseudo element */
}
and to draw borders as well , let's add some extra shadows:
div.border {
box-shadow:
23px 0 0 -20px,/* 23px =>(towards right) width of pseudo seen + fakeborder width 0 0 -20px => reduce size shadow of 20px */
-23px 0 0 -20px,
0 23px 0 -20px,
0 -23px 0 -20px;
}
div.border:before {
box-shadow:
0 0 0 3px,/* draw 3px unblured shadow */
200px 0 0 #F3F3F3,/* mask of main background-color */
200px 0 0 3px ,
0 200px 0 #F3F3F3,
0 200px 0 3px,
200px 200px 0 #F3F3F3,
200px 200px 0 3px,
0 0 0 500px #2798DE;
}