I’ve been looking this CSS3 Pie.
https://codepen.io/anon/pen/gxQarR
HTML
<div class="pie big" data-start="270" data-value="360"></div>
<div class="pie" data-start="0" data-value="90"></div>
<div class="pie" data-start="90" data-value="180">2</div>
<div class="pie" data-start="180" data-value="90">3</div>
<div class="pie" data-start="180" data-value="270">4</div>
CSS
/*
make each pie piece a rectangle twice as high as it is wide.
move the transform origin to the middle of the left side.
Also ensure that overflow is set to hidden.
*/
.pie {
position:absolute;
width:400px;
height:800px;
overflow:hidden;
left:600px;
-moz-transform-origin:left center;
-ms-transform-origin:left center;
-o-transform-origin:left center;
-webkit-transform-origin:left center;
transform-origin:left center;
}
/*
unless the piece represents more than 50% of the whole chart.
then make it a square, and ensure the transform origin is
back in the center.
NOTE: since this is only ever a single piece, you could
move this to a piece specific rule and remove the extra class
*/
.pie.big {
width:800px;
height:800px;
left:50px;
-moz-transform-origin:center center;
-ms-transform-origin:center center;
-o-transform-origin:center center;
-webkit-transform-origin:center center;
transform-origin:center center;
}
/*
this is the actual visible part of the pie.
Give it the same dimensions as the regular piece.
Use border radius make it a half circle.
move transform origin to the middle of the right side.
Push it out to the left of the containing box.
*/
.pie:BEFORE {
content:"";
position:absolute;
width:400px;
height:800px;
left:-400px;
border-radius:400px 0 0 400px;
-moz-transform-origin:right center;
-ms-transform-origin:right center;
-o-transform-origin:right center;
-webkit-transform-origin:right center;
transform-origin:right center;
}
/* if it's part of a big piece, bring it back into the square */
.pie.big:BEFORE {
left:0px;
}
/*
big pieces will also need a second semicircle, pointed in the
opposite direction to hide the first part behind.
*/
.pie.big:AFTER {
content:"";
position:absolute;
width:200px;
height:400px;
left:200px;
border-radius:0 100px 100px 0;
}
/*
add colour to each piece.
*/
.pie:nth-of-type(1):BEFORE,
.pie:nth-of-type(1):AFTER {
background: url(http://takeawayshop.dk/image/frontpage/pizza-1471406_960_720.jpg) no-repeat;
-ms-transform: rotate(360deg); /* IE 9 */
-webkit-transform: rotate(360deg); /* Chrome, Safari, Opera */
transform: rotate(360deg);
}
.pie:nth-of-type(2):AFTER,
.pie:nth-of-type(2):BEFORE {
background-color:green;
}
.pie:nth-of-type(3):AFTER,
.pie:nth-of-type(3):BEFORE {
background-color:red;
}
.pie:nth-of-type(4):AFTER,
.pie:nth-of-type(4):BEFORE {
background-color:orange;
}
/*
now rotate each piece based on their cumulative starting
position
*/
.pie[data-start="0"] {
-moz-transform: rotate(0deg); /* Firefox */
-ms-transform: rotate(0deg); /* IE */
-webkit-transform: rotate(0deg); /* Safari and Chrome */
-o-transform: rotate(0deg); /* Opera */
transform:rotate(0deg);
}
.pie[data-start="90"] {
-moz-transform: rotate(90deg); /* Firefox */
-ms-transform: rotate(90deg); /* IE */
-webkit-transform: rotate(90deg); /* Safari and Chrome */
-o-transform: rotate(90deg); /* Opera */
transform:rotate(90deg);
}
.pie[data-start="180"] {
-moz-transform: rotate(180deg); /* Firefox */
-ms-transform: rotate(180deg); /* IE */
-webkit-transform: rotate(180deg); /* Safari and Chrome */
-o-transform: rotate(180deg); /* Opera */
transform:rotate(180deg);
}
.pie[data-start="270"] {
-moz-transform: rotate(270deg); /* Firefox */
-ms-transform: rotate(270deg); /* IE */
-webkit-transform: rotate(270deg); /* Safari and Chrome */
-o-transform: rotate(270deg); /* Opera */
transform:rotate(270deg);
}
.pie[data-start="360"] {
-moz-transform: rotate(360deg); /* Firefox */
-ms-transform: rotate(360deg); /* IE */
-webkit-transform: rotate(360deg); /* Safari and Chrome */
-o-transform: rotate(360deg); /* Opera */
transform:rotate(360deg);
}
/*
and rotate the amount of the pie that's showing.
NOTE: add an extra degree to all but the final piece,
to fill in unsightly gaps.
*/
.pie[data-value="90"]:BEFORE {
-moz-transform: rotate(90deg); /* Firefox */
-ms-transform: rotate(90deg); /* IE */
-webkit-transform: rotate(90deg); /* Safari and Chrome */
-o-transform: rotate(90deg); /* Opera */
transform:rotate(90deg);
}
.pie[data-value="180"]:BEFORE {
-moz-transform: rotate(180deg); /* Firefox */
-ms-transform: rotate(180deg); /* IE */
-webkit-transform: rotate(180deg); /* Safari and Chrome */
-o-transform: rotate(180deg); /* Opera */
transform:rotate(180deg);
}
.pie[data-value="270"]:BEFORE {
-moz-transform: rotate(270deg); /* Firefox */
-ms-transform: rotate(270deg); /* IE */
-webkit-transform: rotate(270deg); /* Safari and Chrome */
-o-transform: rotate(270deg); /* Opera */
transform:rotate(270deg);
}
.pie[data-value="360"]:BEFORE {
-moz-transform: rotate(360deg); /* Firefox */
-ms-transform: rotate(360deg); /* IE */
-webkit-transform: rotate(360deg); /* Safari and Chrome */
-o-transform: rotate(360deg); /* Opera */
transform:rotate(360deg);
}
/*
NOTE: you could also apply custom classes (i.e. .s0 .v30)
but if the CSS3 attr() function proposal ever gets implemented,
then all the above custom piece rules could be replaced with
the following:
.pie[data-start] {
transform:rotate(attr(data-start,deg,0);
}
.pie[data-value]:BEFORE {
transform:rotate(attr(data-value,deg,0);
}
*/
I am attepmting to create this pie, with pictures in each 90* peice.
Yet I have had no luck rotating the picture, so it looks proper.
I’ve attepmted to take usage of the transform rotate, yet with no luck.
I thought of rotating the picture in Photoshop, so it’d fit. Are there any other ways to do it?
3
Answers
why don’t you try something like this codepen.io
One option would be that you add a new element inside the pie piece that you can control independently of the overall piece, and put the background image on that inner element.
(Note how I also removed the extra pie piece you had. It was unnecessary for this example.)
Then in your CSS, this:
Becomes:
And you can add:
hope this helps