How to place a triangle on my div to make it look like a speech bubble? - html

I created a simple div for my comments section.
I would like to give it the appearance of a speech bubble by having a triangle on the left or any other effect that would make it look like a speech bubble coming from the left.
How can I achieve that without using an image ?
image
html
<div class='comment'></div>
css
.comment {
margin-left: 10px;
height: 80px;
display: inline-block;
color: white;
width: 400px;
border: 1px solid white;
padding: 10px;
border-radius: 5px;
overflow: hidden;
}

Try this
.comment {
margin-left: 10px;
height: 80px;
display: inline-block;
color: white;
width: 400px;
border: 1px solid white;
padding: 10px;
border-radius: 5px;
position: relative;
background-color: #fff;
border:1px solid #000;
}
.comment::before{
content:"";
position: absolute;
top:20px;
left:-12px;
margin:auto;
height: 20px;
width: 20px;
border:1px solid #fff;
transform:rotate(45deg);
background-color: #fff;
border-bottom:1px solid #000;
border-left:1px solid #000;
}
<div class='comment'></div>
style accordingly,
hope this helps...

I hope to help you:
.comment {
position: relative;
margin-left: 50px;
margin-top: 50px;
height: 50px;
display: inline-block;
width: 200px;
padding: 10px;
border-radius: 5px;
background: skyblue;
color: #FFF;
}
.comment:before, .comment:after {
content: '';
border-radius: 100%;
position: absolute;
width: 50px;
height: 50px;
z-index: -1;
}
.comment:after {
background-color: #fff;
bottom: -30px;
left: 55px;
}
.comment:before {
background-color: skyblue;
bottom: -20px;
left: 70px;
}
<div class='comment'>Hello,World!</div>

