Possible to use border-radius together with a border-image which has a gradient?
Probably not possible, as per the W3C spec:
A box's backgrounds, but not its
border-image, are clipped to the
appropriate curve (as determined by
‘background-clip’). Other effects that
clip to the border or padding edge
(such as ‘overflow’ other than
‘visible’) also must clip to the
curve. The content of replaced
elements is always trimmed to the
content edge curve. Also, the area
outside the curve of the border edge
does not accept mouse events on behalf
of the element.
This is likely because border-image
can take some potentially complicated patterns. If you want a rounded, image border, you'll need to create one yourself.
Border Gradient with Border Radius
2021: I recommend using the CSS mask method since the support is pretty good now
You cannot use border-radius
with gradient. Here is another idea where you can rely on multiple background and adjust the background-clip
:
.white-grad {
background:
linear-gradient(#ccc 0 0) padding-box, /*this is your grey background*/
linear-gradient(to right, #9c20aa, #fb3570) border-box;
color: #313149;
padding: 10px;
border: 5px solid transparent;
border-radius: 15px;
display: inline-block;
margin: 75px 0;
}
<div class="white-grad"> Some text here</div>
<div class="white-grad"> Some long long long text here</div>
<div class="white-grad"> Some long long <br>long text here</div>
border-radius with border-image
It is not possible to combine them. The W3 Spec says:
A box's backgrounds, but not its border-image, are clipped to the appropriate curve (as determined by ‘background-clip’). Other effects that clip to the border or padding edge (such as ‘overflow’ other than ‘visible’) also must clip to the curve. The content of replaced elements is always trimmed to the content edge curve. Also, the area outside the curve of the border edge does not accept mouse events on behalf of the element.
However, you can achieve the same effect by using a css gradient
#cont{ background: -webkit-linear-gradient(left top, crimson 0%, blue 100%); width: 300px; height: 300px; border-radius: 1000px; padding: 10px;}
#box{ background: white; width: 300px; height: 300px; border-radius: 1000px;}
<div id="cont"> <div id="box"></div></div>
Gradient border with border radius and gradient text
I will consider this previous answer to build the rounded gradient using pseudo element so that you can use background-clip:text
on the main element. I have used the mask version by you can also consider the SVG one:
.btn {
--r:40px; /* radius */
--b:5px; /* border width */
background: linear-gradient(to right, #006175 0%, #00a950 100%);
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
color: transparent;
border-radius: var(--r);
display: flex;
align-items: center;
justify-content: center;
font: 1.5rem 'Oswald', Arial, sans-serif;
height: 80px;
margin: 0 auto;
position: relative;
z-index:0;
text-decoration: none;
width: 264px;
}
/* check lined question for the detail of the below code */
.btn::before {
content:"";
position:absolute;
z-index:-1;
inset: 0;
border: var(--b) solid transparent;
border-radius: var(--r);
background: inherit;
background-origin: border-box;
background-clip: border-box;
-webkit-mask:
linear-gradient(#fff 0 0) padding-box,
linear-gradient(#fff 0 0);
-webkit-mask-composite: xor;
mask-composite: exclude;
-webkit-mask-repeat: no-repeat;
}
/**/
.btn:hover {
color: #fff;
-webkit-text-fill-color: #fff;
-webkit-background-clip: border-box;
background-clip: border-box;
}
.btn:hover::before {
-webkit-mask:none;
}
body {
background:pink;
}
<a class="btn" href="#">
Click Here!
</a>
Round border with gradient color
This can be achieved with CSS using a pseudo class like :before
.
Sadly, it doesnt have the transparent part between the border and the circle itself but if you know its always going to be on a certain colored background, that shouldn't be a problem.
.luna-icon-wrap{ float: right; padding: 1px 1px; -webkit-border-radius: 50% 50%; -moz-border-radius: 50% 50%; border-radius: 50% 50%; border: 2px solid transparent; position: relative;} .luna-icon-wrap:before {content: ''; position: absolute; top: -2px; bottom: -2px; left: -2px; right: -2px; border-radius: 50%; background: linear-gradient(135deg, #1e5799 0%,#7db9e8 100%); z-index: -2;}
.luna-featbox2-icon{ width: 70px; height: 70px; text-align: center; -webkit-border-radius: 50% 50%; -moz-border-radius: 50% 50%; border-radius: 50% 50%; border: 4px solid white; background: #43257f; /* For browsers that do not support gradients */ background: -webkit-linear-gradient(left top, #43257f, #40c4ff); /* For Safari 5.1 to 6.0 */ background: -o-linear-gradient(bottom right, #43257f, #40c4ff); /* For Opera 11.1 to 12.0 */ background: -moz-linear-gradient(bottom right, #43257f, #40c4ff); /* For Firefox 3.6 to 15 */ background: linear-gradient(to bottom right, #43257f, #40c4ff); /* Standard syntax */}
<div class="luna-icon-wrap"> <div class="luna-featbox2-icon"> <i class="fa fa-diamond"></i> </div></div>
achieving rounded corners for button with border-image-source is linear gradient
You can apply the gradient as the main background then use a pseudo element above it to hide it and keep only the border part visible:
.card-approve-btn { position: relative; display:inline-block; background-image: linear-gradient(291deg, #ffb37c, #f9514f); padding:0 20px; line-height:30px; text-align: center; color: #485564; border-radius: 6px; overflow: hidden; font-size: 14px; font-weight: 600; z-index:0;}
.card-approve-btn:before { content: ''; position: absolute; /* specify the value of border width here */ top: 1px; right: 1px; bottom: 1px; left: 1px; /* --- */ background-color: #fff; border-radius: 5px; box-sizing: border-box; z-index: -1;}
<div class="card-approve-btn"> Approve</div>
Related Topics
How to Position Div Below Another Div
Formatting Numbers (Decimal Places, Thousands Separators, Localization, etc) With CSS
Split Div into 2 Columns Using CSS
Css Change Button Style After Click
What Is the Way to Add Horizontal Scroll on Material-Ui Table With Many Columns
Stretch Child Div Height to Fill Parent That Has Dynamic Height
How to Change Color Property of Mat-Slide-Toggle/ Overwrite CSS of Component
How to Set the Width of Select Box Options
Swap Div Position With CSS Only
Css Force Image Resize and Keep Aspect Ratio
Difference Between "Word-Break: Break-All" Versus "Word-Wrap: Break-Word" in Css
Change Bootstrap Navbar Collapse Breakpoint Without Using Less
Css Reset - What Exactly Does It Do
Css 100% Height With Padding/Margin
Difference Between Max-Device-Width and Max-Width For Mobile Web