curved div with transparent top - html

I'm trying to create transparent div full width and height around 500px using borders but i have trouble with creating this kind of curved shape.
It should look like on the example image, the yellow shape.
.transparent_bg {
width: 100%;
height: 485px;
background: transparent;
border:solid 5px #000;
border-color:#000 transparent transparent transparent;
border-radius: 50%/200px 200px 0 0;
transform: rotate(180deg);
position: relative;
overflow:hidden;
}
.transparent_bg:after {
content: "";
width: 100%;
height: 485px;
position: absolute;
top: 0;
background: red;
}
<div class="transparent_bg"></div>
I have included a link to my work until this moment but without success.

You can use clip path in both ways (on the top element or the bottom one) and simply make top and bottom to overlay like this :
.first,
.second {
display: inline-block;
margin: 5px;
}
.first .top {
clip-path: circle(72.9% at 50% 27%);
height: 200px;
width: 200px;
background: url(https://picsum.photos/id/10/800/800) center/cover;
position: relative;
}
.first .bottom {
margin-top: -70px;
background: yellow;
height: 100px;
width: 200px;
}
.second .top {
height: 200px;
width: 200px;
background:url(https://picsum.photos/id/10/800/800) center/cover;
position: relative;
}
.second .bottom {
clip-path: polygon(0 25%, 14% 41%, 28% 51%, 49% 54%, 66% 53%, 79% 48%, 89% 39%, 100% 27%, 100% 100%, 47% 100%, 0% 100%);
margin-top: -70px;
background: yellow;
height: 100px;
width: 200px;
}
<div class="first">
<div class="top">
</div>
<div class="bottom">
</div>
</div>
<div class="second">
<div class="top">
</div>
<div class="bottom">
</div>
</div>
Here is a useful link to generate path :
https://bennettfeely.com/clippy/
Here is another idea using radial-gradient
.first {
height: 200px;
width: 400px;
background:
radial-gradient(100% 100% at top, #0000 60%, yellow 61%),
url(https://picsum.photos/id/10/800/800) center/cover;
}
<div class="first">
</div>
Using mask if you want transparency:
.first {
height: 200px;
width: 400px;
background: url(https://picsum.photos/id/10/800/800) center/cover;
-webkit-mask:radial-gradient(100% 100% at top, #fff 60%, #0000 61%);
mask:radial-gradient(100% 100% at top, #fff 60%, #0000 61%);
}
.bottom {
-webkit-mask:radial-gradient(100% 100% at top, #0000 60%, #fff 61%);
mask:radial-gradient(100% 100% at top, #0000 60%, #fff 61%);
}
body {
background:yellow;
}
<div class="first">
</div>
<div class="first bottom">
</div>

If you want to overlay top and bottom, just use clip path both ways (on the top or bottom element).`
.transparent_bg {
width: 100%;
height: 485px;
background: transparent;
border-top-left-radius: 50% 50%;
border-top-right-radius: 50% 50%;
transform: rotate(180deg);
position: relative;
overflow:hidden;
}
.transparent_bg:after {
content: "";
width: 100%;
height: 485px;
position: absolute;
top: 0;
background: red;
}

.transparent_bg {
width: 100%;
height: 485px;
background: transparent;
border-top-left-radius: 50% 50%;
border-top-right-radius: 50% 50%;
transform: rotate(180deg);
position: relative;
overflow:hidden;
}
.transparent_bg:after {
content: "";
width: 100%;
height: 485px;
position: absolute;
top: 0;
background: red;
}
<div class="transparent_bg"></div>

Related

Hide SVG or Image behind border

I have the following problem. I have created an Hexagon that has a coloured border and I would like to place an image or SVG inside the hexagon, and the problem is that I cant figure out how to make the image not go on top of the borders.
.App {
background: black;
min-height: 100vh;
width: 100%;
overflow: hidden;
}
.gridComponent {
margin-top: 35px;
display: grid;
justify-content: center;
gap: 2rem;
}
.hexagon {
position: relative;
height: 600px;
width: 339px;
background: rgb(89, 90, 145);
}
.hexagon:before {
position: absolute;
content: "";
top: 10px;
left: 10px;
height: calc(100% - 20px);
width: calc(100% - 20px);
background: #1e40af;
overflow: hidden;
}
.hexagon,
.hexagon:before {
-webkit-clip-path: polygon(50% 0, 100% 10%, 100% 90%, 50% 100%, 0 90%, 0 10%);
clip-path: polygon(50% 0, 100% 10%, 100% 90%, 50% 100%, 0 90%, 0 10%);
}
.topContainer {
position: relative;
width: 339px;
height: 300px;
}
.topContainer:before {
position: absolute;
content: "";
top: 10px;
left: 10px;
height: calc(100% - 20px);
width: calc(100% - 20px);
background: green;
}
.topContainer,
.topContainer:before {
-webkit-clip-path: polygon( 50% 0, 100% 20%, 100% 100%, 50% 100%, 0 100%, 0 20%);
clip-path: polygon(50% 0, 100% 20%, 100% 100%, 50% 100%, 0 100%, 0 20%);
}
.logoVitality {
position: absolute;
width: 212.06px;
height: 257.19px;
top: 1%;
right: 69%;
overflow: hidden;
}
.anon{
position:absolute;}
.divider {
position: absolute;
width: 339px;
height: 10px;
top: 289.5px;
background: black;
}
.bottomContainer {
position: relative;
width: 339px;
height: 300px;
}
.bottomContainer:before {
position: absolute;
content: "";
}
.bottomContainer,
.bottomContainer:before {
-webkit-clip-path: polygon(50% 100%, 100% 81%, 100% 0, 50% 0, 0 0, 0 81%);
clip-path: polygon(50% 100%, 100% 81%, 100% 0, 50% 0, 0 0, 0 81%);
}
.bottomContainer:before {
top: 0px;
left: 10px;
height: calc(100% - 10px);
width: calc(100% - 20px);
background: grey;
}
<div class="App">
<div class="gridComponent">
<div class="hexagon">
<div class="topContainer">
</div>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b0/NewTux.svg/640px-NewTux.svg.png"class="logoVitality"/>
<div class="divider"></div>
<div class="bottomContainer"></div>
</div>
</div>
</div>
I have this codesandbox where you can see the issue. https://codesandbox.io/s/focused-hooks-19rrjj?file=/src/styles.css and I would like to get the image that is outside of the hexagon to be behind the border, I but just could not find a solution. I tried using z-index and playing around with the positions, but I could not figure out.
Thank you for your help!

CSS Shape with Gradient Next Adjacent to Container

I'm trying to put together a specific design for a website we are building. The header needs a parallelogram shape above it, and a trapezium to the right of the container, as shown below.
I've managed to add the parallelogram above the container, but i'm struggling to get the element to the right of the container. The following shows what i've done.
HTML
<div class="container">
<div class="row">
<div class="col">
Content Here
</div>
</div>
</div>
CSS
.container {
width: 700px;
}
.container:before {
content:'';
width: 100%;
height: 30px;
transform: skew(45deg);
background: #254896;
background: linear-gradient(90deg, #254896, #2c2b5b 100%);
display: block;
}
.row {
background: #f8f9fa;
}
.row:before {
content:'';
width: 100%;
height: 0;
border-image-source: linear-gradient(90deg, #FF0000, #940202);
border-image-slice: 1;
border-top: 30px solid red;
border-left: 30px solid transparent;
position: absolute;
left: 800px;
top: 30px;
}
.col {
background-color: #ddd;
padding: 10px;
}
https://jsfiddle.net/scarrott/vgtpna14/
The issues i'm having are:
Getting the red shape to sit neatly to the right of the container regardless of screen size.
Putting a gradient fill on the trapezium shape. If I use border-image-source it makes the shape a rectangle.
Any help would be greatly appreciated.
Here is an idea using multiple background. I used 400px instead of 700px to better see in the snippet
body {
overflow-x: hidden;
}
.container {
--w:400px;
max-width: var(--w);
position: relative;
margin: 40px auto;
}
.container:before {
content: '';
position: absolute;
top: -20px;
left: 0;
width: calc(50vw + var(--w)/2);
min-width: 100%;
height: 40px;
transform: skew(45deg);
transform-origin: top;
background:
linear-gradient(90deg, #254896, #2c2b5b 100%) top left/var(--w) 50%,
linear-gradient(90deg, #FF0000, #940202) bottom right /calc(100% - var(--w)) 50%;
background-repeat: no-repeat;
}
.row {
background: #f8f9fa;
}
.col {
padding: 10px;
}
<div class="container">
<div class="row">
<div class="col">
Content Here
</div>
</div>
</div>
Another idea with clip-path:
body {
overflow-x: hidden;
}
.container {
--w:400px;
max-width: var(--w);
position: relative;
margin: 40px auto;
}
.container:before {
content: '';
position: absolute;
top: -20px;
left: 0;
width: calc(50vw + var(--w)/2);
min-width: 100%;
height: 40px;
clip-path:polygon(0 0, calc(var(--w) - 20px) 0,var(--w) 50%,100% 50%,100% 100%,calc(var(--w) + 20px) 100%,var(--w) 50%, 20px 50%);
background:
linear-gradient(90deg, #254896, #2c2b5b 100%) top left/var(--w) 50%,
linear-gradient(90deg, #FF0000, #940202) bottom right /calc(100% - var(--w)) 50%;
background-repeat: no-repeat;
}
.row {
background: #f8f9fa;
}
.col {
padding: 10px;
}
<div class="container">
<div class="row">
<div class="col">
Content Here
</div>
</div>
</div>
Including bootstrap
body {
overflow-x: hidden;
}
.container {
--w: 540px;
position: relative;
margin-top: 40px;
}
#media (min-width: 768px) {
.container {
--w: 720px;
}
}
#media (min-width: 992px) {
.container {
--w: 960px;
}
}
#media (min-width: 1200px) {
.container {
--w: 1140px;
}
}
.container:before {
content: '';
position: absolute;
top: -20px;
left: 0;
width: calc(50vw + var(--w)/2);
min-width: 100%;
height: 40px;
clip-path: polygon(0 0, calc(var(--w) - 20px) 0, var(--w) 50%, 100% 50%, 100% 100%, calc(var(--w) + 20px) 100%, var(--w) 50%, 20px 50%);
background:
linear-gradient(90deg, #254896, #2c2b5b 100%) top left/var(--w) 50%,
linear-gradient(90deg, #FF0000, #940202) bottom right /calc(100% - var(--w)) 50%;
background-repeat: no-repeat;
}
.row {
background: #f8f9fa;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<div class="container">
<div class="row">
<div class="col">
Content Here
</div>
</div>
</div>
Another approach would be to to have the 2 parallelogram shapes inside the container div with specified percentages.
.row::before {
content: '';
width: calc(70% - 14px);
height: 30px;
transform: skew(45deg);
background: #254896;
background: linear-gradient(90deg, #254896, #2c2b5b 100%);
}
.row::after {
content: '';
width: calc(30% - 14px);
height: 30px;
position: absolute;
right: 0;
top: 30px;
transform: skew(45deg);
background: red;
background: linear-gradient(90deg, #FF0000, #940202);
}
jsFiddle

curved shape with curved line with blur effect CSS

the result I need to get:
what i have so far
header {
min-height: 300px;
background: #000;
}
main {
position: relative;
width: 100%;
overflow: hidden;
min-height: 300px;
}
main:before {
content: '';
position: absolute;
background: #000;
top: 0;
left: 0;
width: 100%;
height: 200px;
}
main:after {
content: '';
position: absolute;
top: 0rem;
background: #141f36;
width: 120%;
height: 300px;
margin-left: -10%;
margin-right: 10%;
border-radius: 200vh 200vh 0% 0% / 20vh 20vh 0% 0%;
}
<div class="page">
<header></header>
<main></main>
</div>
I have no idea how to make the line, can someone help me with this?
NOTE: the line needs to have blur/bright/light effect just like in the example image
Here is a single div idea with radial-gradients.
div {
min-height: 400px;
width: 100%;
/* you can change these variables to see what they do */
--top-distance: 3%;
--line-width: 0.3%;
--blur: 0.5%;
--gradient-top-distance: 100px;
--s: 350%; /* increase this to reduce the slope. */
background: radial-gradient(farthest-side at center bottom, transparent 0 calc(100% - (var(--top-distance) + var(--blur)*2 + var(--line-width))), #0c5dd3 calc(100% - (var(--top-distance) + var(--blur) + var(--line-width))) calc(100% - (var(--top-distance) + var(--blur))), transparent calc(100% - var(--top-distance)) 100%) 50% calc(100% + var(--gradient-top-distance))/var(--s) 100% no-repeat,
radial-gradient(farthest-side at center bottom, #141f36 99%, transparent 100%) 50% calc(100% + var(--gradient-top-distance))/var(--s) 100% no-repeat;
background-color: #000;
}
<div></div>
You can add another pseudo element where you apply a blur filter
main {
position: relative;
overflow: hidden;
min-height: 400px;
background: #000;
}
main:before,
main:after{
content: '';
position: absolute;
height:300px;
background: #141f36;
left:-10%;
right:-10%;
bottom:0;
border-radius: 200vh 200vh 0% 0% / 20vh 20vh 0% 0%;
}
main:after {
border:3px solid #0c5dd3;
filter:blur(1px);
bottom:-22px;
background:none;
}
<main></main>

3 Different Shaped Divs together

I hope you can help me. I have this idea to create 3 divs with different shapes. 1st triangle 2nd rhombus 3rd triangle. When putting together they make one rectangle. I created 3 div figures but have a problem putting them together. I will appreciate your help.
Note: I have tried flex but then the main div is separated into 3 parallel sections.
HTML
.triangle {
width: 80%;
height: 300px;
border: 2px solid black;
margin: 20px auto;
background: grey;
}
.triangle .figure_1 {
width: 50%;
display: inline-flex;
clip-path: polygon(0% 0%, 0% 100%, 100% 100%);
background: green;
}
.triangle .figure_2 {
width: 100%;
clip-path: polygon(0% 0%, 50% 100%, 100% 100%, 50% 0%);
background: yellow;
}
.triangle .figure_3 {
width: 50%;
clip-path: polygon(0% 0%, 100% 100%, 100% 0%);
background: red;
}
<div id="triangle" class="triangle">
<div id="figure_1" class="figure_1">
</div>
<div id="figure_2" class="figure_2">
</div>
<div id="figure_3" class="figure_3">
</div>
</div>
Try to make your triangle as relative and figure as absolute
.triangle {
width: 80%;
height: 300px;
border: 2px solid black;
margin: 20px auto;
background: grey;
position: relative;
}
.triangle .figure_1 {
width: 50%;
display: inline-flex;
clip-path: polygon(0% 0%, 0% 100%, 100% 100%);
background: green;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.triangle .figure_2 {
width: 100%;
clip-path: polygon(0% 0%, 50% 100%, 100% 100%, 50% 0%);
background: yellow;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.triangle .figure_3 {
width: 50%;
clip-path: polygon(0% 0%, 100% 100%, 100% 0%);
background: red;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
<div id="triangle" class="triangle">
<div id="figure_1" class="figure_1">
</div>
<div id="figure_2" class="figure_2">
</div>
<div id="figure_3" class="figure_3">
</div>
</div>

Make a background image fill all the space when rotated

I have a div which has been rotated 45 degrees, this creates a diamond shape. Inside I have another div with a minus 45-degree rotation so the content is square I set the inner container to have 100% width & heightbut because of the rotation, it doesn't fill all the space.
I know the output I get is accurate to the code I've written because of the rotation it is 100%, so I suppose I need it larger than 100% and to scale as the browser scales.
.headerImg {
position: absolute;
top: -100px;
right: -100px;
width: 50%;
display: block;
background: #eee;
height: 95vh;
overflow: hidden;
transform: rotate(45deg);
}
.rotateBack {
width: 100%;
height: 100%;
transform: rotate(-45deg);
background-repeat: no-repeat;
background-size: cover;
background-position: center;
}
<div class="headerImg">
<div class="rotateBack" style="background-image: url('https://www.rd.com/wp-content/uploads/2017/06/05-dog-breed-Safety-Tips-to-Keep-Your-Dog-in-Top-Shape-This-Summer-508549561-Yevgen-Romanenko.jpg')">
</div>
</div>
An example JSFiddle
HTML
<div class="part">
<div class="losange">
<div class="los1">
<img src="http://farm3.staticflickr.com/2178/3531465579_8bff044e9b_z.jpg?zz=1" alt="" width="255" height="320" />
</div>
</div>
CSS
.losange, .losange div {
margin: 0 auto;
transform-origin: 50% 50%;
overflow: hidden;
width: 250px;
height: 250px;
}
.losange {
transform: rotate(45deg) translateY(10px);
}
.losange .los1 {
width: 355px;
height: 355px;
transform: rotate(-45deg) translateY(-74px);
}
.losange .los1 img {
width: 100%;
height: auto;
}
I found this and have used for a project of mine. Hope it helps you, understand the main idea.
Since the container div has fixed size you can use absolute position with the image and make it overflow by specifing negative values on top/left/bottom/right;
.headerImg {
width: 50%;
margin: auto;
display: block;
background: #eee;
height: 95vh;
overflow: hidden;
transform: rotate(45deg);
position: relative;
}
.rotateBack {
position: absolute;
top: -30%;
left: -30%;
bottom: -30%;
right: -30%;
transform: rotate(-45deg);
background-repeat: no-repeat;
background-size: cover;
background-position: center;
}
<div class="headerImg">
<div class="rotateBack" style="background-image: url('https://www.rd.com/wp-content/uploads/2017/06/05-dog-breed-Safety-Tips-to-Keep-Your-Dog-in-Top-Shape-This-Summer-508549561-Yevgen-Romanenko.jpg')">
</div>
</div>
By the way here is another way to achive what you want using clip-path:
body {
margin: 0;
}
.rotateBack {
height: 100vh;
width: 50%;
margin: auto;
clip-path: polygon(50% 0, 0 50%, 50% 100%, 100% 50%);
background-repeat: no-repeat;
background-size: cover;
background-position: center;
}
<div class="rotateBack" style="background-image: url('https://www.rd.com/wp-content/uploads/2017/06/05-dog-breed-Safety-Tips-to-Keep-Your-Dog-in-Top-Shape-This-Summer-508549561-Yevgen-Romanenko.jpg')">
</div>
Or using linear-gradient (but the background cannot be transparent):
body {
margin: 0;
}
.back {
height: 100vh;
width: 50%;
margin: auto;
background:
linear-gradient(45deg, #fff 25%, transparent 20%, transparent 75%, #fff 70%),
linear-gradient(-45deg, #fff 25%, transparent 20%, transparent 75%, #fff 20%),
url('https://www.rd.com/wp-content/uploads/2017/06/05-dog-breed-Safety-Tips-to-Keep-Your-Dog-in-Top-Shape-This-Summer-508549561-Yevgen-Romanenko.jpg') center/cover no-repeat;
}
<div class="back">
</div>