How to place curved arrow on top of your speech bubble? [duplicate] - html

This question already has an answer here:
How to create a curved speech bubble?
(1 answer)
Closed 2 years ago.
I want to create a speech bubble similar to the following image using css.
How would I go about doing this?

You can use a radial-gradient with a transparant circle to create the curved tip of the speech bubble. Apply it to the ::before pseudo element of your bubble so it gets placed on top of your speech bubble div.
.bubble::before {
content: '';
height: 30px;
width: 30px;
background: radial-gradient(circle at 100% 0, transparent 30px, cornflowerblue 0);
display: block;
margin-left: 100px;
}
.message {
padding: 10px 20px;
width: 300px;
background: cornflowerblue;
display: block;
font-family: sans-serif;
color: floralwhite;
font-size: 18px;
border-radius: 0 0 10px 10px;
}
<div class="bubble">
<div class="message">
<p>"Tell me and I forget. Teach me and I remember. Involve me and I learn."<p>
<small>Benjamin Franklin</small>
</div>
</div>
Add border on hover
You can use the ::after pseudo element in combination with z-index to create a border effect when hovering over the speech bubble.
.bubble::before,
.bubble::after {
content: '';
display: block;
position: absolute;
}
.bubble::before {
background: radial-gradient(circle at 95% -2px, transparent 25px, cornflowerblue 0);
left: 103px;
top: 10px;
z-index: 1;
height: 25px;
width: 25px;
}
.bubble::after {
background: radial-gradient(circle at 100% 0, transparent 30px, coral 0);
left: 100px;
top: 0px;
z-index: -1;
height: 30px;
width: 30px;
display: none;
}
.message {
padding: 10px 20px;
width: 300px;
background: cornflowerblue;
display: block;
font-family: sans-serif;
color: floralwhite;
font-size: 18px;
border-radius: 0 0 10px 10px;
border: 3px solid white;
margin-top: 30px;
}
.bubble:hover > .message {
border: 3px solid coral;
}
.bubble:hover::after {
display: block;
}
<div class="bubble">
<div class="message">
<p>"Tell me and I forget. Teach me and I remember. Involve me and I learn."<p>
<small>Benjamin Franklin</small>
</div>
</div>

Related

Can you put 2 circles inside of one Button [duplicate]

