CSS Multiple background with multiple classes - css

HTML :
<div class="blue red"></div>
Blue : If a gradient background from transparent to blue
Red : If a gradient background from red to transparent
Why we can't do something like :
.blue {
background: inherit , background: linear-gradient(to right, rgba(255,255,255,0) 0%, rgba(125,185,232,1) 100%);
}
.red {
background: linear-gradient(to right, rgba(255,10,10,1) 0%, rgba(255,255,255,0) 100%) , inherit;
}
Instead of :
.blue {
background: linear-gradient(to right, rgba(255,255,255,0) 0%, rgba(125,185,232,1) 100%);
}
.red {
background: linear-gradient(to right, rgba(255,10,10,1) 0%, rgba(255,255,255,0) 100%);
}
.blue.red {
background: linear-gradient(to right, rgba(255,255,255,0) 0%, rgba(125,185,232,1) 100%) , linear-gradient(to right, rgba(255,10,10,1) 0%, rgba(255,255,255,0) 100%);
}
Thats ok if i use only 2 multiple classes, but if I have blue,red,yellow,black,white, bla bla bla.... so you know it bored.
I wonder how to use multiple background with multiple classes ?
Any CSS trick ?
Playground : http://jsfiddle.net/5gJyr/
Expand :
I will use inherit property, gives slot(s) for them
If i have more colors I will add them after like
.red {background: red,inherit,inherit;}
.blue {background: inherit,blue,inherit;}
.yellow {background: inherit,inherit,yellow;}
so I can add given multiple classes like
<div class="red yellow">

Simply put, there is no 'easier way'
inherit works by taking the parent property
The inherit CSS-value causes the element for which it is specified to
take the computed value of the property from its parent element. It is
allowed on every CSS property.
The only way to apply multiple background values is to concatenate them with a comma,
More from MDN
With CSS3, you can apply multiple backgrounds to elements. These are
layered atop one another with the first background you provide on top
and the last background listed in the back. Only the last background
can include a background color.
.myclass {
background: background1, background 2, ..., backgroundN;
}

You cannot add an additional background with an additional class. CSS properties have exactly one value, and they do not accumulate. Even with properties like background where multiple values are permitted, those multiple values are not harvested and aggregated from all applicable classes, they are the ones specified in the one, specific rule that defines background according to the cascade.

Related

Background color gradient in Ionic 2

