I have CSS code
#box {
width: 200px;
height: 50px;
background-color: blue;
border-top-left-radius: 9999px;
border-bottom-left-radius: 9999px;
position: relative;
margin: 30px;
text-align: center;
color: white;
padding-top: 10px;
}
#box::before,
#box::after {
content: "";
width: 0;
height: 0;
right: 0;
position: absolute;
}
#box::before {
border-right: 10px solid blue;
border-top: 10px solid blue;
border-left: 10px solid transparent;
border-bottom: 10px solid transparent;
bottom: -20px;
}
#box::after {
border-right: 10px solid blue;
border-top: 10px solid transparent;
border-left: 10px solid transparent;
border-bottom: 10px solid blue;
position: absolute;
top: -20px;
}
<div id="box">#box</div>
which gives some shape like
shape I need is
I need curved line instead of hypotenuse in triangles at top-right (#box::before) and bottom-right (#box::after) as in image.
Is there any way to achieve using pure CSS ?
codesandbox demo
Thanks
You can create a concaved radius using the box-shadow property.
This technique creates a transparant square with overflow hidden.
It then creates a transparant circle with a box shadow.
We then adjust the position of the circle to only view 1 quarter of
it.
SNIPPET
#box {
position: relative;
width: 200px;
height: 50px;
background-color: blue;
border-radius: 9999px 0 0 9999px;
margin: 30px;
text-align: center;
color: #fff;
padding-top: 10px;
}
#top,
#bottom {
position: absolute;
height: 30px;
width: 30px;
right: 0;
overflow: hidden;
}
#top {
top: -30px;
}
#bottom {
bottom: -30px;
}
#top::before,
#bottom::before {
content: '';
position: absolute;
right: 0;
height: 200%;
width: 200%;
border-radius: 100%;
box-shadow: 10px 10px 5px 100px blue;
z-index: -1;
}
#top::before {
top: -100%;
}
<div id="box">
<div id="top"></div>
#box
<div id="bottom"></div>
</div>
You can easily achieve this by using svg background images like in this snippet. Here the curves may not the way you want but surely you can change the path in the svg to your needs.
#box {
width: 200px;
height: 50px;
background-color: blue;
border-top-left-radius: 9999px;
border-bottom-left-radius: 9999px;
position: relative;
margin: 30px;
}
#box::before,
#box::after {
content: "";
width: 20px;
height: 20px;
right: 0;
position: absolute;
}
#box::before {
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg"><path fill="blue" d="M0 0 Q20 0 20 20 L20 0Z" /></svg>');
bottom: -20px;
}
#box::after {
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg"><path fill="blue" d="M0 20 Q20 20 20 0 L20 20Z" /></svg>');
top: -20px;
}
<div id="box"></div>
Can you use negative space? You could have a container with the same background color as your shape, then round the corners surrounding elements to create the illusion.
.container {
background-color: blue;
width: 100%;
}
.negat {
background-color: white;
height: 100px;
}
.posit-bg {
background-color: white;
}
.posit {
background-color: blue;
height: 100px;
border-radius: 50px 0px 0px 50px;
}
.top {
border-radius: 0px 0px 50px 0px;
}
.bot {
border-radius: 0px 50px 0px 0px;
}
<div class="container">
<div class="negat top"></div>
<div class="posit-bg">
<div class="posit"></div>
</div>
<div class="negat bot"></div>
</div>
#box{
width:200px;
height:50px;
background-color:blue;
color:#ffffff;
text-align:center;
padding-top:30px;
border-radius:9999px 0 0 9999px;
}
.sq{
width:25px;
height:25px;
background-color:blue;
}
#sq1,#sq2,#sq11,#sq22{
border-radius:-999px;
margin-left:175px;
}
.sq1{
background-color:#ffffff;
height:25px;
width:25px;
}
#sq11{
border-bottom-right-radius:9999px;
margin-bottom:-25px;
position: relative;
z-index:1;
}
#sq22{
border-top-right-radius:9999px;
margin-top:-25px;
position: relative;
z-index:1;
}
<div class="sq1" id="sq11"></div>
<div class="sq" id="sq1"></div>
<div id="box">#box</div>
<div class="sq" id="sq2"></div>
<div class="sq1" id="sq22"></div>
Related
I child div is not being able to fill the corner of a parent div with a border-radius.
See the top right corner of this picture
.outer {
border-radius: 20px;
background: red;
height: 400px;
overflow: hidden;
position: relative;
width: 600px;
z-index: 10;
border: solid 1px white;
}
.corner {
border-radius: 0 0 0 20px;
background: white;
padding: 14px 20px;
position: absolute;
right: -4px;
top: -4px;
}
<div class="outer">
<div class="corner">Corner Element
</div>
</div>
Any ideas or workarounds?
You can add a small padding and make the background to cover only the content.
.outer {
border-radius: 20px;
background: red content-box;
padding:1px;
height: 400px;
overflow: hidden;
position: relative;
width: 600px;
z-index: 10;
border: solid 1px white;
}
.corner {
border-radius: 0 0 0 20px;
background: white;
padding: 14px 20px;
position: absolute;
right: -4px;
top: -4px;
}
<div class="outer">
<div class="corner">Corner Element
</div>
</div>
Or disable the coloration in that corner with a gradient:
.outer {
border-radius: 20px;
background: linear-gradient(-135deg,transparent 20px,red 0);
height: 400px;
overflow: hidden;
position: relative;
width: 600px;
z-index: 10;
border: solid 1px white;
}
.corner {
border-radius: 0 0 0 20px;
background: white;
padding: 14px 20px;
position: absolute;
right: -4px;
top: -4px;
}
<div class="outer">
<div class="corner">Corner Element
</div>
</div>
This question already has answers here:
Speech bubble with arrow
(3 answers)
Closed 6 years ago.
i'm making special boxes with shape like this, i don't know how to draw this with css
You can first create rectangle with border-radius and add triangle with :after pseudo-element.
.shape {
width: 200px;
height: 50px;
background: #B67025;
margin: 50px;
border-radius: 25px;
position: relative;
}
.shape:after {
content: '';
position: absolute;
border-style: solid;
right: 0;
top: 50%;
border-width: 10px 0 10px 10px;
transform: translate(80%, -50%);
border-color: transparent transparent transparent #B67025;
}
<div class="shape"></div>
Look here at the example Talk Bubble: https://css-tricks.com/examples/ShapesOfCSS/
and here'e the code:
#talkbubble {
width: 120px;
height: 80px;
background: red;
position: relative;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
margin: 50px
}
#talkbubble:before {
content:"";
position: absolute;
right: 100%;
top: 26px;
width: 0;
height: 0;
border-top: 13px solid transparent;
border-right: 26px solid red;
border-bottom: 13px solid transparent; }
<div id="talkbubble"></div>
SVG
Creating a complex shape is easier to do with a SVG then CSS:
svg {
/*For demonstration only*/
border: 1px solid black;
}
<svg width="300px" viewBox="0 0 200 100">
<path d="m50,10 95,0
a40 40 0 0 1 40,30
l10,10
l-10,10
a40 40 0 0 1 -40,30
h-95 a1 1 0 0 1 0,-80z" fill="rgb(182, 112, 37)"/>
</svg>
Impressed with the solution given by #Nenad Vracar
Here is another way of doing the same, may be helpful in understanding the CSS properties.
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<style>
.main-div {
position: relative;
}
.first {
width: 150px;
height: 50px;
background: #B67025;
border-radius: 25px 0 0 25px;
float: left;
position: absolute;
top: 0;
}
.second {
width: 50px;
height: 50px;
background: #B67025;
border-radius: 0 25px 25px 0;
float: left;
position: absolute;
left: 150px;
}
.third {
position: absolute;
left: 197px;
top: 15px;
width: 0;
height: 0;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: 10px solid #B67025;
}
</style>
</head>
<body>
<div class="main-div">
<div class="first">
</div>
<div class="second">
</div>
<div class="third">
</div>
</div>
</body>
</html>
I want the border div to be "hidden" behind the circle and not cross through it. I thought z-index was the way to do things like this.
Any ideas?
JSFIDDLE: http://jsfiddle.net/qs5xmege/1/
CSS and HTML
.container {
width: 15%;
height: 100px;
float: left;
position: relative;
}
.circle {
width:22px;
height:22px;
border-radius:11px;
border: 3px solid red;
background-color: #FFF;
margin: 30px auto 0 auto;
z-index: 100;
}
.border {
width: 50%;
height: 100px;
position: absolute;
border-right: thin solid black;
top: 0;
left: 0;
z-index: 1;
}
<div class="container">
<div class="border"></div>
<div class="circle"></div>
</div>
Give .circle a position:relative, z-index works only with position:relative, position:absolute or position: fixed
.container {
width: 15%;
height: 100px;
float: left;
position: relative;
}
.circle {
width:22px;
height:22px;
border-radius:11px;
border: 3px solid red;
background-color: #FFF;
margin: 30px auto 0 auto;
position: relative;
z-index: 100;
}
.border {
width: 50%;
height: 100px;
position: absolute;
border-right: thin solid black;
top: 0;
left: 0;
z-index: 1;
}
<div class="container">
<div class="border"></div>
<div class="circle"></div>
</div>
Add position:relative; to .circle.
z-index need relative, absolute or fixed vaue for position.
Set position:relative of div circle and z-index:2 ie. 1 more than border is enough
.circle {
background-color: #FFFFFF;
border: 3px solid #FF0000;
border-radius: 11px;
height: 22px;
margin: 30px auto 0;
position: relative;
width: 22px;
z-index: 2;
}
Snippet
.container {
width: 15%;
height: 100px;
float: left;
position: relative;
}
.circle {
background-color: #FFFFFF;
border: 3px solid #FF0000;
border-radius: 11px;
height: 22px;
margin: 30px auto 0;
position: relative;
width: 22px;
z-index: 2;
}
.border {
width: 50%;
height: 100px;
position: absolute;
border-right: thin solid black;
top: 0;
left: 0;
z-index: 1;
}
<div class="container">
<div class="border"></div>
<div class="circle"></div>
</div>
Try like this:
.circle {
background-color: #fff;
border: 3px solid red;
border-radius: 11px;
display: block;
height: 22px;
margin: 0 auto;
position: relative;
top: -68px;
width: 22px;
}
.border {
border-right: thin solid black;
height: 100px;
width: 50%;
}
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/
please help to draw a pentagon means css.
I definitely need to pentagon could completely fill the text. The text should not extend beyond the pentagon (overflow:hidden).
html:
<div class="carousel_gallery" id="carousel_gallery">
укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>укукукБЮ<br>
</div>
css:
body{
position: relative;
}
.carousel_gallery {
width: 360px;
height: 365px;
position: absolute;
top: 0px;
left: 50%;
margin-left: -185px;
border: 1px solid red;
overflow: hidden;
}
.carousel_gallery:before {
content: "";
width: 255px;
height: 255px;
margin-left: 52px;
margin-top: 237px;
position: absolute;
border-bottom: 1px solid red;
border-right: 1px solid red;
-webkit-transform: rotate(45deg);
background: white;
}
fiddle
customize this pentagon..hope this will help you!
<style type="text/css">
#pentagon {
margin:70px 0 5px 20px;
position: relative;
width: 110px;
border-width: 100px 36px 0;
border-style: solid;
border-color: #abefcd transparent;
}
#pentagon:before {
content: "";
position: absolute;
height: 0;
width: 0;
top: -170px;
left: -36px;
border-width: 0 90px 70px;
border-style: solid;
border-color: transparent transparent #abefcd;
}
/* Content in pentagon */
#pentagon div{
position:absolute;
top:-50px;
}
</style>
<div id="pentagon"><div>you text</div></div>