How to create a Cross Curved Box using div [duplicate] - html

This question already has answers here:
'Inverted' border-radius possible? [duplicate]
(3 answers)
Closed 2 months ago.
I want to create a box like this:
It's not looking like that curved. I tried but don't know how to make it. Please help me with some solutions.
.test {
width: 300px;
height: 50px;
background-color: #EFB046;
border-radius: 20px;
display: flex;
justify-content: center;
align-items: center;
}
<div class="test"></div>

You can use gradient like below:
.box {
--r: 40px; /* control the curvature*/
--g: #0000 98%,#EFB046; /* the color here */
width: 250px;
height: 80px;
background:
radial-gradient(var(--r) 100% at var(--r) 0 ,var(--g)) calc(-1*var(--r)) 0,
radial-gradient(var(--r) 100% at var(--r) 100%,var(--g)) calc(-1*var(--r)) 100%;
background-size: 100% 50%;
background-repeat: repeat-x;
}
body {
background: #000;
}
<div class="box"></div>

The trick is used ::before and ::after. In my code you can add border-radius in the CSS.
.pointed {
position: relative;
width:200px;
height:40px;
margin-left:40px;
color:#FFFFFF;
background-color:#c08457;
text-align:center;
line-height:40px;
}
.pointed:before {
content:"";
position: absolute;
right: 100%;
top:0px;
width:0px;
height:0px;
border-top:20px solid transparent;
border-right:40px solid #8d4e24;
border-bottom:20px solid transparent;
}
.pointed:after {
content:"";
position: absolute;
left: 100%;
top:0px;
width:0px;
height:0px;
border-top:20px solid transparent;
border-left:40px solid #8d4e24;
border-bottom:20px solid transparent;
}
<div class="pointed"> Text Content </div>

This question here details what you are requesting
Please Read it and its various answers.
In short it looks like there are 2 approaches.
One is to create 4 elements to block out the content of the main element, the downside to this approach is you will not be able to see any content underneath it incase there is any
The second would be to create an SVG to put in a path element. This would allow you to create the cutout you are looking for. an example could look like as such
Shown below are the HTML and CSS for the 2 possible solutions. Note the path was drawn poorly using a free SVG editor but gives the general idea of what can be done
HTML
<div id="four-element">
<p class="SpanText">Hello World</p>
<div class="top left"></div>
<div class="top right"></div>
<div class="bottom left"></div>
<div class="bottom right"></div>
</div>
<div id="svg">
<svg width="100%" height="270px" \>
<path d="M 52 20 C 53 75 10 135 0 135 C 10 135 55 142 57 272 L 268 270 C 269 180 267 163 304 145 C 266 134 246 62 245 19 L 52 20 Z" fill="blue"/>
<text x="145" y="145" text-anchor="middle" alignment-baseline="middle">
Hello World
</text>
</svg>
</div>
CSS
#four-element {
margin: 40px;
height: 100px;
width: 100px;
background-color: #004C80;
position: relative;
overflow: hidden;
}
#four-element div {
position: absolute;
width: 20px;
height: 20px;
border-radius: 100%;
background-color: #FFFFFF;
}
.SpanText{
position: absolute;
top: 25%;
left: 25%;
}
.top { top: -10px; }
.bottom { bottom: -10px; }
.left { left: -10px; }
.right { right: -10px; }

Related

How can I create curve line with circle inside? [duplicate]