I'm trying to set the background-color for my app using $background-color variable in variables.scss file. This works fine when setting just a color, like #000 or #fff, but can't make it work with a gradient.
$background-color: linear-gradient(to bottom, #000 0%, #fff 100%);
This code throws the following Sass error:
argument '$color' of 'rgba($color, $alpha)' must be a color Backtrace.
So, how can I set the background-color to be a gradient?
This is the scss code I use for my own background gradient.
$SIDEMENU_TOP: #A23C4B;
$SIDEMENU_BOTTOM: #ff9068;
$SIDEMENU_TRANSPARENCY: rgba(255,255,255,0.4);
.side-menu-gradient{
background: -webkit-gradient(left top, $SIDEMENU_TOP, $SIDEMENU_BOTTOM);
background: -o-linear-gradient(bottom right, $SIDEMENU_TOP, $SIDEMENU_BOTTOM);
background: -moz-linear-gradient(bottom right, $SIDEMENU_TOP, $SIDEMENU_BOTTOM);
background: linear-gradient(to bottom right, $SIDEMENU_TOP, $SIDEMENU_BOTTOM);
}
(Maybe highly inspired from Ionic Creator - Creating beautiful Sidemenus (YouTube)
If you want to set the background colour of a page, for example home.html page, to a gradient, you should follow these two steps:
In home.html you should have a class called home in the ion-content tag:
<ion-content padding class="home">
...
</ion-content>
Go to home.scss file (create one if you do not have it) and define the home class:
.home {
background: linear-gradient(to bottom, #000 0%, #fff 100%);
}
Make sure this sass is being compiled by importing it into app.css file:
#import "../pages/home/home";
Insert this line of code in your app.css file.
Do ionic run android in your Terminal and ... you'll have a gradient background for your home page!
Done!
$background-color variable won't work instead use $app-background
Example:
$app-background: linear-gradient(to bottom, #000 0%, #fff 100%);

Combine CSS background-image and gradient on third h3 using nth-child

I'm having a heck of a time trying to combine a diagonal linear gradient and regular background-image together plus apply it only to the second h3 element; here is what I've got:
HTML
<div id="something">
<div><h3>...</h3></div>
<div><h3>...</h3></div>
<div><h3>...</h3></div>
<div><h3>...</h3></div>
</div>
CSS
#something h3:nth-child(2) {
background: linear-gradient(135deg, rgba(221,221,221,1) 0%,
rgba(221,221,221,1) 95%, rgba(0,0,0,1) 95%, rgba(0,0,0,1) 100%),
#ddd url(/assets/img/bullet.png) left 12px no-repeat;
}
I've had the nth-child selector working on other stuff previously before and this gradient is from an online generator, what am I missing here?
Looks like the selector should be:
#something > div:nth-child(3) > h3
https://jsfiddle.net/db2n5r63/1/
linear-gradient() takes the place of url(). In fact they are two delarations for the same background. One will be chosen. So define more precisely what you want and perhaps chose a span inside H3 to achieve the effect you want.
Your nth-childwont work beacuse the h3 tags are wrapped in a div so can you do something like this:
#something div:nth-child(2) h3
Now to make the background work we combine the background image url and the gradient. You can define the background url first then do a comma and define the gradient:
This stackoverflow question answers that in more depth.
#something div:nth-child(2) h3{
background: url("http://lorempixel.com/300/300/") no-repeat,linear-gradient(135deg, rgba(221,221,221,1) 0%,
rgba(221,221,221,1) 95%, rgba(0,0,0,1) 95%, rgba(0,0,0,1) 100%);
background-position-x: 12px;
}
I've made an Example for you to see this in action.

Generate a saturation/brightness mask using gradients

I would like to know if it's possible to generate a mask of saturation+brightness that are used in color pickers for instance (something like http://johndyer.name/lab/colorpicker/refresh_web/colorpicker/images/map-hue.png) but using only linear-gradient in css3 ?
I tried severals things, such as :
background: linear-gradient(to right, hsla(0,100%,0,0) 0%, hsla(0,0%,0%,.5) 100%), /* saturation mask */
linear-gradient(to top, hsla(0,0%,0%,.5) 0%, hsla(0,0%,100%,.5) 100%), /* lightness mask */
but I can't make something like the picture, can't find the right combinaison, and because I don't fully understand, I don't know if it's possible.
Thanks
It is maybe the way you write it.
for the image, 1 gradient + a background-color will do.
you did not close correctly you rules , one value is still expected 100%) , /* li
:)
this could be it :
ele {
background:
linear-gradient(0deg, hsla(0,0%,0%,.5) 0%, hsla(0,0%,100%,.5) 100%) no-repeat left ,
white linear-gradient(180deg, hsla(0,0%,0%,.5) 0%, hsla(0,0%,100%,.5) 100%) no-repeat right;
background-size:95% 100%, 5% 100%;
}
http://codepen.io/anon/pen/ubDsr (gradient covers body)
You had your gradients reversed and some incorrect hsla values.
Just use hex notation, it's easier in this case:
background-image:
linear-gradient(to top, #000 0%, transparent 100%), /* lightness*/
linear-gradient(to right, #fff 0%, transparent 100%); /* saturation */
Here's a demo where you can compare the result with an image-based solution (normal = gradients, hover = Bootstrap Colorpicker).

How do I overlay a gradient background over an existing background with CSS?

I am trying to overlay a white-black linear gradient to an existing image. I have it set up like below; however, only the gradient layer is showing. Can someone point out where I went wrong?
JS Fiddle: http://jsfiddle.net/6nJJD/
HTML
<div>hello</div>
CSS
div {
background:linear-gradient(to bottom, #ffffff 0%, #000000 100%), url("http://us.123rf.com/400wm/400/400/adroach/adroach1210/adroach121000001/15602757-flower-and-bird-ornaments-retro-tile-repeat-as-many-times-as-you-like.jpg") repeat #eae7de;
color:#544a46;
font:62.5%/1.6 Helvetica, Arial, Sans-serif;
height:500px;
width:500px
}
try to change your gradient colours using RGBA values
background:
linear-gradient(to bottom, rgba(255,255,255, 0) 0%, rgba(0,0,0, 1) 100%),
url(...);
Example fiddle: http://jsfiddle.net/J7bUd/
Try also changing rgba(255,255,255, 0) with transparent: the result is slightly different but probably it's exactly what you're trying to achieve
You can accomplish this using RGBA in the gradient.
http://jsfiddle.net/6nJJD/3/
CSS:
linear-gradient(to bottom, rgba(0,0,0,0.65) 0%,rgba(0,0,0,0) 100%)
You can modify the "0.65" value to attain the desired transparancy.
For Creating More Gradients as you like you can visit Ultimate Css
Gradient Generator
Hope This HElps
like this?
http://jsfiddle.net/6nJJD/2/
linear-gradient(to bottom, rgba(255,255,255,0.9) 0%, #000000 100%)

How to mimic Photoshop "Color Overlay" in CSS

I have a button designed with Photoshop. The button has a gradient defined and I know how to generate it using Ultimate CSS Gradients Tool.
The problem is the button also has a 'Color Overlay' and I don't know how to convert it to css terms?!
UPDATE:
O.K, just to clarify, I know CSS quite well and i know how to set styles to elements.
I have this gradient:
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2IzYjdiZCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9Ijg1JSIgc3RvcC1jb2xvcj0iIzZhNzI3ZCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgPC9saW5lYXJHcmFkaWVudD4KICA8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2dyYWQtdWNnZy1nZW5lcmF0ZWQpIiAvPgo8L3N2Zz4=);
background: -moz-linear-gradient(top, rgba(179,183,189,1) 0%, rgba(106,114,125,1) 85%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(179,183,189,1)), color-stop(85%,rgba(106,114,125,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(179,183,189,1) 0%,rgba(106,114,125,1) 85%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(179,183,189,1) 0%,rgba(106,114,125,1) 85%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(179,183,189,1) 0%,rgba(106,114,125,1) 85%); /* IE10+ */
background: linear-gradient(to bottom, rgba(179,183,189,1) 0%,rgba(106,114,125,1) 85%); /* W3C */
But like i mentioned, In photoshop there is also a Color Overlat defined which makes the button a bit darker, so in photoshop the button looks darker then in the browser, So my question is how do i combine the gradient and the Color Overlay in one CSS rule to make the button look exactly the same as in photoshop.
Update:
Demo
A little better button Demo
Demo with overlay
Just declare a class for button say .design
.design {
/* Gradient code goes here */
}
Now you can use this class as follows
<button class="design">Designed Button</button>
OR
<input type="button" class="design" value="Designed Button" />
For the COLOR OVERLAY, you can wrap the button inside a div with
display: inline-block and position: relative so that it will wrap
the button appropriately and use another div which is positioned
absolute inside the wrapper div with a height and width defined as
100% and assign opaque background color using rgba() and define
opacity as needed
Also if you want to be precise with your CSS declarations, you can particularly define .design class as input[type=button].design or button.design whatever you use, so that .design will not be applied to any other element

Resources