This question already has answers here:
Circle with two borders
(4 answers)
Closed 7 months ago.
I want to make a 1€ coin with CSS but I have the problem that I can't give it it's characteristic shape consisting of two circles. I don't want to use multiple divs for making the two circles because I want to have it as a Button. Is there any way to put 2 different shapes in one button tag or are you forced to use divs?
Here is my failed attempt at trying to do so:
.btnCircle1 {
height: 50px;
width: 50px;
border-radius: 50%;
background: red;
z-index: 100;
}
.btnCircle2 {
height: 100px;
width: 100px;
border-radius: 50%;
background: blue;
z-index: 1;
}
<button type="button" class="btnCircle1 btnCircle2"></button>
.btnCircle {
/* here just change one value, to change the other automatically */
/* for example you can use a responsive unit (that change often) like `vw` and the other element will automatically changed automatically */
--bigCirle-Height: 100px;
height: var(--bigCirle-Height);
width: var(--bigCirle-Height);
/* is always a perfect circle */
border-radius: var(--bigCirle-Height);
border: none; /* Remove default borders */
/* add this to make the ::before works */
position: relative;
}
.btnCircle::before {
/* change this value 1 means bigger, the smaller is the number (for example 0.7) the yellow circle is smaller */
/* using css variables and calculations the money it will be always responsive to the parent height */
--smallCirle-Height: calc(var(--bigCirle-Height) * 0.7);
content: '1€';
height: var(--smallCirle-Height);
width: var(--smallCirle-Height);
border-radius: var(--smallCirle-Height);
background: yellow;
/* this two lines will center the circle */
/* inset is like writing top: 50%, left: 50% */
inset: 50%;
transform: translate(-50%, -50%);
/* center the text inside circle */
display: grid;
place-content: center;
/* positioning absolutely */
position: absolute;
}
<button type="button" class="btnCircle"></button>
as A Haworth mentioned you, one way is using the before/after pseudo elements
here's an example:
.btnCircle {
position: relative;
border: none;
padding: 45px;
border-radius: 50%;
background: red;
}
.btnCircle::after {
position: absolute;
inset: 10px;
content: '';
background: blue;
border-radius: 50%;
}
<button class="btnCircle"></button>
One you can use background and border.
/*With background and border css start*/
.btnCircle1 {
position: relative;
background: transparent;
border: none;
z-index: 99;
line-height: 50px;
text-align: center;
width: 85px;
color: white;
background-color: blue;
border: 15px solid red;
border-radius: 100%;
}
/*With background and border css end*/
/*With pesudo element css start*/
.btnCircle1-psd {
position: relative;
background: transparent;
border: none;
z-index: 99;
line-height: 50px;
text-align: center;
width: 50px;
color: white;
}
.btnCircle1-psd::before,
.btnCircle1-psd::after {
content: "";
position: absolute;
top: 0;
left: 0;
display: inline-block;
height: 50px;
width: 50px;
border-radius: 50%;
background: red;
z-index: -1;
}
.btnCircle1-psd::after {
transform: scale(0.8);
background-color: blue;
}
/*With pesudo element css end*/
/*With radial gradient background color start*/
.btnCircle1-bg {
position: relative;
background: transparent;
border: none;
z-index: 99;
line-height: 50px;
text-align: center;
height: 85px;
width: 85px;
color: white;
border-radius: 100%;
background: rgb(255, 0, 0);
background: radial-gradient(circle, rgba(255, 0, 0, 1) 50%, rgba(0, 160, 255, 1) 50%);
}
/*With radial gradient background color end*/
/*With box inset shadow color start*/
.btnCircle1-shadow {
position: relative;
background: red;
border: none;
z-index: 99;
line-height: 50px;
text-align: center;
height: 85px;
width: 85px;
color: white;
border-radius: 100%;
-webkit-box-shadow: inset 0px 0px 0px 10px blue;
box-shadow: inset 0px 0px 0px 10px blue;
}
/*With box inset shadow color end*/
<h1> With background and border</h1>
<button type="button" class="btnCircle1">1$</button>
<h1> With radial gradient background color</h1>
<button type="button" class="btnCircle1-bg">1$</button>
<h1> With box inset shadow color</h1>
<button type="button" class="btnCircle1-shadow">1$</button>
<h1>With pesudo element <strong>before</strong> and <strong>after</strong>.</h1>
<button type="button" class="btnCircle1-psd">1$</button>

How to make an input text field like the one on the Tesla Cybertruck order website?

I want to make an input text field, like the one on https://www.tesla.com/en_gb/cybertruck/design#battery (it appears after clicking 'buy now') but I am unsure how to approach this.
I have tried adding border-radius but of course that only rounds the corners.
Below is my current code:
<style>
body {
background-color: black;
}
label {
color: white;
}
input {
width: 300px;
height: 40px;
border: solid white 1px;
background: transparent;
color: white;
font-family: 'Consolas';
font-size: 0.9em;
font-weight: bold;
padding: 10px 10px 10px 10px;
transition: border 0.3s ease-in-out;
box-sizing: border-box;
outline-width: 0;
border-radius: 10px 10px 10px 10px;
border-style: none;
border-width: 0 0 3px;
padding: 3px 10px;
}
input:focus {
border: solid white 3.5px;
}
</style>
<label>Test field</label>
<br>
<input type = "text">
I would like this to be responsive if possible, thanks in advance.
They are using clip-path and polygon to do this. See this page for details: https://css-tricks.com/notched-boxes/
As already mentioned, by looking at the source you can see that it's a clip path.
In particular the clip path is applied to a wrapper div as ::before pseudo element as opposed to on the input element. Here's a simple example using the exact same clip path on the website.
body,
html {
padding: 0;
margin: 0;
background-color: #333;
display: flex;
justify-content: center;
align-items: center;
height: 100%;
}
.wrapper {
width: 200px;
height: 40px;
position: relative;
display: block;
}
.wrapper::before {
content: "";
display: block;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: blue;
clip-path: polygon(0px 0px, 100% 0px, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0px 100%, 0px 1.5px, 1.5px 1.5px, 1.5px calc(100% - 1.5px), calc(100% - 11.5px) calc(100% - 1.5px), calc(100% - 1.5px) calc(100% - 11.5px), calc(100% - 1.5px) 1.5px, 0px 1.5px);
}
input {
background: transparent;
border-color: transparent;
border-radius: 0;
color: white;
width : 100%;
height: 100%;
outline: none;
}
<div class="wrapper">
<input type="text" />
</div>
The clip path is kind of too complicated to explain bit-by-bit, but it essentially cuts out the middle of a solid rectangle as well as a little corner. So in this case, the background color is what controls the "border color". In order to animate on hover, it probably changes some elements of the clipping path if I were to guess.

