This is the shape I want. Can it be done with CSS?
I have created a circle. Here :
(source: pngimg.com)
<div class="lemon"></div>
CSS :-
.lemon {
width: 200px;
height: 200px;
background-color: #FFFA40;
border: 4px solid #FFF150;
border-radius: 100px;
top:20px;
}
lemon and leaves
body {
background: rgb(48, 52, 52)
}
.container {
margin: 0 auto;
width: 200px;
position: relative;
}
.leaves {
width: 7px;
height: 70px;
background: #339B00;
border-radius: 0 0 10px 10px;
position: absolute;
left: 50%;
margin-left: -4px;
z-index: 1;
}
.leaves:after {
content: '';
width: 80px;
height: 80px;
background: #339B00;
position: absolute;
border-radius: 0% 50%;
transform: rotate(96deg) skew(21deg, 11deg);
transform-origin: left top;
top: 32px;
}
.leaves:before {
content: '';
width: 70px;
left: 8px;
height: 70px;
background: #339B00;
position: absolute;
border-radius: 0% 50%;
transform: rotate(-16deg) skew(21deg, 11deg);
transform-origin: left top;
top: 32px;
}
.lemon {
width: 160px;
height: 160px;
border-radius: 50%;
background: yellow;
position: absolute;
transform: rotate(48deg) skew(6deg, 6deg);
top: 69px;
left: 50%;
margin-left: -80px;
}
.lemon:after {
content: '';
width: 50px;
height: 50px;
background: yellow;
top: 64%;
left: 50%;
position: absolute;
margin-left: 24px;
border-radius: 19px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div class="container">
<div class="leaves"></div>
<div class="lemon"></div>
</div>
You should use different border radii for different corners. Also, add transform: rotate(45deg); to rotate it by 45deg.
.lemon {
width: 200px;
height: 200px;
background-color: #FFFA40;
border: 4px solid #FFF150;
border-radius: 20px 140px 40px 140px; /* top right bottom left */
transform:rotate(45deg);
-webkit-transform:rotate(45deg);
-moz-transform:rotate(45deg);
position:relative;
top:30px;
}
<div class="lemon"></div>
Bonus
A lemon with twig and leaf.
body {
background-color:#333;
}
.lemon {
width: 200px;
height: 200px;
background-color: #FFFA40;
border: 4px solid #FFF150;
border-radius: 20px 140px 40px 140px;
transform:rotate(45deg);
-webkit-transform:rotate(45deg);
-moz-transform:rotate(45deg);
position:relative;
top:145px;
z-index:1;
}
.leaf {
width: 100px;
height: 100px;
background: #11AA11;
border-radius: 5px 100px;
transform:rotate(105deg);
-webkit-transform:rotate(105deg);
-moz-transform:rotate(105deg);
position:relative;
top:-200px;
left:110px;
z-index:3;
}
.twig{
width: 7px;
height: 0px;
border-bottom: 90px solid #A0522D;
border-left: 2px solid transparent;
border-right: 2px solid transparent;
border-bottom-right-radius:4px;
border-bottom-left-radius:4px;
transform:rotate(-10deg);
position:relative;
top:-284px;
left:88px;
z-index:2;
}
<div class="lemon"></div>
<div class="leaf"></div>
<div class="twig"></div>
This is pretty trivial with a pseudo-element for the bottom edge:
.lemon {
background:yellow;
width:200px;
height:150px;
border-radius:50%;
position:relative;
}
.lemon:after {
content:'';
position:absolute;
left:85%;
top:40%;
background:yellow;
width:25%;
height:20%;
border-radius:50%;
}
Sample fiddle here. Obviously you can rotate it to any position you want, ie. transform:rotate(90deg).
Related
I want to create a shape using CSS. The only problem I am facing is the alignment of semicircle with the border of rectangle which is not working out properly.
I am attaching the image of what I have done till now. Can anybody help me out to fix these alignment problem. Thank you.
body {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: white;
}
#talkbubble {
width: 120px;
height: 80px;
border: 4px solid #4C4C4C;
position: relative;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
}
#talkbubble:before {
content: "";
position: absolute;
top: 42%;
left: -11.6px;
width: 30px;
height: 15px;
border: 4px solid #4C4C4C;
border-bottom: none;
border-top-left-radius: 30px;
border-top-right-radius: 30px;
background-color: white;
transform: rotate(90deg);
box-sizing: border-box;
}
#talkbubble:after {
content: "";
position: absolute;
top: 42%;
right: -12px;
width: 30px;
height: 15px;
border: 4px solid #4C4C4C;
border-bottom: none;
border-top-left-radius: 30px;
border-top-right-radius: 30px;
background-color: white;
transform: rotate(270deg);
box-sizing: border-box;
}
<div id="talkbubble"></div>
I would do it differently with one element:
.ticket {
width:300px;
height:200px;
border-radius:20px;
border:8px solid;
background:
radial-gradient(circle 38px at right,#000 95%,#0000),
radial-gradient(circle 38px at left ,#000 95%,#0000);
background-origin:border-box;
-webkit-mask:
radial-gradient(circle 30px at right,#0000 95%,#000) right,
radial-gradient(circle 30px at left ,#0000 95%,#000) left;
-webkit-mask-size:51% 100%;
-webkit-mask-repeat:no-repeat;
}
<div class="ticket"></div>
You could add overflow hidden in case, and a full circle?
.ticket-outer {
overflow: hidden;
height: 150px;
width: 300px;
margin: 50px auto;
}
.ticket {
border: 5px solid #000;
border-radius: 20px;
height: 150px;
width: 300px;
position: relative;
box-sizing: border-box;
}
.ticket::before,
.ticket::after {
content: '';
width: 50px;
height: 50px;
border: 5px solid #000;
background: #fff;
border-radius: 50%;
position: absolute;
top: 50%;
left: -30px;
transform: translateY(-50%);
z-index: 2;
}
.ticket::after {
left: auto;
right: -30px;
}
<div class="ticket-outer">
<div class="ticket"></div>
</div>
I want to do rounded circle like below image
But I am in trouble in making inner rounded one ! I tried with border-top-style & border-right-style but not getting the same yet .
.circle {
border-radius:50%;
width:100px;
height:100px;
background:#A2D36E;
text-align:center; }
.bar {
top:15px;
left:15px;
border-radius:50%;
border:1px solid white;
border-width:3px;
border-top-style:none;
border-right-style:none;
width:80px;
height:80px;
position:absolute;
}
span {
top:30%;
transform:translateY(-30%);
position:relative;
font-size:1.6rem;
color:#fff;
font-weight:bold;
}
<div class='circle'>
<div class='bar'> </div>
<span>8.8</span>
</div>
.circle {
border-radius:50%;
width:100px;
height:100px;
background:#A2D36E;
text-align:center; }
.bar {
top:15px;
left:15px;
border-radius:50%;
border:1px solid white;
border-width:3px;
border-top-style:inset;
border-right-style:inset;
border-top-color: transparent;
width:80px;
height:80px;
position:absolute;
transform: rotate(40deg);
}
span {
top:30%;
transform:translateY(-30%);
position:relative;
font-size:1.6rem;
color:#fff;
font-weight:bold;
}
<div class='circle'>
<div class='bar'> </div>
<span>8.8</span>
</div>
Try This:
.circle {
border-radius:50%;
width:100px;
height:100px;
background:#A2D36E;
text-align:center;
}
.bar {
top:15px;
left:15px;
border-radius:50%;
border:1px solid white;
border-width:3px;
width:80px;
height:80px;
position:absolute;
}
.bar:after {
width: 25px;
height: 10px;
content: '';
position: absolute;
top: -3px;
background: #A2D36E;
transform: rotate(20deg);
}
span {
top:30%;
transform:translateY(-30%);
position:relative;
font-size:1.6rem;
color:#fff;
font-weight:bold;
}
<div class='circle'>
<div class='bar'> </div>
<span>8.8</span>
</div>
The CodePen link demonstrates an SVG solution: https://codepen.io/UncaughtTypeError/pen/WXRObq
The Code Snippet below demonstrates x2 solutions you could explore:
Border Shape solution
Clip Path solution
.circle {
border-radius: 50%;
width: 100px;
height: 100px;
background: #A2D36E;
text-align: center;
position: relative;
}
.bar {
top: 0;
bottom: 0;
left: 0;
right: 0;
border-radius: 50%;
border: 1px solid white;
border-width: 3px;
margin: auto;
width: 80px;
height: 80px;
position: absolute;
}
span {
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
height: 35px;
position: absolute;
font-size: 1.6rem;
color: #fff;
font-weight: bold;
}
/* Additional */
.clip-path-solution .bar:after {
content: "";
width: 90px;
height: 90px;
position: absolute;
bottom: 0;
top: -3px;
left: -3px;
right: 0;
background: #a2d36e;
border-radius: 100%;
-webkit-clip-path: polygon(48% 48%, 100% 0%, 100% 0%, 50% 0%);
clip-path: polygon(48% 48%, 100% 0%, 100% 0%, 50% 0%);
transform: rotate(10deg);
}
.border-solution .shape {
transform: rotate(-30deg);
border-top: 10px solid transparent;
border-left: 10px solid transparent;
border-bottom: 10px solid transparent;
position: absolute;
box-sizing: border-box;
/* starting point */
/*border-right: 10px solid #d36e6e;
margin: auto;
left: 0;
right: 0;
top: 0;
bottom: 0;
width: 90px;
height: 90px;
border-radius: 100%;*/
/* adjusted accordingly for demonstration */
margin: 0;
width: 50px;
height: 50px;
top: 10px;
margin: 0;
right: 10px;
left: auto;
border-top-right-radius: 45px;
border-bottom-right-radius: 30px;
border-right: 10px solid #a2d36e;
}
<h3>Clip Path</h3>
<div class='clip-path-solution circle'>
<div class='bar'></div>
<span>8.8</span>
</div>
<h3>Border Shape</h3>
<div class='border-solution circle'>
<div class='bar'></div>
<div class='shape'></div>
<span>8.8</span>
</div>
I have the following CSS code:
#wrapper{
height:500px;
background: url('http://i.imgur.com/f1uCUEJ.jpg');
}
#menu:before{
width:500px;
height:60px;
background: rgba(255,255,255,0.6);
content: "";
position: fixed;
top:0;
left: 0;
border-radius: 0 0 10px 0;
}
#menu{
position: fixed;
top:60px;
left: 0;
background: rgba(255,255,255,0.6);
height: 300px;
width: 60px;
border-radius: 0 0 10px 0;
}
#circle{
position: fixed;
width:150px;
height:150px;
border-radius: 150px;
background: #000;
top: 10px;
left: 10px;
}
#circle2{
position: fixed;
width:120px;
height:120px;
border-radius: 120px;
background: #fff;
top: 25px;
left: 25px;
}
#circle3{
position: fixed;
width:90px;
height:90px;
border-radius: 90px;
background: #000;
top: 40px;
left: 40px;
}
#circle4{
position: fixed;
top: 54px;
left: 54px;
}
.btn{
border: none;
display: block;
margin: 1px;
background: #fff;
width:60px;
height: 30px;
font-weight: 700;
font-size: 17px;
}
#plus{
border-radius: 30px 30px 0 0;
}
#minus{
border-radius: 0 0 30px 30px;
}
And following HTML code:
<div id="wrapper">
<div id="menu"></div>
<div id="circle">
<div id="circle2">
<div id="circle3">
<div id="circle4">
<button id="plus" class="btn">+</button>
<button id="minus" class="btn">-</button>
</div>
</div>
</div>
</div>
</div>
Could you help me to understand how I can achieve solution, which will make "transparent" black circles and I could see only image? If I make now this black color as - background: rgba(0,0,0,0). I can see "menu" bars and I'd like to not see them.
There's following link with example: http://jsfiddle.net/88Uxw/122/
Is this what you are looking for? FIDDLE
Basically instead of using circles with background one inside the other, make the black color with border and set the "white" ones to not have any background:
#circle{
position: fixed;
width:150px;
height:150px;
border-radius: 150px;
border: 15px solid #000;
box-sizing: border-box;
top: 10px;
left: 10px;
}
#circle2{
position: fixed;
width:120px;
height:120px;
border-radius: 120px;
top: 25px;
left: 25px;
}
#circle3{
position: fixed;
width:90px;
height:90px;
border-radius: 90px;
border: 15px solid #000;
box-sizing: border-box;
top: 40px;
left: 40px;
}
#circle4{
position: fixed;
top: 54px;
left: 54px;
}
.btn{
border: none;
display: block;
margin: 1px;
background: transparent;
width:60px;
height: 30px;
font-weight: 700;
font-size: 17px;
border-bottom:1px solid #000;
}
Don't forget to add box-sizing: border-box; to keep the border inside you fixed size container.
Thanks to #Alvaro Menéndez I was able to do what I wanted to do. That's solution for my problem:
HTML:
<div id="wrapper">
<div id="wrap">
<div id="shape"></div>
</div>
<div id="wrap2">
<div id="shape2"></div>
</div>
<div id="shape3">
<button id="plus" class="btn">+</button>
<button id="minus" class="btn">-</button>
</div>
<div id="left-menu"></div>
<div id="top-menu"></div>
</div>
CSS:
#shape {
width:200px;
height:200px;
position:fixed;
overflow:hidden;
top: 0;
left: 0;
}
#shape:before {
content:" ";
position:absolute;
width:100%;
height:100%;
left:15%; top:15%;
border-radius:50%;
box-shadow:0 0px 0 250px rgba(255,255,255,0.6);
}
#left-menu{
background: rgba(255,255,255,0.6);
width: 59px;
height: 200px;
position: fixed;
top:200px;
left: 0;
}
#top-menu{
position: fixed;
top: 0;
left: 200px;
background: rgba(255,255,255,0.6);
width: 300px;
height: 59px;
}
#shape2 {
width: 140px;
height: 140px;
position: fixed;
top: 60px;
left: 60px;
}
#shape2:before {
content: " ";
position: absolute;
width: 100%;
height: 100%;
border-radius: 50%;
box-shadow: 0 0px 0 20px rgba(255,255,255,0.6);
}
#shape3{
position: fixed;
top: 69px;
left: 69px;
}
.btn{
border: none;
display: block;
margin: 1px;
background: rgba(255,255,255,0.6);
width:120px;
height: 60px;
font-weight: 700;
font-size: 17px;
}
.btn:hover{
background: #fff;
}
#plus{
border-radius: 100px 100px 0 0;
}
#minus{
border-radius: 0 0 100px 100px;
}
And working example: https://jsfiddle.net/L9aeu4o3/
I have a div with a simple border:
border: 10px solid #642850;
div {
border: 10px solid #642850;
height: 100px;
width: 100px;
}
<div></div>
I'm looking to create a shape like this:
What is the best way to achieve this?
try this one :
http://jsfiddle.net/sachinkk/L5zz1hak/2/
.sq {
border: 10px solid #642850;
height: 100px;
width: 100px;
position: relative;
margin-top: 100px;
}
.tl {
position: absolute;
top: -33px;
left: -36px;
border-left: 10px solid #642850;
border-top: 10px solid #642850;
height: 76px;
width: 76px;
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform-origin: 100% 100%;
}
<div class="sq">
<div class="tl"></div>
</div>
CSS
By using a pseudo-element and using css transforms, the desired shape can be accomplished.
div {
background: white;
border: 10px solid #642850;
width: 100px;
height: 100px;
margin-top: 75px;
positioN: relative;
}
div::before {
margin-top: -52px;
border: 10px solid #642850;
background: white;
content: '';
transform: rotate(45deg);
position: absolute;
top: 0;
left: 8px;
height: 64px;
width: 64px;
z-index: -2;
}
<div></div>
SVG
An alternative could be to use SVG to generate the shape you want. SVG's are responsive and well supported across browsers.
<svg width="50%" viewbox="0 0 100 100">
<polygon points="2,25 2,98 98,98 98,25 50,2z" fill="white" stroke-width="2" stroke="#642850"></polygon>
<polyline points="2,25 98,25" stroke="#642850" stroke-width="2"></polyline>
</svg>
Try this
.b{
width:200px;
height:100px;
overflow:hidden;
}
.b div{
width:200px;
height:200px;
transform:rotate(45deg);
content:"";
border:10px solid red;
margin-top:40px;
margin-left:-10px;
}
.a{
width:180px;
height:200px;
border:10px solid red;
margin-top:0px;
}
<div class="b"><div></div></div>
<div class="a"></div>
With one div and using generated content:
div {width:100px; height:100px; border:5px solid red; position:relative; margin-top:50px}
div:after,div:before {content:""; position:absolute; border:55px solid red; border-color:transparent transparent red transparent; border-width:40px 55px; bottom:105px; left:-5px}
div:after {border-color:transparent transparent white transparent; border-width:34px 48px; left:2px}
<div></div>
Try this solution:
.roof {
position: absolute;
top: calc(499px - 48px);
left: 899px;
height: 0;
width: 0;
border-left: 120px solid #f00;
border-top: 120px solid transparent;
transform: rotate(135deg);
}
.roofCovering {
position: absolute;
top: calc(499px - 48px + 5px);
left: 909px;
height: 0;
width: 0;
border-left: 100px solid #fff;
border-top: 100px solid transparent;
transform: rotate(135deg);
}
.house {
position: absolute;
top: calc(499px - 48px + 58px);
left: 874px;
height: 165px;
width: 160px;
border: 5px solid #f00;
}
<div class="roof"></div>
<div class="roofCovering"></div>
<div class="house"></div>
Does anyone know how to make the blue shape above in css3?
use css border-radius and box-shadow
<div class=social></div>
demo: http://jsfiddle.net/vS7bS/4/
.social{
margin: 100px;
width: 150px;
height: 150px;
position: relative;
background: green;
border-radius: 100%;
border: 2px solid black;
overflow:hidden;
box-shadow: 100px 0 0 -2px blue, 100px 0 0px 0px black;
}
.social:after{
content: '';
position: absolute;
left: 100px;
top: 0;
width: 100%;
height: 100%;
border-radius: 100%;
background: red;
box-shadow: 0 0 0 2px black;
}
Demo 2:http://jsfiddle.net/vS7bS/5/
Demo with :hover http://jsfiddle.net/vS7bS/6/
<div class=social>
<section>
<div></div>
<div></div>
</section>
<div></div>
</div>
css
section{
position:relative;
width:150px;
height:150px;
overflow:hidden;
border-radius:100%;
box-shadow: 0 0 0 2px black;
z-index: 10;
}
section div{
width: 170px;
height: 170px;
border-radius:100%;
border:2px solid black;
position:absolute;
}
section div:nth-child(1):hover{
background:orange;
}
section div:nth-child(2):hover{
background:#333;
}
section div:nth-child(1){
left: -8px;
top: -3px;
background: blue;
}
section div:nth-child(2){
width: 150px;
height: 150px;
border-radius: 100%;
border: 2px solid black;
background: red;
right: -76px;
position: absolute;
}
.social{
position:relative;
width: 156px;
height: 156px;
margin:100px;
}
.social >div{
width: 150px;
height: 150px;
border-radius: 100%;
border: 2px solid black;
background: yellow;
right: -70px;
top: 0;
position: absolute;
z-index: 1;
}
.social >div:hover{
background:skyblue;
}
Try this
jsfiddle DEMO
result
#shape {
position:absolute;
top:100px;
left:100px;
width: 80px;
height: 80px;
background: blue;
margin: 3px 0 0 30px;
/* Rotate */
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
/* Rotate Origin */
-webkit-transform-origin: 0 100%;
-moz-transform-origin: 0 100%;
-ms-transform-origin: 0 100%;
-o-transform-origin: 0 100%;
transform-origin: 0 100%;
-moz-border-radius: 60px 0px;
-webkit-border-radius: 60px 0px;
border-radius: 80px 0px;
}