Incomplete circle with line in the middle - css

How can I achieve this shape with CSS:
Ideally, I'd like a background shadow effect too.

You can do this with CSS but it realy isn't the best way to make it. It will need to add unsemantic markup, and probably a lot of CSS.
If you don't want to use an image, I would suggest to use an inline SVG it is much better to control shapes like the one you are trying to achieve.
With SVG:
I made this quick example using a path element with arc commands :
svg{
display:block;
width:30%; height:auto;
}
body{background:url('http://i.imgur.com/qi5FGET.jpg');background-size:cover;}
<svg viewbox="0 0 10 10">
<path d="M4.5 1 A4.05 4.05 0 0 0 4.5 9z M8.4 3 A4.05 4.05 0 0 0 5.5 1 V9 A4.05 4.05 0 0 0 8.4 7"
stroke-width="0.8" fill="transparent" stroke="#000"/>
</svg>
With CSS :
I also made this CSS example with a possible approach if you really want to go with CSS. It uses only one div and two pseudo elements. The lines are made with borders and border-radius :
div {
position: relative;
width: 100px;
padding-bottom: 100px;
border-radius: 50%;
}
div:before,div:after {
box-sizing: border-box;
content: '';
width: 48%;
height: 100%;
position: absolute;
border: 10px solid #000;
}
div:before {
border-radius: 900px 0 0 900px;
}
div:after {
right: 0;
border-radius: 0 35px 35px 0;
border-right-color:transparent;
}
body{background:url('http://i.imgur.com/qi5FGET.jpg');background-size:cover;}
<div></div>

One CSs posibility
.test {
width: 200px;
height: 200px;
border: solid 10px black;
border-radius: 50%;
border-right-color: transparent;
background-image: linear-gradient(90deg, transparent 85px, black 85px, black 115px, transparent 115px);
position: relative;
}
.test:after {
content: "";
position: absolute;
left: 0;
right: 0;
width: 10px;
margin: auto;
background-color: white;
top: -10px;
bottom: -10px;
}
<div class="test"></div>

Here is another CSS alternative which just uses a single pseudo element to create the extra side of the shape.
The after creates the extra curve with a partially transparent border (the right side).
body {
background: skyblue;
}
div {
width: 50px;
height: 100px;
border: 10px solid black;
border-radius: 75px 0px 0px 75px;
position: relative;
box-sizing: border-box;
}
div:after {
content: '';
top: -10px;
width: 50px;
height: 100px;
border-width: 10px;
border-style: solid;
border-right-color: transparent;
border-radius: 0px 39px 39px 0px;
position: absolute;
left: 45px;
box-sizing: border-box;
}
<div></div>

Related

Complex CSS Shape