I am building a website, and I'm having a hard time doing a detail in CSS
I need to make a round border that has a curved end, for you to understand better, I will show photo and post my code
What I need (Photoshop)
I would like a CSS solution, but I could not.
Here is what I have actually:
.bottom-bar {
background: #29a7e8;
position: absolute;
bottom: 0;
width: 100%;
height: 50px;
text-align: center;
}
.circle {
display: inline-block;
position: relative;
top: -10px;
border-radius: 100%;
background: #29a7e8;
width: 60px;
height: 60px;
margin: 0 1rem;
}
<div class="bottom-bar">
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
</div>
You can do this using SVG as background:
.bottom-bar {
background: #29a7e8;
position: absolute;
bottom: 0;
width: 100%;
height: 50px;
text-align: center;
}
.circle {
display: inline-block;
position: relative;
top: -28px;
border-radius: 100%;
background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='10 10 45 15' width='64' height='64' fill='%2329a7e8'><path d='M12 24 L52 24 L52 16 C40 16 42 10 32 10 C20 10 22 16 12 16 Z' /></svg>") 0 0/100% 100% no-repeat;
width: 60px;
height: 60px;
margin: 0 1rem;
}
<div class="bottom-bar">
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
</div>
<svg xmlns='http://www.w3.org/2000/svg'
viewBox='10 10 45 15'
width='64' height='64'
fill='#29a7e8'>
<path d='M12 24 L52 24 L52 16 C40 16 42 10 32 10 C20 10 22 16 12 16 Z' />
</svg>
For a CSS only solution you can consider a combination of radial-gradient to create the curve:
.bottom-bar {
background: #29a7e8;
position: absolute;
bottom: 0;
width: 100%;
height: 50px;
text-align: center;
}
.circle {
display: inline-block;
position: relative;
top: -30px;
background:
radial-gradient(circle at top right,transparent 50%,#29a7e8 51%)100% 21px/12px 10px no-repeat,
radial-gradient(circle at top left,transparent 50%,#29a7e8 51%)0 21px/12px 10px no-repeat,
radial-gradient(circle at center,#29a7e8 55%, transparent 56%);
width: 60px;
height: 60px;
margin: 0 1rem;
}
<div class="bottom-bar">
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
</div>
In general, there are for ways to create that kind of shapes, from simple to more complex:
Adding 2 pseudoelements with radial-gradient.
Simplest and well-supported solution. Probably the one I would use.
Adding 2 pseudoelements with mask-image (same as above, but with worse support).
Quite similar, code-wise, to the previews one, but with really bad support (needs browser prefixes for those that support it).
If you want to check how similar they are, take a look at this other similar question: CSS "inverse border-radius" outside element's bounding box to create a mobile phone notch design
Adding 2 pseudoelements with a border-radius, box-shadow and background: transparent.
Needs a bit more code, but it looks a bit smoother, at least on Chrome Version 78.0.3904.108, although the difference is minimal. In any case, the shapes you can do can't be as complex as with the previous alternatives, especially if you want to work with ellipses rather than circles, as it is your case.
Using an SVG.
I think the SVG solution is not worth it here, but it would be a good alternative for more complex shapes or animated/transitioning shapes. In any case, Temani Afif already added a solution using SVG.
Something to keep in mind is that, as that looks like a navigation bar, the hoverable/clickable area of each button should match as good as possible what users actually see, which is not the case for Temani Afif's solutions.
This is what it would look like using radial-gradient:
body {
margin: 0;
font-family: monospace;
background: #DDD;
}
.bar {
background: white;
position: fixed;
bottom: 0;
width: 100%;
height: 60px;
text-align: center;
}
.circle {
position: relative;
top: -10px;
border-radius: 100%;
background: white;
width: 60px;
height: 60px;
margin: 0 16px;
cursor: pointer;
display: inline-flex;
justify-content: center;
align-items: center;
font-size: 24px;
font-weight: bold;
color: black;
transition: box-shadow ease-in 150ms;
background: white;
border: 0;
outline: none;
}
.circle:hover {
box-shadow: 0 16px 16px 0 rgba(0, 0, 0, .125);
}
.circle:active {
box-shadow: 0 8px 8px 0 rgba(0, 0, 0, .125);
}
.circle::before,
.circle::after {
content: "";
position: absolute;
top: 4px;
width: 32px;
height: 6px;
background: white;
z-index: 1;
}
.circle::before {
left: -18px;
background: radial-gradient(ellipse at 0% -25%, transparent 0, transparent 70%, white 70%, white 100%);
}
.circle::after {
right: -18px;
background: radial-gradient(ellipse at 100% -25%, transparent 0, transparent 70%, white 70%, white 100%);
}
<nav class="bar">
<button class="circle">💖</button>
<button class="circle">🚀</button>
<button class="circle">🌍</button>
</nav>
If you want to see a similar question and all the alternatives in action, check this out: CSS "inverse border-radius" outside element's bounding box to create a mobile phone notch design

create shapes with css

.shape {
width: 200px;
height: 50px;
background-color: green;
border-radius: 10px 10px 0 30px;
transform: skewX(0);
}
<div class="shape">Hello World!</div>
We have two following shapes in jpg format. But on certain condition background and border color needs to change to some different color. So idea is to create those images with CSS transform Property (if possible).
{ width: 200px;
height: 50px;
background-color: green;
border-radius: 10px 10px 0 30px;
transform: skewX(0);
}
Using SVG
.a {
fill: #ef0c4d;
stroke: #999;
stroke-miterlimit: 10;
stroke-width: 7px;
}
.a:hover {
fill: green;
stroke: blue;
}
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 680.4 240.3">
<path class="a" d="M135,113.1s7.7,123.6,13.5,164.4c6.3,44.5,13,64,168,64h490L737.7,184.3a5.6,5.6,0,0,0-4.2-3.2L140.1,108.2A4.5,4.5,0,0,0,135,113.1Z" transform="translate(-131.4 -104.7)"/>
</svg>
Using CSS
.rect {
width: 230px;
height: 100px;
overflow: hidden;
position: relative;
}
.rect:before {
content: " ";
position: absolute;
width: 200px;
height: 50px;
background: #dedede;
border-bottom-left-radius: 26px;
right: 30px;
bottom: 0;
}
.rect:after {
content: " ";
position: absolute;
width: 250px;
height: 50px;
background: #dedede;
transform: rotate(10deg) skew(30deg);
bottom: 20px;
left: -38px;
}
<div class="rect"></div>
It will be easier to go with SVG than pure CSS, here is an example:
path {
fill:pink;
}
path:hover {
fill:red;
stroke:#000;
}
<svg
xmlns='http://www.w3.org/2000/svg'
viewBox='0 0 64 64'
width='200' >
<path d='M18 48 L56 48 L46 30 L12 16 C8 14 8 16 8 18 L8 40 C8 44 10 48 14 48 Z' />
</svg>
You may consider this link to easily adjust the shape http://jxnblk.com/paths/?d=M18 48 L56 48 L46 30 L12 16 C8 14 8 16 8 18 L8 40 C8 44 10 48 14 48 Z
What are the 'certain conditions'? If you wanted to change the image color on hover with pure CSS an easy way would be to set the image as a background of a div element. You would then create a second identical image (with new color) to change to.
HTML -
<div id="color-1"></div>
and the CSS
#color-1 {
width:500px;
height:200px;
background-image:url('some/image/path');
}
#color-1:hover {
background-image:url('some-other/image/path');
}

border curved css - circle with curved end

I am building a website, and I'm having a hard time doing a detail in CSS
I need to make a round border that has a curved end, for you to understand better, I will show photo and post my code
What I need (Photoshop)
I would like a CSS solution, but I could not.
Here is what I have actually:
.bottom-bar {
background: #29a7e8;
position: absolute;
bottom: 0;
width: 100%;
height: 50px;
text-align: center;
}
.circle {
display: inline-block;
position: relative;
top: -10px;
border-radius: 100%;
background: #29a7e8;
width: 60px;
height: 60px;
margin: 0 1rem;
}
<div class="bottom-bar">
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
</div>
You can do this using SVG as background:
.bottom-bar {
background: #29a7e8;
position: absolute;
bottom: 0;
width: 100%;
height: 50px;
text-align: center;
}
.circle {
display: inline-block;
position: relative;
top: -28px;
border-radius: 100%;
background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='10 10 45 15' width='64' height='64' fill='%2329a7e8'><path d='M12 24 L52 24 L52 16 C40 16 42 10 32 10 C20 10 22 16 12 16 Z' /></svg>") 0 0/100% 100% no-repeat;
width: 60px;
height: 60px;
margin: 0 1rem;
}
<div class="bottom-bar">
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
</div>
<svg xmlns='http://www.w3.org/2000/svg'
viewBox='10 10 45 15'
width='64' height='64'
fill='#29a7e8'>
<path d='M12 24 L52 24 L52 16 C40 16 42 10 32 10 C20 10 22 16 12 16 Z' />
</svg>
For a CSS only solution you can consider a combination of radial-gradient to create the curve:
.bottom-bar {
background: #29a7e8;
position: absolute;
bottom: 0;
width: 100%;
height: 50px;
text-align: center;
}
.circle {
display: inline-block;
position: relative;
top: -30px;
background:
radial-gradient(circle at top right,transparent 50%,#29a7e8 51%)100% 21px/12px 10px no-repeat,
radial-gradient(circle at top left,transparent 50%,#29a7e8 51%)0 21px/12px 10px no-repeat,
radial-gradient(circle at center,#29a7e8 55%, transparent 56%);
width: 60px;
height: 60px;
margin: 0 1rem;
}
<div class="bottom-bar">
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
</div>
In general, there are for ways to create that kind of shapes, from simple to more complex:
Adding 2 pseudoelements with radial-gradient.
Simplest and well-supported solution. Probably the one I would use.
Adding 2 pseudoelements with mask-image (same as above, but with worse support).
Quite similar, code-wise, to the previews one, but with really bad support (needs browser prefixes for those that support it).
If you want to check how similar they are, take a look at this other similar question: CSS "inverse border-radius" outside element's bounding box to create a mobile phone notch design
Adding 2 pseudoelements with a border-radius, box-shadow and background: transparent.
Needs a bit more code, but it looks a bit smoother, at least on Chrome Version 78.0.3904.108, although the difference is minimal. In any case, the shapes you can do can't be as complex as with the previous alternatives, especially if you want to work with ellipses rather than circles, as it is your case.
Using an SVG.
I think the SVG solution is not worth it here, but it would be a good alternative for more complex shapes or animated/transitioning shapes. In any case, Temani Afif already added a solution using SVG.
Something to keep in mind is that, as that looks like a navigation bar, the hoverable/clickable area of each button should match as good as possible what users actually see, which is not the case for Temani Afif's solutions.
This is what it would look like using radial-gradient:
body {
margin: 0;
font-family: monospace;
background: #DDD;
}
.bar {
background: white;
position: fixed;
bottom: 0;
width: 100%;
height: 60px;
text-align: center;
}
.circle {
position: relative;
top: -10px;
border-radius: 100%;
background: white;
width: 60px;
height: 60px;
margin: 0 16px;
cursor: pointer;
display: inline-flex;
justify-content: center;
align-items: center;
font-size: 24px;
font-weight: bold;
color: black;
transition: box-shadow ease-in 150ms;
background: white;
border: 0;
outline: none;
}
.circle:hover {
box-shadow: 0 16px 16px 0 rgba(0, 0, 0, .125);
}
.circle:active {
box-shadow: 0 8px 8px 0 rgba(0, 0, 0, .125);
}
.circle::before,
.circle::after {
content: "";
position: absolute;
top: 4px;
width: 32px;
height: 6px;
background: white;
z-index: 1;
}
.circle::before {
left: -18px;
background: radial-gradient(ellipse at 0% -25%, transparent 0, transparent 70%, white 70%, white 100%);
}
.circle::after {
right: -18px;
background: radial-gradient(ellipse at 100% -25%, transparent 0, transparent 70%, white 70%, white 100%);
}
<nav class="bar">
<button class="circle">💖</button>
<button class="circle">🚀</button>
<button class="circle">🌍</button>
</nav>
If you want to see a similar question and all the alternatives in action, check this out: CSS "inverse border-radius" outside element's bounding box to create a mobile phone notch design

bottom 0 in IE for all screen size

I want my svg images to be on bottom of my block (position:absolute, bottom:0). But in Internet Explorer it doesn't work (displays in the center). I can set width and height to svg and it will work somehow, but it will broke on another device with smaller/bigger screen size. How can I resolve this problem? Thank you!
Here is the code codepen
.wrapper {
padding: 150px 20px 50px;
text-align: center;
color: #fff;
}
.main {
background-color: #000;
line-height: 48px;
position: relative;
}
svg {
position: absolute;
bottom: 0;
}
.left {
left: 0;
}
.right {
right: 0;
}
<div class="main">
<div class="wrapper">
<div class="text">Some text here</div>
<button>click</button>
</div>
<svg class="left" fill="#fff" viewBox="0 0 1300 150" width="50%">
<polygon points="0,0 0,150 1300,150"></polygon>
</svg>
<svg class="right" fill="#fff" viewBox="0 0 1300 150" width="50%">
<polygon points="1300,0 0,150 1300,150"></polygon>
</svg>
</div>
You can achieve the same with using either simple divs or with pseudo elements. The following is an example I created to demonstrate both approaches.
https://codepen.io/Nasir_T/pen/oEYYob
The example uses position along with border to set the bottom design the way your want. You can use the div solution if you want to place images in it or use the pseudo solution if only want to show arrow cut in the design at the bottom.
If you want a background image, why not use a background-image??
.wrapper {
padding: 150px 20px 50px;
text-align: center;
color: #fff;
}
.main {
background-color: #000;
line-height: 48px;
position: relative;
background-image: url('data:image/svg+xml,<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg viewBox="0 0 52 3" xmlns="http://www.w3.org/2000/svg"><polygon points="0,0 26,3 52,0 52,3 0,3" fill="#fff" /></svg>');
background-repeat: no-repeat;
background-position: center bottom;
}
<div class="main">
<div class="wrapper">
<div class="text">Some text here</div>
<button>click</button>
</div>
</div>
This can be accomplished using CSS alone.
We can make triangle shape in CSS. Stick a triangle at the bottom of your main container. Will give the same effect.
.wrapper {
padding: 110px 20px 50px;
text-align: center;
color: #fff;
}
.main {
background-color: #000;
line-height: 48px;
position: relative;
width: 1000px;
}
.arrow-down {
width: 0;
height: 0;
border-left: 500px solid transparent;
border-right: 500px solid transparent;
border-top: 50px solid #000;
position:absolute;
bottom:-50px;
}
svg {
position: absolute;
bottom: 0;
}
.left {
left:0;
}
.right {
right:0;
}
<div class="main">
<div class="wrapper">
<div class="text">Some text here</div>
<button>click</button>
</div>
<div class="arrow-down">
</div>
</div>

How to design a image through css [duplicate]

This question already has answers here:
Wave (or shape?) with border on CSS3
(5 answers)
Closed 6 years ago.
How to design This Image
I want to design this type image.
.container {
background: #fff;
padding: 20px;
}
.round {
width: 100px;
height: 100px;
border: solid 2px #000;
position: relative;
}
.round:before {
content: '';
width: 20px;
height: 20px;
background: #fff;
border-bottom: solid 2px #000;
position: absolute;
top: -12px;
left: -11px;
transform: rotate(315deg);
}
.round:after {
content: '';
width: 20px;
height: 20px;
background: #fff;
border-top: solid 2px #000;
position: absolute;
bottom: -12px;
right: -11px;
transform: rotate(315deg);
}
<div class="container">
<div class="round"></div>
</div>
hat do you think?
Perhaps look at using an inline svg image, this would give you control over background image, and would allow for the shape to "scale", and if you like, change the background color (fill) when you like.
HTML
<div class="cornered-box">
<div class="svg-cont">
<svg width="200px" height="200px" viewBox="635 375 202 202" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<polygon id="path-1" points="675.163277 376 836 376 836 535.221624 796.221624 575 636 575 636 414.163277"></polygon>
</defs>
<use stroke="#000000" stroke-width="2" fill="transparent" xlink:href="#path-1"></use>
</svg>
</div>
<div class="cornered-box-content">
<p>
Some content for the box
</p>
</div>
</div>
CSS
.cornered-box{
height:200px;
width:200px;
position: relative;
padding:20px 5px;
box-sizing:border-box;
}
.cornered-box .svg-cont{
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
z-index:-1;
}
.cornered-box .svg-cont svg{
height:100%;
width:100%;
}
.cornered-box .svg-cont svg use{
fill:transparent;
transition: fill 0.2s ease-in-out;
}
.cornered-box:hover .svg-cont svg use{
fill:#F00;
}
JSFIDDLE
Link to SVG