I created a chat bubble using CSS. But I did not get the output I want. Here is my code,
body{
background-color: lightgreen;
}
.bubble {
margin: 100px;
display: inline-block;
position: relative;
width: 300px;
height: auto;
background-color: white;
}
.border{
border: 2px solid red;
}
.border-radius{
border-radius: 10px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
}
.triangle-right.border.right-top:before {
content: ' ';
position: absolute;
width: 0;
height: 0;
left: auto;
right: -26px;
top: -2px;
bottom: auto;
border: 25px solid;
border-color: red transparent transparent transparent;
}
.triangle-right.right-top:after{
content: ' ';
position: absolute;
width: 0;
height: 0;
left: auto;
right: -22px;
top: -0.3px;
bottom: auto;
border: 25px solid;
border-color: white transparent transparent transparent;
}
.chat{
padding: 6px;
}
<div class="bubble triangle-right border-radius border right-top">
<div class="chat">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit,</p>
</div>
</div>
Output I Get:
Output I Want:
How can I get the output in the second picture. I want to get a curve like effect on top right corner (just like in the second image). thanks.
You can try a radial-gradient() to draw the curve :
possible example
body{
background-color: lightgreen;
}
.bubble {
margin: 100px;
display: inline-block;
position: relative;
width: 300px;
height: auto;
background-color: white;
}
.border{
border: 2px solid red;
}
.border-radius{
border-radius: 10px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
}
.triangle-right.right-top:before{
content: ' ';
position: absolute;
border-top:2px red solid;
width:6px;
top:-2px;
right:0;
height:10px;
background:white;
}
.triangle-right.right-top:after{
content: ' ';
position: absolute;
width: 30px;
height: 40px;
left: auto;
right: -30px;
top: -2px;
background:radial-gradient(ellipse at bottom right, transparent 28px, red 29px , red 30px , white 31px);
border-top:solid red 2px;
}
.chat{
padding: 6px;
}
<div class="bubble triangle-right border-radius border right-top">
<div class="chat">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit,</p>
</div>
</div>
tweek size and position to your needs.
Related
I know I can absolute position the pointer of the Tooltip but how can I add the blur effect to the pointer? Because if I put blur effect to it, the blur will not only be shown on the bottom triangle of pointer, but also on the upper half of it.
You can try drop-shadow filter css effect.
.pointer {
width: 200px;
padding: 10px;
position: relative;
filter: drop-shadow(0px 0px 10px #b2b2b2);
background: #fff;
}
.pointer:after {
content: "";
position: absolute;
border: 20px solid;
border-color: #fff transparent transparent;
bottom: -40px;
left: calc(50% - 20px);
}
<div class="pointer">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam convallis interdum cursus.</div>
Check filter cross browser support
Also you can achieve this by using box-shadow and z-index css property. In this you will need to make an extra block to cover the upper part of shadow using :before/:after.
.pointer {
width: 200px;
padding: 10px;
position: relative;
box-shadow: 0px 0px 10px #b2b2b2;
background: #fff;
z-index: 1;
}
.pointer:after {
content: "";
position: absolute;
width: 30px;
height: 30px;
box-shadow: 0px 0px 10px #b2b2b2;
bottom: -15px;
left: calc(50% - 15px);
background: #fff;
transform: rotate(45deg);
z-index: -2;
}
.pointer:before {
content: "";
width: 60px;
height: 30px;
position: absolute;
background: #fff;
left: calc(50% - 30px);
bottom: 0;
z-index: -1;
}
<div class="pointer">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam convallis interdum cursus.</div>
You can use this code
body {
margin: 0;
padding: 0;
}
.example {
background: rgba(219,224,223,0.5);
margin-bottom: 20px;
padding: 20px;
text-align: center;
width: auto;
}
.example-with-box-shadow {
box-shadow: rgba(0,0,0,0.3) 0 2px 10px;
}
.example-with-arrow, .example-with-box-shadow, .example-with-drop-shadow {
background: white;
display: inline-block;
margin-bottom: 5px;
padding: 5px;
position: relative;
width: 200px;
}
.example-with-arrow::after, .example-with-box-shadow::after, .example-with-drop-shadow::after {
border: 10px solid;
border-top-color: currentcolor;
border-right-color: currentcolor;
border-bottom-color: currentcolor;
border-left-color: currentcolor;
border-color: white transparent transparent;
content: "";
left: 50%;
margin-left: -10px;
position: absolute;
top: 100%;
}
<div class="example">
<div class="example-with-box-shadow">Tooltip with box-shadow</div>
</div>
body {
background-color: #888;
}
.triangle {
position: relative;
margin: 3em;
padding: 1em;
box-sizing: border-box;
background: #bada55;
box-shadow: 0px 3px 3px 0 rgba(0, 0, 0, 0.4);
}
.triangle::after{
content: "";
position: absolute;
width: 0;
height: 0;
margin-left: -0.5em;
bottom: -2em;
left: 50%;
box-sizing: border-box;
border: 1em solid black;
border-color: transparent transparent #bada55 #bada55;
transform-origin: 0 0;
transform: rotate(-45deg);
box-shadow: -3px 3px 3px 0 rgba(0, 0, 0, 0.4);
}
<div class="triangle">This is a CSS3 triangle with a proper box-shadow!</div>
I want to design following shape using CSS. I don't want to use svg or canvas for this.
How can I design it. Any help would be greatly appreciated.
You can divide whole background in different parts and draw each with :before and :after pseudo element.
HTML:
<div class="box">
<div class="holder">
// content will go here...
</div>
</div>
* {box-sizing: border-box;}
body {
background: linear-gradient(orange, red);
min-height: 100vh;
margin: 0;
}
.box {
position: relative;
overflow: hidden;
padding: 10px;
width: 250px;
height: 300px;
margin: 20px;
}
.box:before {
position: absolute;
background: green;
border: 2px solid black;
z-index: -1;
content: '';
bottom: 0;
top: 20px;
right: 0;
left: 0;
}
.box:after {
border: solid black;
border-width: 2px 0 0 2px;
position: absolute;
background: green;
height: 30px;
content: '';
right: 50px;
z-index: -1;
left: 0;
top: 0;
}
.holder:before {
border-top: 2px solid black;
margin: -10px 14px 0 25px;
transform: rotate(52deg);
transform-origin: 0 0;
background: green;
float: right;
height: 30px;
content: '';
width: 26px;
}
<div class="box">
<div class="holder">
Lorem ipsum dolor sit sit amet, dolor sit sit amet, lorem ipsum dolor sit amet, lorem ipsum dolor sit amet ...
</div>
</div>
you can do that using 3 <div> tags
initially create a larger div
then create two smaller div with absolute position and set their background white
#border{
position:relative;
width:300px;
height:200px;
border:3px solid #000;
box-shadow:0px 0px 1px 3px #3dd7cf;
background:#304e4b;
border-bottom-width:5px;
}
#triangle{
position: absolute;
top: -31px;
right: 7px;
width: 50px;
height: 50px;
background: #fff;
border-bottom: 3px solid #3dd7cf;
transform: rotate(45deg);
box-shadow: 0px 2px 0px 0px #000;
z-index:990;
overflow:hidden;
}
#sqr{
position: absolute;
top: -22px;
right: -7px;
width: 40px;
height: 50px;
border-bottom: 4px solid #3dd7cf;
box-shadow: 0px 2px 0px 0px #000;
background: #fff;
z-index: 999;
}
<div id="border">
<div id="triangle"></div>
<div id="sqr"></div>
</div>
I am trying to recreate this image using a combination of CSS and HTML with no luck. Please advise.
Current Code:
.lens-profile-timeline {
list-style: none;
padding: 0;
margin: 60px 0 80px;
border-bottom: 8px solid #39752c;
position: relative;
}
.lens-profile-timeline li {
position: absolute;
width: 16px;
height: 16px;
border: 13px solid #39752c;
border-radius: 16px;
background: #fff;
margin-top: -10px;
margin-left: 20px;
margin-right: 20px;
}
.lens-profile-timeline time,
.lens-profile-timeline p {
left: -27px;
top: -40px;
position: absolute;
width: 70px;
text-align: center;
}
.lens-profile-timeline time {
margin-top: 70px;
font-size: 18px;
}
.lens-profile-timeline p {
margin-top: -0px;
font-size: 10px;
line-height: 1.1;
}
.lens-profile-timeline p:after {
content: "";
height: 8px;
border-left: 1px solid #39752c;
position: absolute;
bottom: -10px;
left: 35px;
}
<div class="row">
<div class="col-md-3">
</div>
<div class="col-md-6">
<ol class="lens-profile-timeline point">
<li style="left: 0;">
<time>1970</time>
</li>
<li style="left: 45%;">
<time datetime="2003-01-01">2003</time>
</li>
<li style="right: 0;">
<time>2013</time>
<p class="hidden">Current Year</p>
</li>
</ol>
</div>
<div class="col-md-3">
</div>
</div>
Above represents the current code being used to generate the image. However you will notice there are several elements which are missing.
You can do it with a combination of pseudo elements, CSS triangles and linear-gradients.
The linear-gradient(to right, #AFCB6D, #126A38); will create a mixed background color effect.
The triangles at the end can be created using CSS triangles concept using pseudo-elements.
The indicators are created with pseudo element circles as well. The indicator text can be specified within content: " " or remove the pseudo-elements and specify the text within div for better customization.
Regular text without using CSS content:
.timeline {
width: 500px;
height: 10px;
margin: 20px;
background: linear-gradient(to right, #AFCB6D, #126A38);
position: relative;
font-family: Roboto;
}
.timeline::before,
.timeline::after {
content: " ";
position: absolute;
height: 0px;
width: 0px;
top: -5px;
}
.timeline::before {
left: -20px;
border: 10px solid #AFCB6D;
border-color: transparent #AFCB6D transparent transparent;
}
.timeline::after {
right: -20px;
border: 10px solid #126A38;
border-color: transparent transparent transparent #126A38;
}
.indicators {
position: relative;
}
.indicator-1,
.indicator-2,
.indicator-3 {
border: 5px solid #AFCB6D;
background: white;
border-radius: 50%;
width: 10px;
height: 10px;
top: -5px;
position: absolute;
}
.indicator-1 {
left: 10px;
}
.indicator-2 {
border-color: #5B9951;
left: 240px;
}
.indicator-3 {
border-color: #126A38;
left: 475px;
}
.indicator-text {
position: relative;
top: 15px;
}
.indicator-1 .indicator-text {
left: -20px;
}
.indicator-2 .indicator-text {
left: -15px;
}
.indicator-3 .indicator-text {
left: -10px;
}
<div class="timeline">
<div class="indicators">
<div class="indicator-1">
<div class="indicator-text">Standard</div>
</div>
<div class="indicator-2">
<div class="indicator-text">Better</div>
</div>
<div class="indicator-3">
<div class="indicator-text">Best</div>
</div>
</div>
</div>
Titles using content property:
.timeline {
width: 500px;
height: 10px;
margin: 20px;
background: linear-gradient(to right, #AFCB6D, #126A38);
position: relative;
font-family: Roboto;
}
.timeline::before,
.timeline::after {
content: " ";
position: absolute;
height: 0px;
width: 0px;
top: -5px;
}
.timeline::before {
left: -20px;
border: 10px solid #AFCB6D;
border-color: transparent #AFCB6D transparent transparent;
}
.timeline::after {
right: -20px;
border: 10px solid #126A38;
border-color: transparent transparent transparent #126A38;
}
.indicator {
border: 5px solid #5B9951;
background: white;
border-radius: 50%;
width: 10px;
height: 10px;
margin: 0 auto;
top: -5px;
position: relative;
}
.indicator::after {
content: "\a Best";
white-space: pre;
border: 5px solid #126A38;
background: white;
border-radius: 50%;
width: 10px;
height: 10px;
top: -5px;
left: 230px;
position: absolute;
}
.indicator::before {
content: "\a Standard";
white-space: pre;
border: 5px solid #AFCB6D;
background: white;
border-radius: 50%;
width: 10px;
height: 10px;
top: -5px;
left: -240px;
position: absolute;
}
.spacer {
margin-top: 20px;
}
<div class="timeline">
<div class="indicator">
<div class="spacer"></div>Better
</div>
</div>
It's not perfect, but using CSS 3 gradients, and changing a few numbers, you can get something pretty close to your picture (minus the arrows)
I wrapped it all up in a JSBin.
Hope this helps,
Sean
I have this div:
I need css that do exacly that, the div and the arrow to the right like that.
Alos, i need a random text (length is changing, and we are talking responsive) in it and i want the text always to be in the middle of things... what is the best way to do so?
Here's a great generator to get you started and then you can customize it a little more to get your desired result
http://cssarrowplease.com/
To get something similar to what you showed, try
.arrow_box {
position: relative;
background: #3abc3d;
min-height: 80px;
border-radius: 10px;
padding: 20px;
}
.arrow_box:after {
left: 100%;
top: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-color: rgba(58, 188, 61, 0);
border-left-color: #3abc3d;
border-width: 20px;
margin-top: -20px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-xs-5 col-sm-4 col-md-4 col-lg-2">
<div class="arrow_box">
Message for everything
</div>
</div>
And on your arrow box, using bootstrap or whatever grid system you are using, attach the sizing for responsiveness.
Example 1
.block {
background: green;
border-radius: 10px;
padding: 20px;
position: relative;
color: #fff;
max-width: 200px;
margin: 0 auto;
}
.block:after {
content: '';
position: absolute; right: -20px; top: 50%;
border: 10px solid transparent;
border-left: 10px solid green;
-webkit-transform: translate(0,-50%);
-ms-transform: translate(0,-50%);
transform: translate(0,-50%);
}
<div class="block">
Block
</div>
Example 2
.block {
background: green;
border-radius: 10px;
padding: 20px;
position: relative;
color: #fff;
max-width: 200px;
margin: 0 auto;
}
.block:after{
content: '';
position: absolute; right: -10px; top: 50%;
background: green;
width: 20px; height: 20px;
margin-top: -10px;
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
}
<div class="block">
Block
</div>
Something like this,
Reference
<style>
.arrow-right {
width: 0;
height: 0;
border-top: 60px solid transparent;
border-bottom: 60px solid transparent;
border-left: 60px solid green;
}
</style>
<div class="arrow-right"></div>
Please try this
.box {
width: 200px;
padding: 10px;
background: green;
border-radius: 5px;
position: relative;
}
.box p {
margin: 0;
color: #fff;
}
.box::after {
position: absolute;
content: "";
border-style: solid;
border-width: 20px;
border-color: transparent transparent transparent green;
left: 100%;
top: 50%;
margin-top: -20px;
}
<div class="box">
<p>orem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque in fermentum risus. Donec malesuada, risus id vulputate varius, diam enim elementum sem.</p>
</div>
This question already has answers here:
CSS triangle custom border color
(5 answers)
Closed 8 years ago.
In my case i have something following this:
http://jsfiddle.net/pyx3zx25/12/
and the question is how can i add the border also to triangle.
My css:
.slide{
position: relative;
padding: 15px;
}
.arrow {
max-width: 300px;
background-color: #E01616;
position: absolute;
top: -10px;
left: -10px;
margin: 5px 0 0 5px;
border: 3px solid black;
}
.arrow:after {
left: 100%;
bottom: 0px;
content: "";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-width: 15px;
border-bottom: 30px solid #E01616;
border-right: 30px solid transparent;
}
Use the :before pseudo-element to create a like-for-like triangle with just a few adjustments, to make it seem like your :after element has a border:
.slide{
position: relative;
padding: 15px;
}
.arrow {
max-width: 300px;
background-color: #E01616;
position: absolute;
top: -10px;
left: -10px;
margin: 5px 0 0 5px;
border: 3px solid black;
}
.arrow:after {
left: 100%;
bottom: 0px;
content: "";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-width: 15px;
border-bottom: 30px solid #E01616;
border-right: 30px solid transparent;
}
.arrow:before {
left: 100%;
bottom: -3px;
content: "";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-width: 15px;
border-bottom: 37px solid #000;
border-right: 37px solid transparent;
}
<div class="slide">
<div class="arrow">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer scelerisque ex eget ultricies blandit.</p>
</div>
</div>
You can't use border because you use it already.
Try it.
UPDTATE
.arrow:before{
border-bottom: 40px solid #000;
border-right: 37px solid transparent;
border-width: 0 37px 40px 0;
bottom: 0;
content: "";
left: 100%;
position: absolute;
top: 55px;
}
jsfiddle - jsfiddle
HTML
<div class="slide">
<div class="arrow">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer scelerisque ex eget ultricies blandit.</p>
</div>
</div>
CSS
.slide{
position: relative;
padding: 15px;
}
.arrow {
max-width: 300px;
background-color: #E01616;
position: absolute;
top: -10px;
left: -10px;
margin: 5px 0 0 5px;
border: 3px solid black;
}
.arrow:after {
left: 100%;
bottom: 0px;
content: "";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-width: 15px;
border-bottom: 30px solid #E01616;
border-right: 30px solid transparent;
box-shadow: 0px 3px 0px 0px #000;
}
.arrow:before{
content: "";
right: -30px;
bottom: 0px;
height: 3px;
width: 30px;
position: absolute;
background: #000;
pointer-events: none;
transform: rotate(45deg) translate(-8px,-11px) scale(1.45);
}