I need some CSS help. It’s hard to explain, but looking at the snippet I need the black part without the red.
I used two elements, but it should be possible with one...
.q-rounder {
background: #222;
width: 15px;
height: 15px;
}
.quarter-circle {
width: 15px;
height: 15px;
background: red;
border-radius: 100px 0 0 0;
-moz-border-radius: 100px 0 0 0;
-webkit-border-radius: 100px 0 0 0;
}
<div class="q-rounder">
<div class="quarter-circle"></div>
</div>
(fiddle)
Use a radial gradient as background
.q-rounder {
background:
radial-gradient(farthest-side at bottom right,transparent 94%, #222);
width: 15px;
height: 15px;
}
<div class="q-rounder">
</div>
Another syntax with the at to have better support (safari doesn't support the at)
.q-rounder {
background:
radial-gradient(farthest-side,transparent 94%, #222) top left/200% 200%;
width: 15px;
height: 15px;
}
<div class="q-rounder">
</div>
If you can use a solid background color, maybe this fits for you?
basicaly the before elements lays behind an rectangle which has border-radius an a solid background-color.
Supported in every browser and version.
.q-rounder {
position: relative;
background: white;
width: 15px;
height: 15px;
border-radius: 100px 0 0 0;
}
.q-rounder:before {
position: absolute;
left: 0;
top: 0;
width: 15px;
height: 15px;
background: black;
content: "";
z-index: -1;
}
<div class="q-rounder">
</div>

Create this shape in CSS (half pipe shape)

I've been trying to make this shape in CSS, but unfortunately could not find a way how to. It's half pipe like shaped:
The pixelated corner should be smooth (it's a zoomed in image).
Anyone knows how to create this? Or can get me on the right tracks?
You will need to use pseudo element :after for the inner block and then apply border-radius for curved corner.
div {
height: 60px;
width: 60px;
border: solid red;
position: relative;
background: red;
border-width: 0 10px 10px 0;
box-sizing: border-box;
}
div:after {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
border-bottom-right-radius: 10px;
background: #fff;
}
<div></div>
simple
.shape {
width: 140px;
height: 200px;
background-color: gray;
}
.shape:after {
content: '';
position: absolute;
width: 100px;
height: 160px;
background-color: #fff;
border-bottom-right-radius: 50px;
}
<div class="shape"></div>
I assume that the problem here is to create the "outer" curve, on the arbitrary background. It's achievable by the trick with clipping the needed part from the thick rounded border of the pseudo-element:
div {
width: 50%;
min-height: 4em;
margin: auto;
border: #888 solid;
border-width: 0 1em 1em 0;
position: relative;
}
div::after {
content: '';
border: #888 solid;
border-width: 0 1em 1em 0;
border-radius: 0 0 100% 0;
position: absolute;
right: -1em;
bottom: -1em;
width: 1em;
height: 1em;
clip: rect(0 1em 1em 0);
}
div:hover::after {
border-color: red; /* highlight the curved part */
}
body {
/* just as a background example */
background: repeating-linear-gradient(-45deg, #ddd, #ddd 1px, transparent 1px, transparent 10px);
min-height: 90vh;
}
<div></div>
You can do this with one element and with transparency like this:
.box {
width:80px;
height:100px;
border-right:20px solid grey;
border-bottom:20px solid grey;
box-sizing:border-box;
background:
radial-gradient(farthest-side at top left,transparent 98%,grey ) bottom right/20px 20px no-repeat;
}
body {
background:pink;
}
<div class="box">
</div>

Styling a CSS Button with Pointed Left Edge and Rounded Right Edge

Updated again with Safari screenshot after #LGSon's answer:
Update:
Thanks for your answers, but the following code does not produce the correct effet, one can clearly see the separation between the SVG and the a tag because of the difference in height:
.divsclass {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 146 206'%3E%3Cdefs%3E%3Cstyle%3E.c1%7Bfill:%23fff;%7D.c2%7Bfill:none;stroke:%23a0310f;stroke-linecap:round;stroke-miterlimit:10;stroke-width:10px;%7D%3C/style%3E%3C/defs%3E%3Cpath d='M146 0H98.53l-1 .47-94 94a12 12 0 0 0 0 17l94 94L99 206h47z' class='c1'/%3E%3Cpath d='M113.18 28.2l-73 74.8 73 74.81' class='c2'/%3E%3C/svg%3E");
background-repeat: no-repeat;
}
.divsclass a {
color: red;
text-transform: uppercase;
background-color: white;
margin-left: .75em;
border-bottom-right-radius: 10px;
border-top-right-radius: 10px;
font-size: 75%;
}
<div style="padding: 1em; background: black">
<div class="divsclass"><a role="button">BACK</a></div>
</div>
I'm trying to create the following button where the text inside it (BACK in the example below) can be of variable length. I'm trying with a background image on the left and a border radius on the right but it's not working (using :before). Any ideas?
P.S. I do have an image of the left triangle as a separate SVG if that helps.
This can be done using CSS alone in combination with the pseudo elements
a {
position: relative;
display: inline-block;
padding: 2px 10px 2px 20px;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
overflow: hidden;
text-decoration: none;
}
a::before,
a::after {
position: absolute;
content: '';
left: 0;
top: 50%;
width: 100%;
padding-bottom: 100%;
background: lightgray;
transform: rotate(-45deg);
transform-origin: left top;
z-index: -1;
}
a::after {
left: 5px;
border: 1px solid black;
}
BACK
Updated
And here is a version using the existing SVG and a pseudo
span {
display: inline-block;
background-color: black;
padding: 2px 10px 2px 20px;
}
a {
position: relative;
display: block;
color: red;
padding: 2px 10px 2px 0;
text-transform: uppercase;
background-color: white;
border-bottom-right-radius: 10px;
border-top-right-radius: 10px;
font-size: 75%;
}
a::before {
content: '';
position: absolute;
top: 0;
left: -14px;
height: 100%;
width: 15px;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 146 206'%3E%3Cdefs%3E%3Cstyle%3E.c1%7Bfill:%23fff;%7D.c2%7Bfill:none;stroke:%23a0310f;stroke-linecap:round;stroke-miterlimit:10;stroke-width:10px;%7D%3C/style%3E%3C/defs%3E%3Cpath d='M146 0H98.53l-1 .47-94 94a12 12 0 0 0 0 17l94 94L99 206h47z' class='c1'/%3E%3Cpath d='M113.18 28.2l-73 74.8 73 74.81' class='c2'/%3E%3C/svg%3E");
background-repeat: no-repeat;
background-size: 100%;
background-position: center;
}
<span><a role="button">BACK</a></span>
If you use a div as a button and an image as a background you can make your CSS like this:
div.divsclass {
border-radius: 15px 50px 30px 5px:
}
So you can set the border-radius in all of the 4 corners, if you want to only with CSS. Or edit your SVG, as mentioned before.

Clipping a circle box-shadow where it overlaps square <div>

Consider the following -
#banner {
width: 100%;
height: 50px;
box-shadow: 0 0 10px #000000;
background: #63B0F2;
}
#circle {
position: relative;
top: 20px;
height: 80px;
width: 80px;
margin: 0 auto;
border-radius: 50%;
box-shadow: 0 0 10px #000000;
background-color: white;
}
<div id="banner">
<div id="circle">
</div>
</div>
Is it possible to remove/clip the drop-shadow cast by the top half of the white square onto the blue div?
To put it another way, so there is only shadow cast onto the background, but not each other?
Possible solution with pseudo-elements :before and :after. Just add to your CSS:
#circle:before{
position: absolute;
content: "";
width: 150%;
height: 50%;
left: -25%;
top: -10px;
background: #63B0F2;
}
#circle:after{
position: absolute;
content: "";
width: 100%;
height: 100%;
left: 0;
top: 0;
background: white;
border-radius: 50%;
}
DEMO
Add a second element for the shadow and position it behind the banner using z-index.
.shadow,
.circle {
display: block;
height: 120px;
width: 120px;
position: absolute;
bottom: -100%;
left: calc(50% - 62px);
border-radius: 50%;
}
.shadow {
box-shadow: 0 0 1em -.125em rgba(10,10,10,.1), 0 0 0 1px rgba(10, 10, 10, .2);
border: 2px solid transparent;
z-index: -1;
}
.circle {
background: #e0e0e0;
border: 2px solid white;
}
See this codepen, in which I have used ridiculous colors to illustrate my point: https://codepen.io/pen/?editors=0100

Circular segment using CSS/CSS3

Is there any variant to draw a circular segment using just CSS/CSS3?
I need that green part of circle.
I was trying this:
div {
width: 86px;
height: 22px;
background-color: green;
border-bottom-right-radius: 42px;
border-bottom-left-radius: 42px;
}
<div></div>
But it doesn't look like a circular segment.
The width and height of the div should be same to produce a circle.
eg: http://jsfiddle.net/wGzMd/
Here is the css:
div{
position: absolute;
top: 50px;
left: 50px;
width:100px;
height:100px;
border: 1px solid green;
background: green;
border-radius: 360px;
} ​
EDIT (for segment):
http://jsfiddle.net/wGzMd/3/
CSS:
div.outerClass{
position: absolute;
left: 50px;
top: 50px;
height: 25px;
overflow: hidden;
}
div.innerClass{
width:100px;
height:100px;
border: 1px solid green;
border-radius: 360px;
}
HTML:
<div class="outerClass"><div class="innerClass"></div></div>
Hey check to this site http://css-tricks.com/examples/ShapesOfCSS/
and this http://www.russellheimlich.com/blog/pure-css-shapes-triangles-delicious-logo-and-hearts/
and this
http://www.css3shapes.com/
Css
#oval {
width: 86px;
height: 22px;
background: green;
-moz-border-radius: 50px / 25px;
border-radius: 100px 100px 0 0 / 47px;
-webkit-border-radius: 100px 100px 0 0 / 47px;
}
HTML
<div id="oval"></div>
Live demo http://jsfiddle.net/carTT/
and create any shape in pure css as like you .................
Half circle:
http://www.paulund.co.uk/how-to-create-different-shapes-in-css
div {
height:45px;
width:90px;
border-radius: 0 0 90px 90px;
-moz-border-radius: 0 0 90px 90px;
-webkit-border-radius: 0 0 90px 90px;
background:green;}

Resources