I like Nicholas Gallagher's work best, see his demo page.
This is lifted off his page and is not my own work.
<style>
/* Bubble with an isoceles triangle
------------------------------------------ */
.triangle-isosceles {
position: relative;
padding: 15px;
margin: 1em 0 3em;
color: #000;
background: #f3961c;
border-radius: 10px;
background:linear-gradient(#f9d835, #f3961c);
}
/* creates triangle */
.triangle-isosceles:after {
content: "";
display: block; /* reduce the damage in FF3.0 */
position: absolute;
bottom: -15px;
left: 50px;
width: 0;
border-width: 15px 15px 0;
border-style: solid;
border-color: #f3961c transparent;
}
</style>
<p class="triangle-isosceles">This is a quote. Hello world. text goes here.</p>

Related

css - create a circle at the bottom right position of an element

I'm trying to come up with a system where I can easily place a small circle at the top left and bottom right of a container element - an element that will be dynamic in size using flex or grid etc.
I managed to get the top-left circle appearing in the right place (c-tl) but I can't figure out how to get the bottom-right circle appearing at the other end of the border line.
I've tried messing around with different display types on different elements (e.g. the blue circle) and ::after selectors on various elements (e.g. the orange circle)... I'm sure there's an easy way but I'm certainly not a css expert!
.container {
margin: 0;
padding: 2rem;
}
.ele {
padding: 2rem;
border-bottom-left-radius: 1rem;
border-left: solid 1px grey;
border-bottom: solid 1px grey;
}
.c-tl {
height: 10px;
width: 10px;
border-radius:5px;
background-color: grey;
display: block;
position: relative;
top: 5px;
left: -5px;
}
.c-br {
height: 10px;
width: 10px;
border-radius:5px;
background-color: orange;
display: block;
}
.ele::after{
content: "";
height: 10px;
width: 10px;
border-radius:5px;
background-color: blue;
display: block;
}
<div class="container">
<span class="c-tl"></span>
<div class="ele">
<p>Hello, world!</p>
</div>
<span class="c-br"></span>
</div>
You can use position: absolute; with bottom: 0; and right: 0; to position the desired element on the bottom right corner of its parent element which must have position: relative;.
In your case:
the .c-tl and .c-br must be placed in .ele (the element relative which the circles are placed)
add position: relative; to .ele
add position: absolute; to both .c-tl and .c-br, and their corresponding top/bottom & left/right values set.
Reference (last example)
.container {
margin: 0;
padding: 2rem;
}
.ele {
padding: 2rem;
border-bottom-left-radius: 1rem;
border-left: solid 1px grey;
border-bottom: solid 1px grey;
position: relative;
}
.c-tl {
height: 10px;
width: 10px;
border-radius:5px;
background-color: grey;
display: block;
position: absolute;
top: -5px;
left: -5px;
}
.c-br {
height: 10px;
width: 10px;
border-radius:5px;
background-color: orange;
display: block;
position: absolute;
bottom: -5px;
right: -5px;
}
.ele::after{
content: "";
height: 10px;
width: 10px;
border-radius:5px;
background-color: blue;
display: block;
}
<div class="container">
<div class="ele">
<span class="c-tl"></span>
<p>Hello, world!</p>
<span class="c-br"></span>
</div>
</div>
I added the following to your c-br class.
float: right;
position: relative;
top: -5px;
right: -5px;
It seems to work in both views, including full screen.
.container {
margin: 0;
padding: 2rem;
}
.ele {
padding: 2rem;
border-bottom-left-radius: 1rem;
border-left: solid 1px grey;
border-bottom: solid 1px grey;
}
.c-tl {
height: 10px;
width: 10px;
border-radius: 5px;
background-color: grey;
display: block;
position: relative;
top: 5px;
left: -5px;
}
.c-br {
height: 10px;
width: 10px;
border-radius: 5px;
background-color: orange;
display: block;
float: right;
position: relative;
top: -5px;
right: -5px;
}
.ele::after {
content: "";
height: 10px;
width: 10px;
border-radius: 5px;
background-color: blue;
display: block;
}
<div class="container">
<span class="c-tl"></span>
<div class="ele">
<p>Hello, world!</p>
</div>
<span class="c-br"></span>
</div>

how to apply rounded border to only left side of element

I want to achieve this
But using this css
border-left: 3px solid red;
border-radius: 3px;
It is producing this result
plz ignore spacing, i will add that
I would recommend using pseudo-classes in order to create your red bar. Try this:
span {
font-family: Arial;
font-size: 3em;
}
span::before {
content: "";
display: inline-block;
margin-right: 10px;
width: 10px;
height: 40px;
border-radius: 50px;
background-color: red;
}
<span>2.1 Cr</span>
Use border-top-left-radius and border-bottom-left-radius
.div{
margin-top:40px;
width:50px;
height:10px;
border-radius:50px;
background:red;
transform:rotateZ(90deg);
}
<div class="div"></div>
Edited:
try this
Fiddle file:
https://jsfiddle.net/swuzqpbt/
htmlelement {
position: relative;
height: 40px;
border: none;
margin: 20px auto;;
}
htmlelement ::before {
content: '';
display: inline-block;
background: red;
width: 5px;
height: 40px;
top: 0;
left: 0;
border-radius: 140px;
position: absolute;
border:none;
}

How to have an icon on the edge of a button?

I have a button that is supposed to show the tick icon on the top-right edge of the button, upon selected. Placing the tick icon partially over the button and partially out of the button seems to be a challenge. I was wondering if you can help me with this.
You can make top right circle with before element
button {
width: 100px;
height: 50px;
position: relative;
border-radius: 5px;
background-color: white;
border: 1px solid blue;
transform: translate(3rem, 3rem);
}
button:before {
content: attr(data);
width: 20px;
height: 20px;
border-radius: 50%;
background: skyblue;
border: 1px solid blue;
position: absolute;
top: -10px;
right:-10px;
display: flex;
justify-content: center;
align-items: center;
}
<button data="&check;" class="badge-top-right">Button</button>
HTML
<button data="i" class="badge-top-right">Button</button>
CSS
button {
background-color: white;
width: 100px;
height: 40px;
border-radius: 5px;
border: 1px solid grey;
margin-top: 40px;
margin-left: 40px;
position: relative;
}
button:before {
content: attr(data);
width: 20px;
height: 20px;
line-height: 20px . ;
border-radius: 50%;
background: white;
border:1px solid grey;
color: black;
position: absolute;
top: -10px;
left: -10px;
right:-10px;
left:auto;
}
You can see the result here:
https://stackblitz.com/edit/angular-pjfn6t

How can I increase the angle of an intersection?

I'm trying to create an envelope icon in HTML/CSS but I can't seem to get this part right.
Image 1
As you can see, the corners don't quite line up correctly with the diagonal lines and I don't really know how to open the angle a little more. This is what I've written :
CSS
.enveloppe {
overflow: hidden;
position: relative;
width: 14px; height: 11px;
border-radius: 3px;
margin-right: 6px;
background: white;
display: inline-block;
}
.enveloppe-plie{
position: absolute;
width: 14px;
height: 5px;
top: 3pt;
content: "";
display: inline-block;
border-right: 1px solid #333333;
border-top: 1px solid #333333;
transform: rotate(135deg);
vertical-align: top;
margin-top: -10px;
margin-left: -5px;
}
HTML
<div class="enveloppe">
<div class="enveloppe-plie"></div>
</div>
Replace margin-left: -5px; with margin-left: 3px; and it looks a bit better
This will make a white envelope. Use this link to learn to make triangles using CSS https://css-tricks.com/snippets/css/css-triangle/
CSS
.envelope {
background-color: white;
border-radius: 4px;
height: 64px;
width: 96px;
overflow: hidden;
position: relative;
}
.envelope-fold1, .envelope-fold2 {
border-right: 48px solid transparent;
border-left: 48px solid transparent;
margin: auto;
position: absolute;
top: 0;
right: 0;
left: 0;
}
.envelope-fold1 {
border-top: 48px solid black;
}
.envelope-fold2 {
border-top: 44px solid white;
}
HTML
<div class="envelope">
<div class="envelope-fold1"></div>
<div class="envelope-fold2"></div>
</div>

How to make an arrow next to a pseudo:hover::before element

This is my code
.privacycheck1 {
position: relative;
top: 265px;
background-color: #CF0000;
width: 24px;
height: 24px;
left: 843px;
border-radius: 50px;
border: 5px #E60000;
}
.privacycheck1::before {
position: relative;
display: block;
height: 20px;
width: 200px;
left: 30px;
}
.privacycheck1:hover::before {
content: 'This information is private';
width: 125px;
height: 35px;
background-color: #CF0000;
left: 40px;
top: -10px;
font-family: arial;
font-size: 15px;
font-weight: 100px;
color: white;
padding: 10px;
}
<div class="privacycheck1"></div>
I want to make it so when someone hovers over the privacycheck1, I want them to see an arrow connecting to the box pointing at privacycheck1's circle.
Is there anyway to make a class in a class?
You can use an extra span element to create this.
First create the tail of the arrow using the span and then create the arrow head using the border-hack on the after pseudo-element. You can find a wide range of arrows here
.privacycheck1 {
position: relative;
top: 30px;
background-color: #CF0000;
width: 24px;
height: 24px;
left: 30px;
border-radius: 50px;
border: 5px #E60000;
}
.privacycheck1::before {
position: relative;
display: block;
height: 20px;
width: 200px;
left: 30px;
}
.privacycheck1:hover::before {
content: 'This information is private';
width: 125px;
height: 30px;
background-color: #CF0000;
left: 40px;
top: -10px;
font-family: arial;
font-size: 15px;
font-weight: 100px;
color: white;
padding: 10px;
}
.arrow {
position: absolute;
width: 15px;
height: 5px;
background: green;
left: 20px;
top: 8px;
display:none;
}
.arrow:after {
position: absolute;
content: "";
width: 0;
height: 0;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-left: 5px solid green;
left:15px;
top:-2px;
display:none;
}
.privacycheck1:hover span,.privacycheck1:hover span:after{
display:block;
}
<div class="privacycheck1"><span class="arrow"></span>
</div>
You don't need an extra span. You can use an :after just like you used a :before.
.privacycheck1:after {
content: "";
display: block;
position: absolute;
top: 50%;
left: 100%;
width: 0;
height: 0;
margin-top: -15px;
border-top: 15px solid transparent;
border-bottom: 15px solid transparent;
border-right: 15px solid #CF0000;
}
If you use top: 50%; and margin-top negative half the arrow height it will always be perfectly aligned in the vertical center. In this case I gave the arrow height: 30px; so the margin-top is -15px
Oh and you made a mistake in you hover:before. 'font-weight: 100px;' doesn't exist, you can use 'bold', '700' or another value.
Another tip, add this to your hover:before
left: calc(100% + 15px);
This way your box will always have the right distance between the 'dot' and the text box. The box will use the width of the parent (the element with position: relative;) + 15px (the width of the arrow) to align from the left.