I have this design from a client with two layers of gradients in a button. The tricky thing is, one of the layers has a curved edge. I've mocked up the button so you have a sense of what I'm saying, hopefully.
What I managed to do is a straight edge (see code snippet, color difference is not important, just need the curve). Does anyone have done this before? Or does it have to be a background image? Thanks!
P.S. I also thought about using radial gradient on a pseudo element and absolute position it, but couldn't get the exact straight edge look like the linear gradient.
a {
background-image: linear-gradient(-155deg,rgba(74,148,214,.4) 45%,rgba(255,255,255,.08) 15%),linear-gradient(258deg,rgba(87,238,255,.1),rgba(77,108,211,.2));
background-color: rgba(74,148,214,.9);
color: #fff;
width: 200px;
height: 40px;
border-radius: 10px;
margin-top: 50px;
display: block;
text-align: center;
line-height: 40px;
}
<a>
Some button
</a>
You can get pretty close by using a radial-gradient instead of linear:
a {
background-image:
radial-gradient(ellipse farthest-corner at 0 140%, #3c84cc 0%, #316dc2 70%, #4e95d3 70%);
color: white;
width: 200px;
height: 50px;
border-radius: 10px;
margin-top: 50px;
display: block;
text-align: center;
line-height: 50px;
}
<a>
Some button
</a>
You can use a pseudo element to draw the curve using a circle, then just use whatever gradient you want as the background(s)
a {
background-color: lightblue;
color: #fff;
width: 200px;
height: 40px;
border-radius: 10px;
margin-top: 50px;
display: block;
text-align: center;
line-height: 40px;
position: relative;
z-index: 1;
overflow: hidden;
}
a:after {
content: '';
position: absolute;
background-color: blue;
width: 600px;
height: 200px;
border-radius: 50%;
top: 0;
left: 0;
transform: translate(-49%,0);
z-index: -1;
}
<a>
Some button
</a>
I just modified a bit #Blazemonger's post.
I fixed the position of the curved line.
a {
background-image: radial-gradient(ellipse farthest-corner at -10% 250%, #3c84cc 0%, #315dc2 80%, #4e95d3 80%);
color: white;
width: 200px;
height: 50px;
border-radius: 10px;
margin-top: 50px;
display: block;
text-align: center;
line-height: 50px;
}
<a>Some button</a>
Related
I am trying to achieve radius in a single. Well let me show what I am trying and what I want:
.bar{
height: 20px;
border-radius: 2.5rem;
background: linear-gradient(to right, green 0%, green 50%,gray 50%,gray 100%);
}
<div class='bar'></div>
With this code I am getting the sharp right side with green color. I want a rounded right side where the green color ends. something like :
You can see the smooth round green end
You can achieve it with the help of ::after pseudo-element
.bar{
height: 20px;
border-radius: 2.5rem;
background: gray;
position: relative;
}
.bar::after{
content: "";
position: absolute;
top:0;
left:0;
width: 50%;
height: 20px;
border-radius: 2.5rem;
background: green;
}
<div class="bar"></div>
Since you're using a gradient, you won't achieve that.
Here you have two possible options:
1 - use a pseudo element
.bar {
height: 20px;
border-radius: 2.5rem;
background: linear-gradient(to right, green 0%, green 50%,gray 50%,gray 100%);
position: relative;
}
.bar::after {
content: ' ';
position: absolute;
left: 50%;
margin-left: -10px;
height: 20px;
width: 20px;
border-radius: 2.5rem;
background-color: green;
}
<div class='bar'></div>
2 - use two elements
.bar {
height: 20px;
border-radius: 2.5rem;
background: gray;
position: relative;
}
.progress {
width: 50%;
height: 100%;
border-radius: 2.5rem;
background-color: green;
}
<div class='bar'>
<div class='progress'></div>
</div>
If you want to use gradient do it like below:
.bar{
--p: 50%;
height: 20px;
border-radius: 2.5rem;
margin: 10px;
background:
radial-gradient(circle closest-side at var(--p) 50%,green 98%,#0000),
linear-gradient(green 0 0) left/var(--p) 100% no-repeat
#ddd;
}
<div class='bar'></div>
<div class='bar' style="--p: 40%"></div>
<div class='bar' style="--p: 80%"></div>
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>
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>
I have a some text on image, but the problem is i am using opacity so that text gets highlighted but it makes images look very dull.
Here is Updated Fiddle Link
Html
<div class="subcontainer">
<img src="http://i58.tinypic.com/11kbnlf.png" alt="">
<h3 class="header3">Motivate Yourself</h3>
</div>
CSS
.subcontainer {
width: 100%;
height: 100%;
float: left;
position: relative;
border: 3px solid white;
}
.imgcolumn {
background-repeat: no-repeat;
float: left;
width: 60%;
height: 80%;
margin-left: 130px;
margin-top: 45px;
position: absolute;
opacity: 0.4;
filter: alpha(opacity=40);
}
.header3 {
z-index: 100;
position: absolute;
float:right;
color: black;
font-size: 25px;
margin-top: 175px;
text-align: center;
margin-left: 170px;
}
Is there any other way i can highlight text by keeping image as it is.
Note : I am trying to achieve something like this PAGE and i don't see image being blurred or having opacity.
use this fiddle
eg:
.header3 {
z-index: 100;
position: absolute;
float:right;
color: black;
font-size: 25px;
text-align: center;
position:absolute;
width:80%;
height:45%;
background-color:rgba(0,0,0,0.4);
top:20px;
left:24px;
line-height:150px;
}
You could also set the background-image of the parent container then lay another element over top of it with a semi-transparent background color as I have done here. Then, the highlight can be controlled via the opacity of the BACKGROUND of the overlay layer without affecting the text opacity.
http://jsfiddle.net/xDaevax/8Mzh9/
.subcontainer {
border: 3px solid white;
margin: 0px auto;
background: url("http://i61.tinypic.com/2ur6rk1.png") no-repeat center top;
height: 225px;
}
.imgcolumn {
width: 60%;
display: table;
height: 100%;
margin: 0px auto;
border: solid 1px #000000;
background-color: rgba(255, 255, 255, .6);
}
.header3 {
color: black;
font-size: 25px;
text-align: center;
position: relative;
top: -120px;
}
HTML
<div class="subcontainer">
<h3 class="header3">Motivate Yourself</h3>
</div>
The page you gave as an example uses contrasting colors for text and image. For example, that page uses dark images and the text on them is pure white.
If you want the text to stand out, use contrasting colors, or else use a contrasting drop shadow/outer glow (made with image editing software like PhotoShop), or add a semi-transparent background like this: http://jsfiddle.net/P22Cg/
.header3 {
z-index: 100;
position: absolute;
float:right;
color: black;
font-size: 25px;
margin-top: 175px;
text-align: center;
margin-left: 170px;
background-color: rgba(255, 255, 255, 0.5); /* I added this... */
padding: 5px; /* ... and this */
}
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%;
}