I'm trying to create a ring shape in css, divided into 4 quarters.
Each quarter will represent a button.
I've been playing around with the following code:
#quarterCircleTopLeft{
width:100px;
height:100px;
border:1px solid #000;
background: orange;
border-radius: 90px 0 70px 0;
-moz-border-radius: 90px 0 70px 0;
-webkit-border-radius: 90px 0 70px 0;
}
Which produces this (disregard the grey lines):
Obviously, I want the border at the right bottom to be inverted. However, since this is a button I cannot use another shape to produce a cutout (as this would overlap with other buttons of the menu). I've added a red line to show approx how I would want the border to go. Sorry, my paint skills are bad :-P
How can I invert the border or in another way produce the shape I want?
I'd do something like:
http://dabblet.com/gist/5476973
In short, lots of border radius + a white circle on top of everything.
On my example, I'd then bind click events onto the divs using javascript, or just make them all <a> elements instead and add a display:block;.
/**
* Quarter Circles
*/
.main {
position: relative;
width: 200px;
height: 200px;
margin: 0 auto;
}
.quarter {
position: absolute;
width: 50%;
height: 50%;
transition: background-color 0.2s ease-in-out;
}
.quarter:hover {
background-color: pink;
}
.quarter1 {
top: 0;
left: 0;
background-color: red;
border-radius: 100% 0 0 0;
}
.quarter2 {
top: 0;
right: 0;
background-color: blue;
border-radius: 0 100% 0 0;
}
.quarter3 {
bottom: 0;
left: 0;
background-color: orange;
border-radius: 0 0 0 100%;
}
.quarter4 {
bottom: 0;
right: 0;
background-color: green;
border-radius: 0 0 100% 0;
}
.cutout {
width: 50%;
height: 50%;
background-color: white;
position: absolute;
top: 25%;
left: 25%;
border-radius: 50%;
pointer-events: none;
}
<div class="main">
<div class="quarter quarter1"></div>
<div class="quarter quarter2"></div>
<div class="quarter quarter3"></div>
<div class="quarter quarter4"></div>
<div class="cutout"></div>
</div>
Here is an <svg> solution.
Svg has its own <a> element svg.
Just press the corners and you will find some amazing documentation ;)
Jokes aside The a link works on the shape so the shape gets the link.
This leaves the space empty space inside the shape that will show any thing behind it.
<svg width="150px" height="150px" viewbox="-1 -1 102 102">
<a xlink:href="https://developer.mozilla.org/en-US/docs/SVG">
<path stroke="tomato" fill="orange" d="M10 50 0 50 C 0 16 16 0 50 0 V0 20
C 31 20 20 31 20 50Z" />
</a>
<a xlink:href="https://developer.mozilla.org/en-US/docs/SVG">
<path stroke="darkRed" fill="red" transform="translate(100, 0) rotate(90)" d="M10 50 0 50 C 0 16 16 0 50 0 V0 20
C 31 20 20 31 20 50Z" />
</a>
<a xlink:href="https://developer.mozilla.org/en-US/docs/SVG">
<path stroke="DarkBlue" fill="blue" transform="translate(100, 100) rotate(180)" d="M10 50 0 50 C 0 16 16 0 50 0 V0 20
C 31 20 20 31 20 50Z" />
</a>
<a xlink:href="https://developer.mozilla.org/en-US/docs/SVG">
<path stroke="darkGreen" href="#" fill="green" transform="translate(0, 100) rotate(-90)" d="M10 50 0 50 C 0 16 16 0 50 0 V0 20
C 31 20 20 31 20 50Z" />
</a>
</svg>
i have been able to enhance the 1st answer and avoid getting the ring respond when mouse is on cutoff area.
http://codepen.io/a-zaki/pen/rLRyAm
/**
* Quarter Circles
*/
.main {
position: relative;
width: 300px;
height: 300px;
margin: 0 auto;
}
.quarter {
position: absolute;
width: 50%;
height: 50%;
transition: background-color 0.2s ease-in-out;
z-index: 1;
}
.quarter:hover {
background-color: pink;
}
.quarter1 {
top: 0;
left: 0;
background-color: red;
border-radius: 100% 0 0 0;
}
.quarter2 {
top: 0;
right: 0;
background-color: blue;
border-radius: 0 100% 0 0;
}
.quarter3 {
bottom: 0;
left: 0;
background-color: orange;
border-radius: 0 0 0 100%;
}
.quarter4 {
bottom: 0;
right: 0;
background-color: green;
border-radius: 0 0 100% 0;
}
.cutout {
width: 50%;
height: 50%;
background-color: white;
position: absolute;
top: 25%;
left: 25%;
border-radius: 50%;
border: 3px solid #000;
z-index: 2;
}
<div class="main">
<div class="quarter quarter1"></div>
<div class="quarter quarter2"></div>
<div class="quarter quarter3"></div>
<div class="quarter quarter4"></div>
<div class="cutout"></div>
</div>
On Safari this should work:
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 40px;
height: 40px;
border: solid;
border-radius: 100px 0 0 0;
border-width: 30px 30px 0;
border-right: hidden;
}
</style>
<title>Quatre Circle Outline</title>
</head>
<body>
<div></div>
</body>
</html>
Related
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; }
I want to code the active state of the anchor tag to change the overlay class opacity to 1.
I am only able to do that using the :hover pseudo with the image to achieve this. Once try to use the link (anchor tag) in styling the image doesn't appears as a link anymore.
.card{
order: -1;
justify-content: center;
position: relative;
}
.card > a{
display: block;
position: relative;
}
.card a img{
display: block;
max-width: 100%;
width: 90%;
height: 50%;
border-radius: 20px;
/* align-self: center; */ /* centert the image cross-wise (horizontally) */
padding: 12px;
/* margin-top: 12px;*/
}
.overlay {
position: absolute;
top: 12px;
bottom: 12;
left: 12px;
right: 12;
height: 92%;
width: 90%;
opacity: 0;
transition: .5s ease;
background-color: #00FFF8;
border-radius: 13px;
}
.card > a:active .overlay{
opacity: 0.6;
}
<body>
<section id="card_details">
<h1>Equilibruim #3429</h1>
<p>Our Equilibruim collections promotes balance and calm.</p>
<div class="card">
<img src="images/nft.jpg" alt="" class="image">
<div class="overlay">
<div class="eye">
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48"><g fill="none" fill-rule="evenodd"><path d="M0 0h48v48H0z"/><path d="M24 9C14 9 5.46 15.22 2 24c3.46 8.78 12 15 22 15 10.01 0 18.54-6.22 22-15-3.46-8.78-11.99-15-22-15Zm0 25c-5.52 0-10-4.48-10-10s4.48-10 10-10 10 4.48 10 10-4.48 10-10 10Zm0-16c-3.31 0-6 2.69-6 6s2.69 6 6 6 6-2.69 6-6-2.69-6-6-6Z" fill="#FFF" fill-rule="nonzero"/></g></svg>
</div>
</div>
</div>
The only way I'm getting the overlay to work is with this css below;
.card:hover .overlay{
opacity: 0.6;
}
Below is the live link for the outcome
Your active state css doesn't work since .overlay is not a child of .cardlink.
.card{
order: -1;
justify-content: center;
position: relative;
max-width:25%;
}
.card > a{
display: block;
position: relative;
}
.card a img{
display: block;
max-width: 100%;
width: 90%;
height: 50%;
border-radius: 20px;
/* align-self: center; */ /* centert the image cross-wise (horizontally) */
padding: 12px;
/* margin-top: 12px;*/
}
.overlay {
position: absolute;
top: 12px;
bottom: 12;
left: 12px;
right: 12;
height: 92%;
width: 90%;
opacity: 0;
transition: .5s ease;
background-color: #00FFF8;
border-radius: 13px;
}
.card > a:active+.overlay{
opacity: 0.6;
}
.overlay{
user-select:none;
pointer-events: none;
}
<div class="card">
<div class="overlay">
<div class="eye">
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48">
<g fill="none" fill-rule="evenodd">
<path d="M0 0h48v48H0z" />
<path d="M24 9C14 9 5.46 15.22 2 24c3.46 8.78 12 15 22 15 10.01 0 18.54-6.22 22-15-3.46-8.78-11.99-15-22-15Zm0 25c-5.52 0-10-4.48-10-10s4.48-10 10-10 10 4.48 10 10-4.48 10-10 10Zm0-16c-3.31 0-6 2.69-6 6s2.69 6 6 6 6-2.69 6-6-2.69-6-6-6Z" fill="#FFF" fill-rule="nonzero" />
</g>
</svg>
</div>
</div>
</div>
You will also need to disable pointer events on the overlay element – otherwise you won't get any focus on your <a> element.
.card > a:active+.overlay{
opacity: 0.6;
}
.overlay{
user-select:none;
pointer-events: none;
}
One of my first css intensive projects, having trouble getting everything lined up how I'd want it to.
How it is and what I want to achieve
The second section is ignoring the overblown 600% image and going right after the previous container (obviously).
I tried setting the .container-stars height to 600%, but that does literally nothing.
Tried using px or vh units, but it messes with the SVG paths, where they ignore the absolute top: 0; and move to the middle (I imagine it's because of the height: 100% somehow, but I can't set it to specific units because then it wouldn't be responsive anymore)
When I set the .container-stars to height: 600vh
.container-stars {
position: relative;
width: 100vw;
height: 100%;
margin-top: 20%;
background: linear-gradient(to bottom, $background 5%, white 40%, transparent 100%, $background 90%);
.path_left {
top: 0;
left: 0;
width: 45%;
height: 100%;
fill: $background;
}
.path_right {
position: absolute;
width: 45%;
height: 100%;
top: 0;
right: 0;
transform: scaleX(-1);
fill: $background;
}
.img_stars {
position: absolute;
background-image: url('/img/stars-1654074_1920.jpg');
top: 0;
left: 0;
width: 100%;
height: 600%;
repeat: repeat-y;
z-index: -1;
}
}
#content {
position: relative;
width: 100vw;
margin-top: 0%;
h2 {
position: absolute;
font-family: $primary-font;
font-size: calc(2vw + 0.5rem);
top: 0;
background: green;
display: block;
transform: translate(0, 50%);
color: #fff;
}
}
<section class="container-stars">
<svg class="path_left" width="450" height="600" viewBox="0 0 450 600">
<path d="M 0 600 C 260 327 202 133 450 0 L 0 0"></path>
</svg>
<svg class="path_right" width="450" height="600" viewBox="0 0 450 600">
<path d="M 0 600 C 260 327 202 133 450 0 L 0 0"></path>
</svg>
<div class="img_stars"></div>
</section>
<section id="content">
<h2>...matter, energy, time and space came into being</h2>
</section>
Would also appreciate any tips if someone has a better way to achieve this.
Troubleshooting whilst trying to maintain responsiveness can really be a pain.
.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');
}
Hi i have a HTML polygon, this is my code :
<div class="full-background">
<div class="diag">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 10" preserveAspectRatio="none">
<polygon points="100 0 100 10 0 10" />
</svg>
<img src="assets/img/downarrow.png" alt="" />
</div>
</div>
This produces :
I actually want this the other way around, so that the black section is blue and the blue section is transparent. I cant find a way at all to edit the color of the black section i have even tried changing the bodys bg-color.
Here is my css:
.diag {
position: absolute;
bottom:0;
width:100%;
}
svg {
display: block;
width: 100%;
height: 20vh;
background: #38aae1;
}
img {
height: 50px;
position: absolute;
top: 0; bottom: 0;
left: 0; right: 0;
margin: auto;
background: #ef7d00;
border-radius: 50%;
padding: 10px;
}
Can anyone help? Thanks.
Add fill property to polygon and change the background of svg to transparent.
Have a look at the snippet below (use full screen for better view, ignore placeholder image of arrow):
.diag {
position: absolute;
bottom:0;
width:100%;
}
svg {
display: block;
width: 100%;
height: 20vh;
background: transparent;
}
svg polygon {
fill: #38aae1;
}
img {
height: 50px;
position: absolute;
top: 0; bottom: 0;
left: 0; right: 0;
margin: auto;
background: #ef7d00;
border-radius: 50%;
padding: 10px;
}
<div class="full-background">
<div class="diag">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 10" preserveAspectRatio="none">
<polygon points="100 0 100 10 0 10" />
</svg>
<img src="http://placehold.it/10x10" alt="" />
</div>
</div>
Hope this helps!
Set the polygon fill to the blue color and set the svg background to black in css:
svg{
background: black;
}
and your svg:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 10" preserveAspectRatio="none">
<polygon points="100 0 100 10 0 10" fill="#38aae1"/>
</svg>