I'm doing some CSS animations with a baby's animated face, and I'm trying to create the mouth as a specific smile shape.
The shape I need looks like this. Take note of the top left and right edges, which are rounded:
You can see the closest I've gotten here. The only thing missing is the rounded top left and right edges.
.half-circle {
height:150px;
width: 75px;
border-radius: 150px 0 0 150px;
border-top: 20px solid #000;
border-left: 20px solid #000;
border-bottom: 20px solid #000;
transform: translate(100px) rotate(-90deg);
}
<div class="half-circle"></div>
*Edit The submitted answers so far are not good enough so I unfortunately had to use a bitmap instead. If someone finds a better solution in the future, please provide an answer and I'll mark it as accepted if it works adequately.
Flink suggested adding circles in a comment so I tried it, and while not perfect it might be the best option. I edited the fiddle below with the circles. If someone has a better alternative or a way to do this better, then please let me know/post an answer:
JSFiddle
.half-circle {
height:150px;
width: 75px;
border-radius: 150px 0 0 150px;
border-top: 20px solid #000;
border-left: 20px solid #000;
border-bottom: 20px solid #000;
transform: translate(100px) rotate(-90deg);
position: relative;
}
.border-circle {
background-color: #000;
width: 20px;
height: 20px;
border-radius: 100%;
position: absolute;
}
.left-circle {
right: -8px;
top: -20px;
}
.right-circle {
bottom: -20px;
right: -8px;
}
<div class="half-circle">
<div class="border-circle left-circle"></div>
<div class="border-circle right-circle"></div>
</div>
Here is an example:
.half-circle {
height:150px;
width: 75px;
position: absolute;
border-radius: 150px 0 0 150px;
border-top: 20px solid #000;
border-left: 20px solid #000;
border-bottom: 20px solid #000;
transform: translate(100px) rotate(-90deg);
}
.half-circle:before, .half-circle:after{
content: "";
width: 10px;
height: 20px;
position: absolute;
left: 99%;
top: -20px;
background: #000;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
}
.half-circle:after{
bottom:-20px;
top: inherit;
}
<div class="half-circle"></div>
JSFIDDLE LINK
By changing the 0 0 in border-radius, I was able to round the outer
sides of the half circle. I will edit if/when I figure out the
insides.
Note: I understand this isn't the full answer but it might get you on the right track.
.half-circle {
height:150px;
width: 75px;
border-radius: 150px 20px 20px 150px ;
border-top: 20px solid #000;
border-left: 20px solid #000;
border-bottom: 20px solid #000;
transform: translate(100px) rotate(-90deg);
}
<div class="half-circle"></div>
Related
Creating a DIV that uses CSS to draw a triangle to the left. Trying to apply a uniform box-shadow to both parent and the pseudo element (see images) and code.
Is this possible? Or am I better off using border-image for this?
(Top: Before Shadow, Middle: CSS Box-Shadow, Bottom: Desired Result)
.bubble{
height: 200px;
width: 275px;
opacity: 0;
margin-top: 41px;
float: right;
background-color: #F2F2F2;
-webkit-border-radius: 5px;
-webkit-box-shadow: 0px 0px 6px #B2B2B2;
}
.bubble::after {
height: 0px;
width: 0px;
content: "\00a0";
display: block;
margin-left: -10px;
margin-top: 28px;
border-width: 10px 10px 10px 0;
border-style: solid;
border-color: transparent #F2F2F2 transparent transparent;
-webkit-box-shadow: 0px 0px 6px #B2B2B2;
}
Instead of using a triangle hack, you can just rotate a div using transform and get a real box-shadow. Since you only want the shadow on one side of the div (the visible triangle side), you have to make the blur smaller and lower the opacity.
Demo: http://jsfiddle.net/ThinkingStiff/mek5Z/
HTML:
<div class="bubble"></div>
CSS:
.bubble{
background-color: #F2F2F2;
border-radius: 5px;
box-shadow: 0px 0px 6px #B2B2B2;
height: 200px;
margin: 20px;
width: 275px;
}
.bubble::after {
background-color: #F2F2F2;
box-shadow: -2px 2px 2px 0 rgba( 178, 178, 178, .4 );
content: "\00a0";
display: block;
height: 20px;
left: -10px;
position: relative;
top: 20px;
transform: rotate( 45deg );
-moz-transform: rotate( 45deg );
-ms-transform: rotate( 45deg );
-o-transform: rotate( 45deg );
-webkit-transform: rotate( 45deg );
width: 20px;
}
Output:
Here is a complete working example in full (S)CSS, with
variables for nose size shadow width and an optional border.
The trick is to get the offsets and transform right to achieve pixel-perfection, and to use overflow:hidden as necessary to cut the nose of your bubble (especially if you need borders).
The example in the answer above doesn't work for us because the shadow gets cropped and is laid over the main bubble area.
Degrades gracefully in IE7/8.
HTML:
<div class="chat">
<div class="bubble">
<span class='tail'> </span>
<p>The path of the righteous man is beset on all sides by the iniquities of the selfish and the tyranny of evil men. Blessed is he who, in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children.</p><p>And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy My brothers. And you will know My name is the Lord when I lay My vengeance upon thee.</p>
</div>
</div>
SCSS:
$shadow_radius = 6px;
$nose_size = 12px;
$shadow = 0 1px $shadow_radius #B2B2B2;
$border = 1px solid #bbb
.chat {
font-family: sans-serif;
font-size: small;
}
.bubble {
background-color: #F2F2F2;
border-radius: 5px;
border: $border;
box-shadow: $shadow;
display: inline-block;
padding: 10px 18px;
margin-left: ($shadow_radius + $nose_size);
margin-right: ($shadow_radius + $nose_size);
position: relative;
vertical-align: top;
}
.tail {
position: absolute;
top: $nose_size;
left: -($shadow_radius + $nose_size);
height: ($shadow_radius + $nose_size);
width: ($shadow_radius + $nose_size);
overflow: hidden;
}
.tail:before {
border: $border;
background-color: #F2F2F2;
box-shadow: $shadow;
content: "\00a0";
display: block;
position: absolute;
top: 0px;
left: $nose_size;
height: $nose_size;
width: $nose_size;
-webkit-transform: skew( -45deg );
-moz-transform: skew( -45deg );
}
Another solution is to use filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); It only places the shadow around the objects shape.
I know It's a little bit tricky but, seems nice to me.
Here is the fiddle http://jsfiddle.net/dzfj6/
HTML
<div class="bubble">
<div class="triangle"></div>
<div class="border"></div>
<div class="content">some content</div>
</div>
CSS
.bubble
{
height: 200px;
width: 275px;
float:right;
margin-top: 41px;
margin-left:11px;
background-color: #f2f2f2;
-webkit-border-radius: 5px;
-webkit-box-shadow: 0px 0px 5px #b2b2b2;
position:relative;
z-index:1;
}
.triangle
{
position:absolute;
top:12px;
width: 0;
height: 0;
border-top: 15px solid transparent;
border-bottom: 15px solid transparent;
border-right: 10px solid #f2f2f2;
margin-left:-9px;
z-index:3;
}
.border
{
position:absolute;
top:12px;
width: 0;
height: 0;
border-top: 15px solid transparent;
border-bottom: 15px solid transparent;
border-right: 10px solid #e0e0e0;
margin-left:-10px;
z-index:2;
}
.content{
padding:10px;
}
Instead of box-shadow, you can simply use border for buble.
Don't use box-shadow.
height: 200px;
width: 275px;
float:right;
margin-top: 41px;
margin-left:11px;
background-color: #f2f2f2;
-webkit-border-radius: 5px;
-webkit-box-shadow: 0px 0px 5px #b2b2b2;
position:relative;
z-index:1;
I have been trying hard without success to add a little triangle under my square to act as a pointer like this:
My code by itself works, but whenever I try to add css to make this triangle nothing will appear. I think it has to do with before-after functions, but I'm not really getting it. Anyone can help me with that?
<div id="slider_outer1">
<div class="slider_segment"><img src="myurl.com" alt="Nature" style="width:100%;"></div>
<div id="slider_marker1"></div>
</div>
<style>
.container {width:400px;}
#slider_outer1 {width: 98%;border: 5px solid #8f89ff; position: relative;display: inline-block; border-radius: 5px;}
.slider_segment {width: 100%; float: left; display: inline;}
#slider_marker1 {
position: absolute;
border: 2px solid #574fff;
height: 30px;
width: 5%;
top: 120px;
left: 57.25%;
text-align: center;
Margin-left: -10%;
padding: 5px 0px;
background: #ffffff;
border-radius: 5px;
}
div#slider_marker1:after {
content: "5";
font-size: 20px;
padding: 5px;
line-height: 30px;
font-family: sans-serif;
}
</style>
edit: code of the triangle
<div class="triangle-down"></div>
<style>
.triangle-down {
width: 0;
height: 0;
border-left: 15px solid transparent;
border-right: 15px solid transparent;
border-top: 20px solid #555;
}
</style>
Generally in CSS triangles are made using borders, not before and after pseudo elements. To create a downward pointing triangle, you would create a top border of n number of pixels, and left and right borders of half that width and also transparent.
Example:
<div id="slider_outer1">
<div class="slider_segment"><img src="myurl.png" alt="Nature" style="width:100%;"></div>
<div id="slider_marker1"><div id='triangle-down'></div></div>
</div>
<style>
.container {width:400px;}
#slider_outer1 {width: 98%;border: 5px solid #8f89ff; position: relative;display: inline-block; border-radius: 5px;}
.slider_segment {width: 100%; float: left; display: inline;}
#slider_marker1 {
position: absolute;
border: 2px solid #574fff;
height: 30px;
width: 5%;
top: 120px;
left: 57.25%;
text-align: center;
Margin-left: -10%;
padding: 5px 0px;
background: #ffffff;
border-radius: 5px;
}
#triangle-down {
position: absolute;
top: 40px;
right: 50%;
transform: translateX(50%);
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-top: 20px solid blue;
}
div#slider_marker1:after {
content: "5";
font-size: 20px;
padding: 5px;
line-height: 30px;
font-family: sans-serif;
}
</style>
See my codepen here: https://codepen.io/anon/pen/bvXOab
You could add another div for the triangle like
<div id='triangle'></div>
Css For the triangle...
#triangle{
width: 0;
height: 0;
border-left: 40px solid transparent;
border-right: 40px solid transparent;
border-top: 80px solid blue;
}
However I feel that your problem is not that it just isnt appearing its that the positioning is messed up so its 'hidden' behind the sliders
I think I understand what you're trying to make. This should add a triangle above the marker. This solution should allow you to also remove anything related to triangle-down as it only requires the slider_marker1 div
#slider_marker1::before {
content: "";
width: 0;
height: 0;
position: absolute;
top: -6px;
left: 0;
right: 0;
margin: auto;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-bottom: 4px solid green;
z-index: 100;
}
Please take a look here:
http://jsfiddle.net/ztu267zp/1/
border:3px solid grey;
border-bottom: 8px solid red;
At the bottom corners you can see, that both the grey and the red borders intersect diagonally.
Can I cut the grey border to end at the bottom of the DIV and the red border having 100% width over the full distance?
Thank you very much,
Doing it right now with box-shadows, but also here, there is no clean edge in Chrome and FF:
http://imgur.com/mf7ABEO
Thanks
matt
its not possible but you can use something like this
<div id="bord">
<div class="line-cover">
</div>
css
#bord{
height:200px;
width:200px;
border:3px solid grey;
border-bottom: 8px solid white;
}
.line-cover{
position: relative;
border-bottom: 8px solid red;
width: 100%;
top: 200px;
padding: 0 3px;
left: -3px;
}
Fiddle here
What about st. like that, using pseudoelement after?
#bord{
height:200px;
width:200px;
border:3px solid grey;
border-bottom: 0;
/*border-bottom: 8px solid red;*/
position: relative;
}
#bord:after {
display: block;
background: red;
height: 8px;
width: 100%;
content: '';
position: absolute;
bottom: -8px;
left: 0;
margin: 0 -3px;
padding: 0 3px;
}
http://jsfiddle.net/ztu267zp/4/
This question already has answers here:
Div with cut out edges, border and transparent background
(6 answers)
Closed 7 years ago.
What I want to achieve :
What I did so far is to make the corners as if it had the same color with the container and then cover the unneeded area with the "fake" square rotated by 45 deg.
I don't like that much the result, especially the bottom right corner and I can't thing another way to do it. What is the best way to achieve it ? Is it possible to be done with gradients ?
First Step : http://jsfiddle.net/laxmana/wjaAs/
Final : http://jsfiddle.net/laxmana/j9NWC/
CSS :
.chamfered-box{
width: 100%;
position: relative;
background: white;
border: 1px solid #149E4B;
}
.chamfered-box::before, .chamfered-box::after{
width: 0px;
height: 0px;
background: #fff;
content: '';
position: absolute;
bottom: 0;
}
.chamfered-box::after{
right: -1px;
bottom: -1px;
border-top: 10px solid #149E4B;
border-right: 10px solid white;
border-left: 10px solid #149E4B;
border-bottom: 10px solid white;
}
.chamfered-box::before{
left: -1px;
top: -1px;
border-top: 10px solid #149E4B;
border-right: 10px solid white;
border-left: 10px solid #149E4B;
border-bottom: 10px solid white;
}
.ch-top, .ch-bottom{position: absolute;z-index: 5;}
.ch-top{
top: -16px;
left: -18px;
width: 30px;
height: 30px;
background: white;
-webkit-transform: rotate(45deg);
}
.ch-bottom{
bottom: 5px;
right: 6px;
width: 28px;
height: 28px;
background: white;
-webkit-transform: rotate(45deg);
}
.ch-content{
padding: 20px;
}
HTML :
<div class="chamfered-box">
<div class="ch-top"></div>
<div class="ch-bottom"></div>
<div class="ch-content">The text</div>
</div>
You may use the pseudo element and rotate them on top(over) of the container with a little difference from your method.
Draw an inset shadow instead a border to your container.
Draw squares with a white background (as container) with borders.
Rotate the square and hide part of them overflowing from container.
DEMO
.chamfered-box{
margin:1em auto;
width: 440px;
padding:5px;
position: relative;
overflow:hidden;
background: white;
box-shadow: inset 0 0 0 1px #149E4B;
}
.chamfered-box::before, .chamfered-box::after{
width: 20px;
height: 20px;
background: #fff;
content: '';
position: absolute;
bottom: 0;
border: 1px solid #149E4B;
transform:rotate(45deg);
}
.chamfered-box::after{
right: -11px;
bottom: -11px;
}
.chamfered-box::before{
left: -11px;
top: -11px;
}
Creating a DIV that uses CSS to draw a triangle to the left. Trying to apply a uniform box-shadow to both parent and the pseudo element (see images) and code.
Is this possible? Or am I better off using border-image for this?
(Top: Before Shadow, Middle: CSS Box-Shadow, Bottom: Desired Result)
.bubble{
height: 200px;
width: 275px;
opacity: 0;
margin-top: 41px;
float: right;
background-color: #F2F2F2;
-webkit-border-radius: 5px;
-webkit-box-shadow: 0px 0px 6px #B2B2B2;
}
.bubble::after {
height: 0px;
width: 0px;
content: "\00a0";
display: block;
margin-left: -10px;
margin-top: 28px;
border-width: 10px 10px 10px 0;
border-style: solid;
border-color: transparent #F2F2F2 transparent transparent;
-webkit-box-shadow: 0px 0px 6px #B2B2B2;
}
Instead of using a triangle hack, you can just rotate a div using transform and get a real box-shadow. Since you only want the shadow on one side of the div (the visible triangle side), you have to make the blur smaller and lower the opacity.
Demo: http://jsfiddle.net/ThinkingStiff/mek5Z/
HTML:
<div class="bubble"></div>
CSS:
.bubble{
background-color: #F2F2F2;
border-radius: 5px;
box-shadow: 0px 0px 6px #B2B2B2;
height: 200px;
margin: 20px;
width: 275px;
}
.bubble::after {
background-color: #F2F2F2;
box-shadow: -2px 2px 2px 0 rgba( 178, 178, 178, .4 );
content: "\00a0";
display: block;
height: 20px;
left: -10px;
position: relative;
top: 20px;
transform: rotate( 45deg );
-moz-transform: rotate( 45deg );
-ms-transform: rotate( 45deg );
-o-transform: rotate( 45deg );
-webkit-transform: rotate( 45deg );
width: 20px;
}
Output:
Here is a complete working example in full (S)CSS, with
variables for nose size shadow width and an optional border.
The trick is to get the offsets and transform right to achieve pixel-perfection, and to use overflow:hidden as necessary to cut the nose of your bubble (especially if you need borders).
The example in the answer above doesn't work for us because the shadow gets cropped and is laid over the main bubble area.
Degrades gracefully in IE7/8.
HTML:
<div class="chat">
<div class="bubble">
<span class='tail'> </span>
<p>The path of the righteous man is beset on all sides by the iniquities of the selfish and the tyranny of evil men. Blessed is he who, in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children.</p><p>And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy My brothers. And you will know My name is the Lord when I lay My vengeance upon thee.</p>
</div>
</div>
SCSS:
$shadow_radius = 6px;
$nose_size = 12px;
$shadow = 0 1px $shadow_radius #B2B2B2;
$border = 1px solid #bbb
.chat {
font-family: sans-serif;
font-size: small;
}
.bubble {
background-color: #F2F2F2;
border-radius: 5px;
border: $border;
box-shadow: $shadow;
display: inline-block;
padding: 10px 18px;
margin-left: ($shadow_radius + $nose_size);
margin-right: ($shadow_radius + $nose_size);
position: relative;
vertical-align: top;
}
.tail {
position: absolute;
top: $nose_size;
left: -($shadow_radius + $nose_size);
height: ($shadow_radius + $nose_size);
width: ($shadow_radius + $nose_size);
overflow: hidden;
}
.tail:before {
border: $border;
background-color: #F2F2F2;
box-shadow: $shadow;
content: "\00a0";
display: block;
position: absolute;
top: 0px;
left: $nose_size;
height: $nose_size;
width: $nose_size;
-webkit-transform: skew( -45deg );
-moz-transform: skew( -45deg );
}
Another solution is to use filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); It only places the shadow around the objects shape.
I know It's a little bit tricky but, seems nice to me.
Here is the fiddle http://jsfiddle.net/dzfj6/
HTML
<div class="bubble">
<div class="triangle"></div>
<div class="border"></div>
<div class="content">some content</div>
</div>
CSS
.bubble
{
height: 200px;
width: 275px;
float:right;
margin-top: 41px;
margin-left:11px;
background-color: #f2f2f2;
-webkit-border-radius: 5px;
-webkit-box-shadow: 0px 0px 5px #b2b2b2;
position:relative;
z-index:1;
}
.triangle
{
position:absolute;
top:12px;
width: 0;
height: 0;
border-top: 15px solid transparent;
border-bottom: 15px solid transparent;
border-right: 10px solid #f2f2f2;
margin-left:-9px;
z-index:3;
}
.border
{
position:absolute;
top:12px;
width: 0;
height: 0;
border-top: 15px solid transparent;
border-bottom: 15px solid transparent;
border-right: 10px solid #e0e0e0;
margin-left:-10px;
z-index:2;
}
.content{
padding:10px;
}
Instead of box-shadow, you can simply use border for buble.
Don't use box-shadow.
height: 200px;
width: 275px;
float:right;
margin-top: 41px;
margin-left:11px;
background-color: #f2f2f2;
-webkit-border-radius: 5px;
-webkit-box-shadow: 0px 0px 5px #b2b2b2;
position:relative;
z-index:1;