Css border and outline generator

I"m trying to apply a gradient lớn a border, I thought it was as simple as doing this:

border-color: -moz-linear-gradient(top, #555555, #111111);But this does not work.

Bạn đang xem: Css border and outline generator

Does anyone know what is the correct way to vày border gradients?


*

*

WebKit now (and Chrome 12 at least) supports gradients as border image:

-webkit-border-image: -webkit-gradient(linear, left top, left bottom, from(#00abeb), to(#fff), color-stop(0.5, #fff), color-stop(0.5, #66cc00)) 21 30 30 21 repeat repeat;Proofliên kết -- http://www.webkit.org/blog/1424/css3-gradients/Browser support: http://caniuse.com/#search=border-image


*

*

instead of borders, I would use background gradients & padding. same look, but much easier, more supported.

a simple example:


.g background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0.33, rgb(14,173,173)), color-stop(0.67, rgb(0,255,255)));background-image: -moz-linear-gradient(center bottom, rgb(14,173,173) 33%, rgb(0,255,255) 67% );padding: 2px;.g > div background: #fff;
body padding: 20px;.circle width: 100%; height: 200px; background: linear-gradient(khổng lồ top, #3acfd5 0%, #3a4ed5 100%); border-radius: 100%; position: relative; text-align: center; padding: 20px; box-sizing: border-box;.circle::before border-radius: 100%; content: ""; background-image: linear-gradient(khổng lồ bottom, #3acfd5 0%, #3a4ed5 100%); top: -10px; left: -10px; bottom: -10px; right: -10px; position: absolute; z-index:-1;

*

border-image-slice will extover a CSS border-image gradientThis (as I understvà it) prevents the mặc định slicing of the "image" inlớn sections - without it, nothing appears if the border is on one side only, & if it"s around the entire element four tiny gradients appear in each corner.

border-bottom: 6px solid transparent; border-image: linear-gradient(to lớn right, red , yellow); border-image-slice: 1;
Mozilla currently only supports CSS gradients as values of the background-image property, as well as within the shorthand background.

— https://developer.mozilla.org/en/CSS/-moz-linear-gradient

Example 3 - Gradient Bordersborder: 8px solid #000;-moz-border-bottom-colors: #555 #666 #777 #888 #999 #aaa #bbb #ccc;-moz-border-top-colors: #555 #666 #777 #888 #999 #aaa #bbb #ccc;-moz-border-left-colors: #555 #666 #777 #888 #999 #aaa #bbb #ccc;-moz-border-right-colors: #555 #666 #777 #888 #999 #aaa #bbb #ccc;padding: 5px 5px 5px 15px; — http://www.cssportal.com/css3-preview/borders.htm


Share
Follow
answered Aquảng bá 26 "10 at 21:53
QuentinQuentin
785k9999 gold badges10621062 silver badges11911191 bronze badges
Add a bình luận |
28
Try this, works fine on web-kit


.border width: 400px; padding: 20px; border-top: 10px solid #FFFF00; border-bottom:10px solid #FF0000; background-image: linear-gradient(#FFFF00, #FF0000), linear-gradient(#FFFF00, #FF0000) ; background-size:10px 100%; background-position:0 0, 100% 0; background-repeat:no-repeat;
Hello!
Share
Follow
edited Jan 7 "19 at 2:02
Joseph Sible-Reinstate Monica
32.1k33 gold badges3131 silver badges7171 bronze badges
answered Aug 30 "13 at 9:33
GibboKGibboK
62.9k127127 gold badges374374 silver badges603603 bronze badges
2
Add a phản hồi |
12
It"s a haông xã, but you can achieve sầu this effect in some cases by using the background-image to lớn specify the gradient & then masking the actual background with a box-shadow. For example:

p display: inline-block; width: 50px; height: 50px; /* The background is used to lớn specify the border background */ background: -moz-linear-gradient(45deg, #f00, #ff0); background: -webkit-linear-gradient(45deg, #f00, #ff0); /* Background origin is the padding box by default. Override khổng lồ make the background cover the border as well. */ -moz-background-origin: border; background-origin: border-box; /* A transparent border determines the width */ border: 4px solid transparent; border-radius: 8px; box-shadow: inphối 0 0 12px #0cc, /* Inmix shadow */ 0 0 12px #0cc, /* Outset shadow */ inset -999px 0 0 #fff; /* The background color */From: http://blog.nateps.com/the-elusive-css-border-gradient


Share
Follow
answered Sep 21 "11 at 1:04
Nate SmithNate Smith
43944 silver badges66 bronze badges
Add a phản hồi |
5
Try the below example:

.border-gradient border-width: 5px 5px 5px 5px; border-image: linear-gradient(45deg, rgba(100,57,242,1) 0%, rgba(242,55,55,1) 100%); border-image-slice: 9; border-style: solid;
Share
Follow
edited Oct 1 "19 at 22:18
gorelative
8,93455 gold badges4545 silver badges6969 bronze badges
answered Oct 1 "19 at 16:39
Vijay ChauhanVijay Chauhan
9701313 silver badges1414 bronze badges
Add a phản hồi |
4
Try this, it worked for me.


div border-radius: 20px; height: 70vh; overflow: hidden;div::before content: ""; display: block; box-sizing: border-box; height: 100%; border: 1em solid transparent; border-image: linear-gradient(to lớn top, red 0%, xanh 100%); border-image-slice: 1;

The liên kết is to lớn the fiddlehttps://jsfiddle.net/yash009/kayjqve3/1/ hope this helps


Share
Follow
edited Dec 3 "19 at 15:18
vsync
83.4k4444 gold badges236236 silver badges310310 bronze badges
answered Oct 24 "18 at 20:trăng tròn
Yash009Yash009
49333 silver badges1616 bronze badges
0
Add a bình luận |
3
I agree with szajmon. The only problem with his và Quentin"s answers is cross-browser compatibility.

Xem thêm: Bệnh Tuyến Giáp Ở Đàn Ông - 6 Vấn Đề Tuyến Giáp Có Thể Gặp Ở Nam Giới

HTML:


bla
CSS:

.g background-image: -webkit-linear-gradient(300deg, white, black, white); /* webkit browsers (Chrome và Safari) */background-image: -moz-linear-gradient(300deg, white, blaông chồng, white); /* Mozilla browsers (Firefox) */filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="#ffffff", endColorstr="#000000", gradientType="1"); /* Internet Explorer */background-image: -o-linear-gradient(300deg,rgb(255,255,255),rgb(0,0,0) 50%,rgb(255,255,255) 100%); /* Opera */.g > div background: #fff;
Share
Follow
answered Jan 20 "12 at 23:10
ScottyScotty
3911 bronze badge
4
Add a bình luận |
3
Webkit supports gradients in borders, & now accepts the gradient in the Mozilla format.

Firefox claims to tư vấn gradients in two ways:

IE9 has no support.


Share
Follow
answered Jul 11 "12 at 21:50
SamGoodySamGoody
11.7k88 gold badges6868 silver badges8484 bronze badges
0
Add a bình luận |
2
Another hack for achieving the same effect is khổng lồ utilize multiple background images, a feature that is supported in IE9+, newish Firefox, và most WebKit-based browsers: http://caniuse.com/#feat=multibackgrounds

There are also some options for using multiple backgrounds in IE6-8: http://www.beyondhyper.com/css3-multiple-backgrounds-in-non-supportive-browsers/

For example, suppose you want a 5px-wide left border that is a linear gradient from xanh lớn white. Create the gradient as an image and export khổng lồ a PNG. List any other CSS backgrounds after the one for the left border gradient:

#theBox background: url(/images/theBox-leftBorderGradient.png) left no-repeat, ...;You can adapt this technique to top, right, và bottom border gradients by changing the background position part of the background shorth& property.

Here is a jsFiddle for the given example: http://jsfiddle.net/jLnDt/


Share
Follow
answered Sep 12 "12 at 23:18
Daniel TrebbienDaniel Trebbien
35.3k1414 gold badges103103 silver badges182182 bronze badges
Add a phản hồi |
2
Gradient Borders from Css-Tricks: http://css-tricks.com/examples/GradientBorder/

.multbg-top-to-bottom border-top: 3px solid black; background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#000), to(transparent)); background-image: -webkit-linear-gradient(#000, transparent); background-image: -moz-linear-gradient(#000, transparent), -moz-linear-gradient(#000, transparent); background-image: -o-linear-gradient(#000, transparent), -o-linear-gradient(#000, transparent); background-image: linear-gradient(#000, transparent), linear-gradient(#000, transparent); -moz-background-size: 3px 100%; background-size: 3px 100%; background-position: 0 0, 100% 0; background-repeat: no-repeat;
Share
Follow
answered Oct 27 "14 at 14:23
VVSVVS
1,64911 gold badge1010 silver badges1212 bronze badges
Add a bình luận |
2
Example for Gradient Border

Using border-image css property

Credits to : border-image in Mozilla


.grad-border height: 1px; width: 85%; margin: 0 auto; display: flex;.left-border, .right-border width: 50%; border-bottom: 2px solid #695f52; display: inline-block;.left-border border-image: linear-gradient(270deg, #b3b3b3, #fff) 1;.right-border border-image: linear-gradient(90deg, #b3b3b3, #fff) 1;
Share
Follow
edited Jul 12 "19 at 10:48
answered Jul 12 "19 at 7:41
MagaeshMagaesh
41144 silver badges1515 bronze badges
Add a bình luận |
1
For cross-browser support you can try as well imitate a gradient border with :before or :after pseuvì elements, depends on what you want khổng lồ vì.


Share
Follow
answered Mar 5 "14 at 9:21
DeneesDenees
8,6191313 gold badges4545 silver badges7373 bronze badges
Add a phản hồi |
0
try this code

.gradientBoxesWithOuterShadows height: 200px;width: 400px; padding: 20px;background-color: white; /* outer shadows (note the rgba is red, green, xanh, alpha) */-webkit-box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.4); -moz-box-shadow: 0px 1px 6px rgba(23, 69, 88, .5);/* rounded corners */-webkit-border-radius: 12px;-moz-border-radius: 7px; border-radius: 7px;/* gradients */background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, white), color-stop(15%, white), color-stop(100%, #D7E9F5)); background: -moz-linear-gradient(top, trắng 0%, Trắng 55%, #D5E4F3 130%); or maybe refer to lớn this fiddle: http://jsfiddle.net/necolas/vqnk9/


Share
Follow
answered May 15 "14 at 8:07
x'tianx'tian
71422 gold badges1010 silver badges3434 bronze badges
Add a bình luận |
0
Here"s a nice sengươi cross-browser way khổng lồ have gradient borders that fade out half way down. Simply by setting the color-stop to rgba(0, 0, 0, 0)

.fade-out-borders min-height: 200px; /* for example */-webkit-border-image: -webkit-gradient(linear, 0 0, 0 một nửa, from(black), to(rgba(0, 0, 0, 0))) 1 100%;-webkit-border-image: -webkit-linear-gradient(blaông xã, rgba(0, 0, 0, 0) 50%) 1 100%;-moz-border-image: -moz-linear-gradient(blaông xã, rgba(0, 0, 0, 0) 50%) 1 100%;-o-border-image: -o-linear-gradient(blaông chồng, rgba(0, 0, 0, 0) 50%) 1 100%;border-image: linear-gradient(to bottom, black, rgba(0, 0, 0, 0) 50%) 1 100%;
Usage explained:

Formal grammar: linear-gradient( < | khổng lồ ,>? <, >+ ) ---------------------------------/ ----------------------------/ Definition of the gradient line List of color stops More here: https://developer.mozilla.org/en-US/docs/Web/CSS/linear-gradient


Share
Follow
answered Jul 3 "14 at 0:40
Yes BarryYes Barry
8,77744 gold badges4343 silver badges6262 bronze badges
Add a bình luận |
-2
There is a nice css tricks article about this here: https://css-tricks.com/gradient-borders-in-css/

I was able to come up with a pretty simple, single element, solution to this using multiple backgrounds & the background-origin property.

.wrapper background: linear-gradient(#222, #222), linear-gradient(to right, red, purple); background-origin: padding-box, border-box; background-repeat: no-repeat; /* this is important */ border: 5px solid transparent;The nice things about this approach are:

It isn’t affected by z-indexIt can scale easily by just changing the width of the transparent border

Cheông xã it out: https://codepen.io/AlexOverbeck/pen/axGQyv?editors=1100


Share
Follow
answered Aquảng cáo 19 "19 at 20:24
AlexAlex
1,98911 gold badge1111 silver badges55 bronze badges
Add a phản hồi |
Highly active question. Earn 10 reputation in order to answer this question. The reputation requirement helps protect this question from spam & non-answer activity.

Not the answer you're looking for? Browse other questions tagged css gradient or ask your own question.


The Overflow Blog
Featured on Meta
Visit chat
Linked
14
Can we mix a gradient color to border-bottom property?
12
Is it possible lớn make a gradient border?
2
border-top with linear gradient?
2
Creating vertical divider with CSS3 / Compass rather than using image
0
Linear gradient border issue
0
Border Gradient
1
Adding a linear-gradient lớn a border via :root var in CSS?
0
Border with multiple colors on several sides
36
“Fade” borders in CSS
33
CSS - Border where only half of a border is visible
See more linked questions
Related
830
CSS 100% height with padding/margin
1430
How do I style a dropdown with only CSS?
1297
How do I combine a background-image & CSS3 gradient on the same element?
729
Can I use a :before or :after pseudo-element on an input field?
178
Multi-gradient shapes
222
Use CSS3 transitions with gradient backgrounds
112
SVG gradient using CSS
2918
Is it possible khổng lồ apply CSS to half of a character?
5
how lớn add gradient lớn borders
Hot Network Questions more hot questions
Question feed
Subscribe to lớn RSS
Question feed To subscribe to lớn this RSS feed, copy & paste this URL into lớn your RSS reader.


default
Staông xã Overflow
Products
Company
Staông xã Exchange Network
site kiến thiết / hình ảnh sản phẩm © 2021 Staông xã Exchange Inc; user contributions licensed under cc by-sa. rev2021.3.5.38718