How to create curve and circle in css and html5? - html

I'm new to the css world and I'm trying to make a responsive design like this using bootstrap, css and html5
for more information here is an illustration:
curve
how to create the same curve and a circle above? i really need help i try everything but it doesn't work
a little help will be really good

You have two options, the better is to use SVG (I would go for this one if its me), also you can implement something like you provided in HTML but not every shape is possible to have using HTML, if curve and circles all you need then, something like can be implemented:
.main {
border-radius: 50%;
width: 300px;
height: 300px;
background: red;
padding: 50px;
position:absolute;
top:-240px;
}
.inner {
border-radius: 50%;
width: 300px;
height: 300px;
background: white;
}
.innerWhite {
border: 1px solid 50px;
border-radius: 50%;
width: 50px;
height: 50px;
background: white;
position: absolute;
bottom: 45px;
}
<div class="main">
<div class="inner">
<div class="innerWhite"></div>
</div>
</div>

You can use radial-gradient combined with mask:
.box {
height:300px;
max-width:1024px;
margin:auto;
border:1px solid red;
position:relative;
}
.box::before {
content:"";
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
background:radial-gradient(circle 1800px at 50% -840px,transparent 53.8%,red 54% 60.8%,transparent 61%);
-webkit-mask:radial-gradient(circle at 20% 70%, transparent 80px,#fff 81px);
mask:radial-gradient(circle at 20% 70%, transparent 80px,#fff 81px);
}
body {
background:url(https://i.picsum.photos/id/1000/800/800.jpg) center/cover;
}
<div class="box"><div>

Related

Position an element on top-border, but behind bottom-border

I have a div-container, a bootstrap collapse element. In it there is another round element, which changes position, when using the collapse function. Means: It should be positioned on the top-border, but behind the bottom-border.
How would you solve this task?
My first idea was to use object-fit to cut off the bottom part of the round element, but that did not look well with transition and collapse. Second idea was to use a thick border-bottom as an after-pseudo-element to cover the bottom part, which did not work so far.
Do you have any ideas or have you done something like that?
Thank you!
Use clip-path:
.box {
border: 3px solid;
height: 200px;
margin: 50px;
position: relative;
clip-path: inset(-200% 0 0); /* a big negative value on the top to clip only left/right/bottom */
transition: 1s;
}
.box:hover {
height: 50px;
}
.box:before {
content: "";
position: absolute;
right: 10px;
top: 50%;
transform: translateY(-50%);
width: 100px;
height: 100px;
border: 3px solid;
border-radius: 50%;
background: red;
}
<div class="box">
</div>
You may also use transform3D + background to hide portions of it:
div {
margin:0 1em;
padding:1px;
display:flex;
padding-bottom:2em;
background:white;
transform-style: preserve-3d;
}
div[class] {
border:solid;
border-bottom:none;
height:150px;
transition:0.25s;
}
div[class] + div {
border-top:solid;
}
div[class]:hover {
height:60px;
}
div span {
height:150px;
width:150px;
align-self:center;
background:red;
border-radius:50%;
margin-right:1em;
border:solid;
margin-left:auto;
margin-bottom:-2.2em;
transform:rotatex(-0.15deg) translatez(1px);;
}
<div>Whatever stands here</div>
<div class>
<p>hover to collapse</p>
<span></span>
</div>
<div>Whatever stands next</div>

how to make double angled edge that comes to a point in css

I've seen a million tutorials on how to make a slanted edge like in this article for example.
but I cannot seem to find any information on how I would be able to create a div that looks like this...
a double slanted edge that comes to a point.. now I experimented a bit with using an svg image at the bottom of the div but it just wouldnt work properly.. any idea how I can recreate this??
I've seen something similar which required the user of a clip-path, but I need to support IE etc..
any help would be appreciated!
Thanks
I did a feeble attempt to recreate the same div with a double-slanted edge using before and after pseudo elements. You just have to tweak the rotation, top and left values to match your design.
div {
width: 400px;
height: 400px;
border: 1px solid black;
position: relative;
overflow: hidden;
}
div:after{
content: '';
position: absolute;
width: 100%;
background: green;
height:100%;
left: 50%;
top: 50%;
transform: rotate(75deg);
}
div:before{
content: '';
position: absolute;
width: 100%;
background: green;
height:100%;
right: 50%;
top: 50%;
transform: rotate(-75deg);
}
<div></div>
I'm not sure if this is the design that you are wanting.
This is accomplishable with just the border property of a second div, which would help with compatibility of older browsers (if you need to support older versions of IE which don't support pseudo-elements, or even current versions, which don't support use of em units on pseudo-elements)
The CSS
div {
width: 100%;
min-height: 100px;
}
#chevron {
padding-bottom: 100px;
}
#second {
width: 0px;
margin-top: -100px;
border-top: 50px solid transparent;
border-right: 50vw solid blue;
border-left: 50vw solid blue;
border-bottom: 50px solid blue;
}
The HTML
<div id='chevron'></div>
<div id='second'></div>
See this CodePen for a result.
You might use linear-gradients:
body {
background:
linear-gradient(10deg, transparent 45%, #fff 45%) 0 0 / 50vw 50vh,
linear-gradient(-10deg, transparent 45%, #fff 45%) 100% 0 / 50vw 50vh,
linear-gradient(180deg, #cde, #eee 70%) 0 0 / 100vw 100vh;
background-repeat:no-repeat;
}

Diamond in rectangle HTML & CSS3

I would like to make a diamond in a rectangle. I've already did it with a square :
.box {
width:100px;
height:100px;
background:orange;
z-index:1;
position:relative;
}
.box:before {
position:absolute;
content:'';
width:70.71%;
height:70.71%;
transform: rotate(45deg);
background: red;
top: 15%;
left: 15%;
}
<div class="box"></div>
But I want to make it like this :
The rectangle is responsive so it's never the same size. Any idea ?
Thanks a lot
This approach uses two triangles generated using CSS border.
I don't think you can use % for borderwidth, so I have used viewport units instead.
.box {
width: 50vw;
height: 25vw;
background: orange;
z-index: 1;
position: relative;
}
.box:before,
.box:after {
content: '';
position: absolute;
width: 0;
height: 0;
}
.box:before {
border-right: solid 25vw red;
border-top: solid 12.5vw transparent;
border-bottom: solid 12.5vw transparent;
}
.box:after {
right: 0;
border-left: solid 25vw red;
border-top: solid 12.5vw transparent;
border-bottom: solid 12.5vw transparent;
}
<div class="box"></div>
You're attempting to create a diamond by modifying a rectangle. If you tried that with a paper rectangle, you'd understand it's not the simplest way to go about it.
You could use clip-path:
.diamond {
background-color: #eee;
-webkit-clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
margin: 0 auto;
text-align: center;
padding: 2rem;
}
<div class="diamond">I'm a diamond</div>
... and all that's left for you to do is to set it's width, height (or min-* / max-* for any of them) in order to control its proportion responsively.
Do note CSS clip-path is currently supported by only ~88% of actively used browsers most notably lacking support by IE and Edge.
If you need support for those, the only way to do it is by using two levels of wrappers and construct the outline from ::before and ::after pseudos of those wrappers.

How do you create a div with a triangle shape using css only?

I want a div that has an "angle like shape on the left". How can I create this with CSS3 only? I am assuming this requires 2 divs? I know I can make a rectangle div and fill it back, and have yellow text. Though I don't know what I can do to make the triange shape on the left. Can it be done with done div only? Or does it need 2? Looking for the best way to do this.
You can achieve this using linear-gradient. Demo:
.text {
width: 400px;
background-image: linear-gradient(45deg, transparent 50px, black 50px);
padding-left: 100px;
color: yellow;
}
<div class="text">
<h1>Some Name Here</h1>
</div>
Why not try something like this:
.triangle {
width: 0;
height: 0;
border: 50px solid black;
border-bottom-color: transparent;
border-left-color: transparent;
float: left;
}
.text {
width: 400px;
height: 100px;
background-color: black;
float: left;
color: yellow;
}
<div class="triangle"></div>
<div class="text"><h1>Some Name Here</h1></div>
See How do CSS triangles work? for more info on this.
You can use of Pseudo Elements ::before or ::after
.triangle {
padding: 10px;
position: relative;
background-color: #000;
color: yellow;
display: inline-block;
margin-left: 40px;
}
.triangle::after {
content: "";
position: absolute;
border: 19px solid #000;
height: 0;
width: 0;
left: -38px;
top: 0;
bottom: 0;
margin: auto;
border-left-color: transparent;
border-bottom-color: transparent;
}
<div class="triangle">
text-here
</div>
Link for reference
Style Accordingly.
You can use clip-path but it has not so good browser support. I'm using 100vmax 100vmax here to achieve 45 degrees clipping. Demo:
.text {
width: 400px;
background-color: black;
-webkit-clip-path: polygon(100vmax 100vmax, 0% 0%, 100% 0%, 100% 100%);
clip-path: polygon(100vmax 100vmax, 0% 0%, 100% 0%, 100% 100%);
padding-left: 100px;
color: yellow;
}
<div class="text">
<h1>Some Name Here</h1>
</div>

How to create a gullwing shape with CSS

I am trying to create a div with a background image (background-size:cover) with this shape cut out in the center top of the div.
The div above the div I want to cut this shape out of has background-image:cover on it as well. I'm trying to do this with a CSS shape, moving the lower div up using a negative margin top, so the background image on the div above shows through the cut out shape.
Note: The shape has to look identical or almost identical to the image, as it is part of a site designed by someone else, and they are very specific with their designs.
Anyone out there know how to create this shape?
EDIT: #SZenC offered a really cool solution that I implemented, except it leaves me with colored shapes overlayed on top of background images. See image:
I need the light blue pattern to show through where the gray is, and the purple texture to show through where the white is. I'm not sure at this point if this is possible, at least with CSS.
The best solution using CSS would be to use some nested elements.
You could create a div (.pointy) with two other divs inside it (.curve-left & .curve-right).
The inner divs should be sided so that they each have half of the curve. So if your curve drops 10px and goes 20px horizontal, it's height should be 10px and the width 20px. Then give it a border radius in the top-left or top-right corner of 100%. Now the curve will go trough the entire div. You could then give it a gray background-color and the parent div white in the background. Then some simple CSS-tricks to center the .pointy-div and do the backgrounds, and voila, there is your curvy triangle-y thingy.
So example below.
#c1 {
position: relative;
width: 200px;
height: 190px;
overflow: hidden;
}
#c2 {
position: relative;
top: 0px;
width: 200px;
height: 200px;
background-color: gray;
}
.pointy {
position: absolute;
top: 0px;
left: 50%;
margin-left: -20px;
width: 40px;
height: 10px;
background-image: url("http://lorempixel.com/output/technics-q-c-200-200-4.jpg");
background-position:center bottom;
}
.pointy>.curve-left,
.pointy>.curve-right{
position:absolute;
background-color:red;
width:20px;
height:10px;
background-image:url("http://lorempixel.com/output/technics-q-c-200-200-1.jpg");
}
.pointy>.curve-left{
border-top-right-radius:100%;
background-position:120px 0;
left:0;
}
.pointy>.curve-right{
border-top-left-radius:100%;
background-position:80px 0;
right:0;
}
<div id="c1">
<img src="http://lorempixel.com/output/technics-q-c-200-200-4.jpg" />
</div>
<div id="c2">
<div class="pointy">
<div class="curve-left"></div>
<div class="curve-right"></div>
</div>
<img src="http://lorempixel.com/output/technics-q-c-200-200-1.jpg" />
</div>
Here you could use a couple of pseudo elements with border radius to create that curved shape.
note there are multiple elements in this demo to show how this could be used in practice
.image {
height: 300px;
width: 80%;
background: url(http://lorempixel.com/900/500);
position: relative;
display: inline-block;
}
.shape {
position: absolute;
bottom: 0;
width: 100%;
height: 30px;
background: url(http://lorempixel.com/900/400);
background-position: 0 60px;
}
.shape:before,
.shape:after {
content: "";
position: absolute;
background: inherit;
height: 100%;
top: 0;
width: 50%;
transform: translateY(-100%);
}
.shape:before {
left: 0;
border-radius: 0 50% 0 0;
background-position: 0 90px;
}
.shape:after {
left: 50%;
border-radius: 50% 0 0 0;
background-position: -100% 90px;
}
<div class="image">
<div class="shape"></div>
</div>
Another, more in practical approach (with responsiveness), would be something like:
.wrap{
width:100%;display:inline-block;
position:relative;
height:600px;
}
.wrap img:first-child{
top:0;z-index:5;
}
.wrap img:last-child{
top:40%;
}
.wrap img{
position:absolute;
height:50%;width:100%;
}
.wrap .splitter{
z-index:10;
position:absolute;
top:40%; width:100%;
height:10%;
}
.wrap .splitter:before, .wrap .splitter:after{
content:"";
position:absolute;
width:50%;
height:100%;
background-size:200% 500%;
border-radius: 0 100% 0 0;
}
.wrap .splitter:after{
left:50%;
background-position:-100% 0;
border-radius: 100% 0 0 0;
}
.wrap .partA:before, .wrap .partA:after{ background-image:url("http://lorempixel.com/450/250");}
<div class="wrap">
<img src="http://lorempixel.com/900/500"/>
<span class="splitter partA"></span>
<img src="http://lorempixel.com/450/250"/>
</div>