I've stumbled upon something weird. When applying a dashed white border to an element, the colors of the background gradient appear on the wrong side of the element, like so:
I've seen this in the latest versions of Firefox, Chrome, Opera and in IE10. IE9 has my intented effect, however.
My css is currently:
aside.block {
width: 259px;
padding: 12px;
margin: 15px 0;
border: 2px dashed #fff;
background-image: -o-linear-gradient(bottom, rgb(219,203,0) 0%, rgb(255,236,0) 100%);
background-image: -moz-linear-gradient(bottom, rgb(219,203,0) 0%, rgb(255,236,0) 100%);
background-image: -webkit-linear-gradient(bottom, rgb(219,203,0) 0%, rgb(255,236,0) 100%);
background-image: -ms-linear-gradient(bottom, rgb(219,203,0) 0%, rgb(255,236,0) 100%);
background-image: linear-gradient(bottom, rgb(219,203,0) 0%, rgb(255,236,0) 100%);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffec00', endColorstr='#dbcb00');
}
The border colors on the left and right side color fine, but since this happens in pretty much every browser, I'll have to assume this is my mistake, not a browser bug. What am I missing here?
To show gradients for a border with CSS you can use the border-image property. It allows setting gradient values in the same way as the background-image property. Besides the border-image property, you should specify additional properties to actually show border gradient.
Because <gradient> s belong to the <image> data type, they can only be used where <image> s can be used. For this reason, linear-gradient() won't work on background-color and other properties that use the <color> data type.
Just as you can declare the background of an element to be a solid color in CSS, you can also declare that background to be a gradient. Using gradients declared in CSS, rather using an actual image file, is better for control and performance.
You can fix this by setting background-origin
to border-box
.
http://jsfiddle.net/LVfqe/11/
.block{
width: 259px;
padding: 12px;
background-image: -o-linear-gradient(bottom, rgb(219,203,0) 0%, rgb(255,236,0) 100%);
background-image: -moz-linear-gradient(bottom, rgb(219,203,0) 0%, rgb(255,236,0) 100%);
background-image: -webkit-linear-gradient(bottom, rgb(219,203,0) 0%, rgb(255,236,0) 100%);
background-image: -ms-linear-gradient(bottom, rgb(219,203,0) 0%, rgb(255,236,0) 100%);
background-image: linear-gradient(bottom, rgb(219,203,0) 0%, rgb(255,236,0) 100%);
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffec00',endColorstr='#dbcb00');
border: 2px dashed #fff;
background-origin:border-box;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With