I try to use custom variables inside my CSS.
Under FireFox: everything is okay.
Under Google Chrome or Microsoft Edge: it works pretty well on linear-gradient but not on -moz-linear-gradient
Here is my code: https://codepen.io/Bronzato1/pen/VwWBJjP?editors=1100
To show you the problem, I created the first class which works as expected and the second class with the usage of a variable inside -moz-linear-gradient breaks the style !
HTML
<div class="first red"></div>
<div class="second red"></div>
CSS
.red {
--custom-color: #FF0000;
}
.first::before{
content:'';
position: absolute;
width: 19rem;
height: 14rem;
background: linear-gradient(128deg, transparent 51%, black 53%, var(--custom-color) 70%, transparent 72%) no-repeat bottom left;
/*FF*/
background: -moz-linear-gradient(128deg, transparent 51%, black 53%, black 70%, transparent 72%) no-repeat bottom left;
background-color: #000000;
}
.second::before{
content:'';
position: absolute;
top: 250px;
width: 19rem;
height: 14rem;
background: linear-gradient(128deg, transparent 51%, black 53%, var(--custom-color) 70%, transparent 72%) no-repeat bottom left;
/*FF*/
background: -moz-linear-gradient(128deg, transparent 51%, black 53%, var(--custom-color) 70%, transparent 72%) no-repeat bottom left;
background-color: #000000;
}
You need to put your prefixed styles above the standard style, e.g.
background: -moz-linear-gradient(...) no-repeat bottom left;
background: linear-gradient(...) no-repeat bottom left;
Otherwise the browser will attempt to use the last valid style, which I believe causes problems since background is a combined style so you end up overwriting your linear-gradient with a -moz-linear-gradient that Chrome doesn't understand.
Working example:
.red {
--custom-color: #FF0000;
}
.first::before {
content: '';
position: absolute;
width: 19rem;
height: 14rem;
background: -moz-linear-gradient(128deg, transparent 51%, black 53%, red 70%, transparent 72%) no-repeat bottom left;
background: linear-gradient(128deg, transparent 51%, black 53%, var(--custom-color) 70%, transparent 72%) no-repeat bottom left;
background-color: #000000;
}
.second::before {
content: '';
position: absolute;
top: 250px;
width: 19rem;
height: 14rem;
background: -moz-linear-gradient(128deg, transparent 51%, black 53%, var(--custom-color) 70%, transparent 72%) no-repeat bottom left;
background: linear-gradient(128deg, transparent 51%, black 53%, var(--custom-color) 70%, transparent 72%) no-repeat bottom left;
background-color: #000000;
}
<div class="first red"></div>
<div class="second red"></div>
Try this:
.red {
--custom-color: #FF0000;
}
.first::before, .second::before{
content:'';
position: absolute;
width: 19rem;
height: 14rem;
background: linear-gradient(128deg, transparent 51%, black 53%, var(--custom-color) 70%, transparent 72%) no-repeat bottom left;
/*FF*/
background: -moz-linear-gradient(128deg, transparent 51%, black 53%, red 70%, transparent 72%) no-repeat bottom left;
background-color: #000000;
}
.second::before{
top: 250px;
}
Related
Here is my fiddle, I want to set the text color to background color but inverted.
https://jsfiddle.net/6q34vf7o/16/
<div>
<span>Test</span>
</div>
div {
background: linear-gradient(to right, #fff, #000);
width: 100vh;
height: 50vh;
}
span{
font-size: 30vh;
}
How can I do it?
I know there's a mix-blend-mode, but I don't know how to use it at here.
div {
background: linear-gradient(to right, #fff, #000);
width: 100vh;
height: 50vh;
}
span {
font-size: 30vh;
mix-blend-mode: difference;
filter: invert(1);
}
<div>
<span>Test</span>
</div>
You need to add text-fill-color: transparent and background-clip: text in order to make gradient work as background-image in text. In the background line, just change 'to right' by 'to left'.
div {
background: linear-gradient(to right, #fff, #000);
}
span {
background-image: -webkit-linear-gradient(to left, #fff, #000);
background-image: linear-gradient(to left, #fff, #000);
-webkit-text-fill-color: transparent;
text-fill-color: transparent;
-webkit-background-clip: text;
background-clip: text;
}
<div style='width: 85vh; height: 35vh;'><span style='font-size: 30vh; font-family: Arial; font-weight: bold;'>TEST</span></div>
div {
background: linear-gradient(to right, #fff, #000);
width: 100vh;
height: 50vh;
}
span{
font-size: 30vh;
filter: invert(1);
}
<div>
<span>Test</span>
</div>
Was trying to make a multi-color bottom border like in below image, but failed.
Tried to use border-image: linear-gradient(), but didn't manage. it only gets one of the colors: #707070.
a {
color: #707070 !important;
font-size: 20px;
text-decoration: none;
margin-right: 50px;
border-bottom: 5px solid;
border-image: linear-gradient(to bottom, #707070 20%, #a4c0e9 20%, #a4c0e9 80%, #707070 80%) 5;
}
<div id="nav">
HOME
PROJECTS
RESUME
</div>
The issue is that percentages are relative to the element not the border which will make the 20% bigger than 5px.
You need to consider pixel values. You also need to start from the bottom because the top reference is also the top of the element:
a {
color: #707070 !important;
font-size: 20px;
text-decoration: none;
margin-right: 50px;
border-bottom: 5px solid;
border-image:
linear-gradient(to top, #707070 1px, #a4c0e9 1px, #a4c0e9 4px, #707070 4px) 5;
}
<a>A link element</a>
Or use it as background and it will be easier to handle:
a {
color: #707070 !important;
font-size: 20px;
text-decoration: none;
margin-right: 50px;
border-bottom: 5px solid transparent;
background:
linear-gradient(to bottom, #707070 20%, #a4c0e9 20%, #a4c0e9 80%, #707070 80%) bottom/100% 5px border-box no-repeat;
}
<a>A link element</a>
Related: border-image-slice for gradient border image
Here is an example to better illustrate the issue you were having:
.box {
width:100px;
height:100px;
display:inline-block;
border-bottom:10px solid rgba(0,0,0,0.2);
}
<div class="box" style="background:linear-gradient(to bottom, #707070 20%, #a4c0e9 20%, #a4c0e9 80%, #707070 80%) border-box">
</div>
<div class="box" style="border-image:linear-gradient(to bottom, #707070 20%, #a4c0e9 20%, #a4c0e9 80%, #707070 80%) 10 fill">
</div>
<div class="box" style="border-image:linear-gradient(to bottom, #707070 20%, #a4c0e9 20%, #a4c0e9 80%, #707070 80%) 10 ">
</div>
In this example, the first box show the gradient we will be using. In the second one, we are applying it to the border using fill to also color the middle area and in the last one we are coloring only the border-bottom
It's always good to post your code, or a link to jsfiddle or codepen. You can refer help section on how to ask?
In your case, the design you have shown here doesn't look like a gradient. I have a solid color and borders on it. Gradients can be used on border, you can see it here
To achieve what you have shown I would have used :after and following style,
a{
position: relative;
padding-bottom: 20px;
&:after{
position: absolute;
content: '';
height: 10px;
width: 100%;
left: 0;
bottom: 0;
background: #a4c0e9;
border-top: 1px solid #707070;
border-bottom: 1px solid #707070;
}
}
Hello I am having trouble trying to come up with a way of adding a border of 1px to a container with a jagged border such as:
https://codepen.io/swizenfeld/pen/ZyBybW
body {
background: #f4f4f4;
}
.edge {
width: 100%;
height: 400px;
background: #fff;
margin-top: 30px;
}
.edge:before {
content: " ";
display: block;
position: relative;
width: 100%;
top:-30px;
height:30px;
background: linear-gradient(135deg, transparent 75%, white 76%) 0 50%,
linear-gradient(-135deg, transparent 75%, white 76%) 0 50%;
background-repeat: repeat-x;
background-size: 30px 30px, 30px 30px;
}
<div class="edge"></div>
Any ideas?
You need to add more linear-gradient() to show jagged border
body {
background: #f4f4f4;
}
.edge {
width: 100%;
height: 400px;
background: #fff;
margin-top: 30px;
}
.edge:before {
content: " ";
display: block;
position: relative;
width: 100%;
top:-30px;
height:30px;
background: linear-gradient(135deg, transparent 75%, white 76%) 0 50%, linear-gradient(-135deg, transparent 75%, white 76%) 0 50%, linear-gradient(45deg, red 30%, transparent 0%), linear-gradient(-45deg, red 30%, transparent 0%);
background-repeat: repeat-x;
background-size: 30px 30px, 30px 30px;
}
<div class="edge"></div>
For border-left, -bottom, -right, try to play with below snippet and see the comment also given for css properties.
body {
background: #ccc;
}
.edge {
width: 100%;
height: 400px;
background: white;
margin-top: 30px;
border-left:2px solid red;
border-bottom:2px solid red;
border-right:2px solid red;
position:relative; /*make it relative*/
}
.edge:after {
content: " ";
display: block;
position:absolute; /*make it absolute*/
width: 100%;
top:-6px; /* play with top and height too*/
height:23px;
/*background: linear-gradient(135deg, transparent 75%, white 76%) 0 50%, linear-gradient(-135deg, transparent 75%, white 76%) 0 50%, linear-gradient(45deg, red 30%, transparent 0%), linear-gradient(-45deg, red 30%, transparent 0%);*/
background: linear-gradient(45deg,white 14px, red 16px, transparent 17px), linear-gradient(-45deg, white 14px, red 16px, #ccc 17px);
background-repeat: repeat-x;
background-size: 30px 30px, 30px 30px;
}
<div class="edge"></div>
I'm designing a site for a school project, and I'm trying to design a particular style for the buttons and navigation, but I'm not sure how to go about this.
I considered doing a border effect, but I stopped short as I realized that it doesn't just involve changing individual side's colors but cutting two sides in half and coloring those pieces differently. A gradient on a div behind it might work, but not only would that get complicated, but it would look blurry while I'm going for sharpness like an edge on a 3D shape. Is this doable, or would I have to use images?
EDIT: Wow, looks like there's a lot of methods out there. Code Golf, anyone?
A solution without css gradient if you want to support IE8 too: http://jsfiddle.net/2am780pq/
HTML:
<a class="button">Cool</a>
CSS:
.button {
display: inline-block;
position: relative;
background-color: #4755e7;
padding: 10px 20px;
color: #fff;
}
.button:before {
content: '';
position: absolute;
top: 50%;
bottom: -5px;
left: -5px;
right: -5px;
margin: auto;
background-color: #4451dc;
z-index: -1;
}
.button:after {
content: '';
position: absolute;
top: -5px;
bottom: 50%;
left: -5px;
right: -5px;
margin: auto;
background-color: #5d67e9;
z-index: -1;
}
without gradient nor pseudo-elemts, box-shadow could do the job too:
http://codepen.io/anon/pen/NPaZBd
a{
display: inline-block;
color: #FFF;
padding:5px 1em;
line-height:2em;
background:#4755E7;
margin:1em;
box-shadow:-0.8em -0.8em 0 -0.5em #5d67e9,
0.8em -0.8em 0 -0.5em #5d67e9,
-0.8em 0.8em 0 -0.5em #4451dc,
0.8em 0.8em 0 -0.5em #4451dc;
}
/* add an inside blurry border too ? */
a:nth-child(even) {
box-shadow:-0.8em -0.8em 0 -0.5em #5d67e9,
0.8em -0.8em 0 -0.5em #5d67e9,
-0.8em 0.8em 0 -0.5em #4451dc,
0.8em 0.8em 0 -0.5em #4451dc,
inset 0 0 1px
}
link
link link
link bigger link
link even bigger works still
Yes, with gradient backgrounds and nested elements. This is NOT cross-browser compatible in browsers that do not support CSS3.
Live example: JSFiddle
The HTML:
<span>Click Me</span>
The CSS:
.button {
display: inline-block;
padding: 4px;
background: rgba(115,127,255,1);
background: -moz-linear-gradient(top, rgba(115,127,255,1) 0%, rgba(68,81,220,1) 50%, rgba(68,81,220,1) 51%, rgba(68,81,220,1) 100%);
background: -webkit-gradient(left top, left bottom, color-stop(0%, rgba(115,127,255,1)), color-stop(50%, rgba(68,81,220,1)), color-stop(51%, rgba(68,81,220,1)), color-stop(100%, rgba(68,81,220,1)));
background: -webkit-linear-gradient(top, rgba(115,127,255,1) 0%, rgba(68,81,220,1) 50%, rgba(68,81,220,1) 51%, rgba(68,81,220,1) 100%);
background: -o-linear-gradient(top, rgba(115,127,255,1) 0%, rgba(68,81,220,1) 50%, rgba(68,81,220,1) 51%, rgba(68,81,220,1) 100%);
background: -ms-linear-gradient(top, rgba(115,127,255,1) 0%, rgba(68,81,220,1) 50%, rgba(68,81,220,1) 51%, rgba(68,81,220,1) 100%);
background: linear-gradient(to bottom, rgba(115,127,255,1) 0%, rgba(68,81,220,1) 50%, rgba(68,81,220,1) 51%, rgba(68,81,220,1) 100%);
}
.button span {
display: inline-block;
background: #4755E7;
color: #fff;
padding: 0.5em 0.75em;
}
Here one element solution, simplier markup :D
<b>Im sexy and i know it!</b>
http://jsfiddle.net/ebdq20vm/1/
b {
padding: 20px;
display: inline-block;
color: #FFF;
background: #5d67e9;
background: -moz-linear-gradient(top, #5d67e9 50%, #4451dc 51%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(50%, #5d67e9), color-stop(51%, #4451dc));
background: -webkit-linear-gradient(top, #5d67e9 50%, #4451dc 51%);
background: -o-linear-gradient(top, #5d67e9 50%, #4451dc 51%);
background: -ms-linear-gradient(top, #5d67e9 50%, #4451dc 51%);
background: linear-gradient(to bottom, #5d67e9 50%, #4451dc 51%);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#5d67e9', endColorstr='#4451dc', GradientType=0);
position: relative;
z-index: 5;
}
b:before {
content:'';
position: absolute;
top: 4px;
left: 4px;
right: 4px;
bottom: 4px;
background-color: #4755E7;
display: block;
z-index: -1;
}
Is there a way to set the size of the image independent from the general size of the background with css?
With following code I set the size of the of the background, so the gradient and the image have the width of 30px.
background(url("../images/icons/double_arrow_37px.svg"), linear-gradient(to top bottom, rgb(171, 129, 85), rgb(148, 112, 74)));
background-size: 30px 37px;
What I need is to set the width of the image to 30px and the gradient to a width of 100% of the button.
I already know the workaround to create a extra image with the correct dimensions, but maybe there is a smarter way with css?
Full Example:
body {
background-color: #000;
}
.button-custom {
color: #fff;
font-family: $font-centennial;
background-image: url("http://metk.de/kunden/stackoverflow/double_arrow_37px.svg");
background-size: 30px 37px;
background-position: center left;
background-repeat: no-repeat;
margin-top: 70px;
padding: 15px 45px;
border-radius: 0;
border: 0;
text-transform: uppercase;
overflow: hidden;
}
.button-custom.bronze {
background-color: #ab8155;
}
.button-custom.bronze:hover {
background: url("http://metk.de/kunden/stackoverflow/double_arrow_37px.svg"), -moz-linear-gradient(bottom, #ab8155, #94704a);
background: url("http://metk.de/kunden/stackoverflow/double_arrow_37px.svg"), -webkit-linear-gradient(bottom, #ab8155, #94704a);
background: url("http://metk.de/kunden/stackoverflow/double_arrow_37px.svg"), linear-gradient(to top bottom, #ab8155, #94704a);
background-position: center left;
background-size: 30px 37px;
background-position: center left;
background-repeat: no-repeat;
color: #fff;
}
Contact
In CSS3, you can use multiple images background. linear-background is interpreted as an image not a color. Known that, you can write something like that :
body {
height: 600px; /* not relevant for your problem */
width: 600px;
}
div {
height: 500px; /* not relevant for your problem */
width: 500px; /* not relevant for your problem */
border: 3px dashed green; /* not relevant for your problem */
background: url("http://i436.photobucket.com/albums/qq90/KatDJZ/Forums/18556-Robot_Unicorn_Attack.jpg"), -moz-linear-gradient(top, red 0%, blue 100%);
background: url("http://i436.photobucket.com/albums/qq90/KatDJZ/Forums/18556-Robot_Unicorn_Attack.jpg"), -webkit-gradient(linear, left top, left bottom, color-stop(0%, red), color-stop(100%, blue));
background: url("http://i436.photobucket.com/albums/qq90/KatDJZ/Forums/18556-Robot_Unicorn_Attack.jpg"), -webkit-linear-gradient(top, red 0%, blue 100%);
background: url("http://i436.photobucket.com/albums/qq90/KatDJZ/Forums/18556-Robot_Unicorn_Attack.jpg"), -o-linear-gradient(top, red 0%, blue 100%);
background: url("http://i436.photobucket.com/albums/qq90/KatDJZ/Forums/18556-Robot_Unicorn_Attack.jpg"), -ms-linear-gradient(top, red 0%, blue 100%);
background: url("http://i436.photobucket.com/albums/qq90/KatDJZ/Forums/18556-Robot_Unicorn_Attack.jpg"), linear-gradient(to bottom, red 0%, blue 100%);
background-position: 50% 50%, 50% 50%;
background-repeat: no-repeat, no-repeat;
background-size: 150px, 300px;
}
<div>Yo!</div>