box-shadow on angled border :after pseudoelement

So, I've searched for a solution to this, and have had no luck. I need the box-shadow on the parent div to carry through the :after pseudo element.
Currently, the box shadow is still applying like a rectangle instead of following the edge of the border, which renders the angle at the end of the div. You can see what I'm talking about here:
https://codepen.io/thomasjost/pen/XBOjqm
Here's my HTML:
<div class="total-tag">
<h3 class="h-big-dollar-sign">$</h3>
<h1 class="total">13,550</h1>
</div>
SCSS:
.total-tag {
border-radius : 6px 0 0 6px;
background : #EBEDEE;
height : 68px;
width : 15em;
position : relative;
box-shadow: 0 1px 2px 0 rgb(0,0,0);
display: flex;
justify-content: flex-start;
align-content: center;
align-items: center;
&:after {
content : '';
display : block;
position : absolute;
top : 0;
left : 15em;
border-style : solid;
border-color : #EBEDEE transparent transparent transparent;
border-width : 68px 34px 0 0;
box-shadow: 1px 1px 2px 0 rgb(0,0,0);
}
}
.total {
font-size: 38px;
font-weight: 300;
color: #64A31B;
line-height: 1em;
margin-top: 5px;
}
.h-big-dollar-sign {
position: relative;
left: inherit;
top: inherit;
margin-top: 5px;
margin-left: 17px;
font-size: 24px;
}
Any assistance would be greatly appreciated.
you could play with a gradient background to draw bg and simulate the shadow:
&:after {
content : '';
display : block;
position : absolute;
top : 0;
left : calc(15em - 2px);/* minus shadow's width */
bottom : 0;
width :36px;
background: linear-gradient(to bottom right, #EBEDEE 49%, #000 50%, transparent calc(50% + 2px) );/* draw bg and part of slanted shadow */
box-shadow:0px -2px 2px -3px;/* top shadow is to be shawn too, give it a try */
}
DEMO:
.total-tag {
border-radius: 6px 0 0 6px;
background: #EBEDEE;
height: 68px;
width: 15em;
position: relative;
box-shadow: 0 1px 2px 0 black;
display: flex;
justify-content: flex-start;
align-content: center;
align-items: center;
}
.total-tag:after {
content: '';
display: block;
position: absolute;
top: 0;
left: calc(15em - 2px);
bottom: 0;
width: 36px;
background: linear-gradient(to bottom right, #EBEDEE 49%, #000 50%, transparent calc(50% + 2px));
box-shadow: 0px -2px 2px -3px;
}
.total {
font-size: 38px;
font-weight: 300;
color: #64A31B;
line-height: 1em;
margin-top: 5px;
}
.h-big-dollar-sign {
position: relative;
left: inherit;
top: inherit;
margin-top: 5px;
margin-left: 17px;
font-size: 24px;
}
<div class="total-tag">
<h3 class="h-big-dollar-sign">$</h3>
<h1 class="total">13,550</h1>
</div>

Transparent trapezoidal buttons with border and centered text

I'm designing a site where trapezoids are crucial. I'm using the following code to achieve the effect I'm looking for, but am having issues with it: http://jsfiddle.net/9n9uh6f6/9/
The biggest problems are the mouseover area (because I'm using perspective transforms, the clickable area is skewed) and centering text within the shape.
Other than using perspective transforms, how can I make a shape that does the following:
Trapezoid with a colored border and transparent interior.
Trapezoid that can change color when a user hovers over it.
Trapezoid that houses text in the center of the shape.
Here's the CSS I'm using:
.prodcaptions {
width:136px;
height: 85px;
position:relative;
left:10%;
text-transform:uppercase;
text-align:center;
letter-spacing: 1.6px;
color: #000;
}
.prodcaptions:before {
content:"";
position:absolute;
border-radius:1px;
box-shadow:0 0 0 3px #27628e;
top:-5%;
bottom:-11%;
left:-1%;
right:-5%;
-webkit-transform:perspective(40em) rotateX(-45deg);
transform:perspective(40em) rotateX(-45deg);
}
.prodcaptions a {
z-index:999;
position:relative;
height: 85px;
display: block;
padding-top: 25px;
}
For this case, it would be better to use a skew transform to produce the shape than a rotation with perspective.
We can achieve the shape by using two pseudo-elements skewed in opposite directions and then position one at the left corner and the other at the right corner. Since only the pseudo-elements are skewed and not the main container, the text remains in its expected place (at center-middle).
This shape can (a) support dynamic width (b) have a colored border with transparent background (c) have the text in the center of the shape and (d) support change of background color when hovered on.
.trapezoid {
display: inline-block;
position: relative;
height: 100px;
width: auto;
color: #27628e;
border-top: 2px solid #27628e;
border-bottom: 2px solid #27628e;
line-height: 100px;
text-align: center;
white-space: nowrap;
text-transform: uppercase;
letter-spacing: 1.6px;
margin: 15px 250px; /* Just for demo */
}
.trapezoid:after,
.trapezoid:before {
position: absolute;
content: '';
top: -2px;
height: 100%;
width: 50%;
z-index: -1;
}
.trapezoid:before {
left: 0px;
border-left: 2px solid #27628e;
border-top: 2px solid #27628e;
transform-origin: left bottom;
transform: skew(10deg);
}
.trapezoid:after {
right: 0px;
border-right: 2px solid #27628e;
border-top: 2px solid #27628e;
transform-origin: right bottom;
transform: skew(-10deg);
}
.trapezoid:hover,
.trapezoid:hover:after,
.trapezoid:hover:before {
background: #27628e;
color: white;
}
/* Just for demo */
body {
background: linear-gradient(90deg, aliceblue, powderblue);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
Click Me!!!
You could also create the same shape using SVG and the angled sides look a tad more smoother while using SVG. The below snippet currently works only for a fixed size container. It should not be an issue as the code in question also has fixed dimensions.
.vector {
position: relative;
height: 100px;
width: -webkit-calc(100px * 1.36);
width: calc(100px * 1.36);
line-height: 100px;
margin: 0px auto; /* Just for demo */
}
svg {
height: 100%;
width: 100%:
}
polygon {
fill: transparent;
stroke-width: 2;
stroke: steelblue;
}
.vector a {
position: absolute;
display: block;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
text-decoration: none;
text-transform: uppercase;
letter-spacing: 1.6px;
color: steelblue;
text-align: center;
white-space: nowrap;
}
.vector:hover polygon {
fill: steelblue;
}
.vector:hover a {
color: white;
}
/* Just for demo */
body{
background: linear-gradient(90deg, aliceblue, powderblue);
}
<div class='vector'>
<svg viewBox='0 0 136 100' preserveaspectratio='none'>
<polygon points='1,2 18,98 118,98 135,2' />
</svg>
<a href='#'>Click Me!!!</a>
</div>

Positioning Text Inside a Triangle CSS

So assuming I have the below triangle. Without adding any html or tags how could I go about positioning the text into the center of the triangle?
Fiddle: http://jsfiddle.net/3LXaD/
You will notice the white text in the top right corner of the triangle. I understand a triangle is a large border around the shape. Is this even possible?
CSS
div:nth-of-type(1) {
width: 0;
height: 0;
border-style: solid;
border-width: 0 150px 130px 150px;
border-color: transparent transparent #d30000 transparent;
line-height: 0px;
_border-color: #000000 #000000 #d30000 #000000;
_filter: progid:DXImageTransform.Microsoft.Chroma(color='#000000');
}
div {
font-size: 16px;
color: #FFFFFF;
text-align: center;
}
HTML
<div>This is a triangle</div>
Without extra markup try this:
div:nth-of-type(1):before {
content: '';
width: 0;
height: 0;
border-style: solid;
border-width: 0 150px 130px 150px;
border-color: transparent transparent #d30000 transparent;
line-height: 0px;
_border-color: #000000 #000000 #d30000 #000000;
_filter: progid:DXImageTransform.Microsoft.Chroma(color='#000000');
position: absolute;
top: 0;
z-index: -1;
left: 50%;
margin-left: -150px;
}
div {
font-size: 16px;
color: #ffffff;
text-align: center;
line-height: 130px;
position: relative;
}
Here is an example.
Ciao
Ralf
Wrap the text in the span and position it absolutely:
JSfiddle
span{
position: absolute;
top: 80px;
left: 33%;
}
<div><span>This is a triangle</span></div>
Here would be the solution if you were to use a pseuedo element. (not best practice)
div:after{
content: 'This is a triangle';
color: white;
position: absolute;
top: 80px;
left: 33%;
}