Css background linear Gradient direction from ( Left to Right ) - html

#myGrad {
background-image: linear-gradient(red, yellow);
}
<div id="myGrad">howdy I am fun</div>
In this code, I want to use a gradient from left to right. How can I apply left to right gradient background?

You can use different methods to achieve that, for example adding this keyword: to right. linear-gradient() docs
#myGrad {
background-image: linear-gradient(to right, red, yellow);
}
#myGrad {
background-image: linear-gradient(to right, red, yellow);
}
.myGrad{
width: 200px;
height: 200px;
}
<div id="myGrad" class="myGrad"></div>

You need only this property: background-image: linear-gradient(to right, red, yellow); if you want to left change it to ...to left,...
#grad1 {
height: 55px;
background-color: red; /* For browsers that do not support gradients */
background-image: linear-gradient(to right, red, yellow);
}
div {
text-align:center;
margin:auto;
color:#888888;
font-size:40px;
font-weight:bold;
height:500px;
}
<div id="grad1" class="">
From left to right
</div>

The syntax of linear gradient is,
linear-gradient(direction, stop color 1 , stop color 2)
So you can write it as,
#myGrad {
background-image: linear-gradient(to right,red, yellow);
}

Related

How do I make my navbar only a gradiented shadow

I am trying to create a navbar with a gradiented background as shown in the image below
How can I create the gradient in the red box in this image
This is a sample CSS class for using gradients.
#gradient {
height: 50px;
opacity: 0.2;
background-color: transparent;
background-image: linear-gradient( black, white);
}
You can tweak the opacity for shadows accordingly.
Your code:
div {
background-image: linear-gradient(black, white);
height:60px;
position:fixed;
top:0px;
width:100%;
border:2px solid black;
text-align:center;
}
There you go:
div {
background-image: linear-gradient(grey, white);
height:60px;
position:fixed;
top:0px;
width:100%;
border:2px solid black;
text-align:center;
}
<div><h1>My Youtube Channel</h1></div>
A completely working example!
You'll want to use linear-gradient.
background-image: linear-gradient(to bottom, rgba(0,0,0,1) 0, rgba(0,0,0,0) 100%);
This is rgba black full opacity (1) to rgba black 0 opacity. If you want it to be lighter you can set the first rgba to something like rgba(0,0,0,0.5), black half opacity (0.5).

HTML CSS Gradient - I have try everything

Before any thing thanks for pay attencion to me.
I just want to make a grandient.
So in HTML i have create a div simple as that.
Code:
body {
}
.containerallbody {
width: 800px;
height: 300px;
background-color: #0076b4;
background-image: -moz-linear-gradient (top, #0076b4 0%, white 100%);
background-image: -webkit-linear-gradient (top, #0076b4 0%, white 100%);
background-image: linear-gradient (top, #0076b4 0%, white 100%); /*STANDARD*/
}
<body>
<div class="containerallbody">
</div>
</body>
I have try Safari, Chrome, Firefox and IE.
I Try also every thing that shows on w3scholls.
And i have seen a lots of videos on youtube talking about this, i dont know what to do more. I just want a simple background cover all the body with a linear grandient from blue to white.
Can anyone save me please?
You have an extra space after the linear-gradient.
body {
}
.containerallbody {
width: 800px;
height: 300px;
background-color: #0076b4;
background-image: -moz-linear-gradient(top, #0076b4 0%, white 100%);
background-image: -webkit-linear-gradient(top, #0076b4 0%, white 100%);
background-image: linear-gradient(top, #0076b4 0%, white 100%); /*STANDARD*/
}
<body>
<div class="containerallbody">
</div>
</body>

How to control the transition of multiples linear-gradients?

Lets say we have:
.el {
background:linear-gradient(to bottom, black, black), linear-gradient(to bottom, red, red), linear-gradient(to bottom, blue, blue), linear-gradient(to bottom, green, green);
background-repeat:no-repeat;
background-position:0 0;
background-size:100% 0;
}
.el:hoover{
background-size:100% 100%;
}
How to control the transition of each linear-gradient? lets say.... 500ms 800ms 1s 1.5s?
Without another div / ::before / ::after is it possible?
Thanks

Adding gradient to button image upon hover

I have a png graphic that I'm using as a button and when the user hovers over the image, I would like to have a color gradient appear over just the button image. Everything I'm finding is working for background images.
My html looks like this:
<img id="connectionRight_img" class="btn" src="imgs/trailEnd_turnRight.png" alt="Right Arrow"/>
And now I'm wondering what needs to go inside the css to accomplish the color change upon hover:
.btn:hover: {
??
}
Any suggestions would be appreciated.
You need to wrap your img with an inline or inline-block element and add a pseudo element to that wrap that only displays on hover
FIDDLE: http://jsfiddle.net/xz7xy8dg/
CSS:
.wrap {
position:relative;
display:inline-block;
}
.wrap::after {
position:absolute;
height: 100%;
width:100%;
top:0;
left:0;
background: -moz-linear-gradient(top, rgba(0,255,0,1) 0%, rgba(255,255,255,0) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,255,0,1)), color-stop(100%,rgba(255,255,255,0)));
background: -webkit-linear-gradient(top, rgba(0,255,0,1) 0%,rgba(255,255,255,0) 100%);
background: -o-linear-gradient(top, rgba(0,255,0,1) 0%,rgba(255,255,255,0) 100%);
background: -ms-linear-gradient(top, rgba(0,255,0,1) 0%,rgba(255,255,255,0) 100%);
background: linear-gradient(to bottom, rgba(0,255,0,1) 0%,rgba(255,255,255,0) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ff00', endColorstr='#00ffffff',GradientType=0 );
display:none;
content: ' ';
}
.wrap:hover::after {
display:block;
}
HTML:
<div class="wrap">
<img id="connectionRight_img" class="btn" src="imgs/trailEnd_turnRight.png" alt="Right Arrow"/>
</div>
This works fine for me. Still recommend not to use image as background if possible. It will slowdown the performance.
<style>
button.mylink { border-width:0px; text-align:center; width : 60px; height : 20; display: inline-block; background-image : url(imgs/trailEnd_turnRight.png); text-decoration:none }
button.mylink:hover { background-image : url(imgs/trailEnd_turnRight_hover.png) }
</style>
<button class="mylink" href="#">abc</button>

Multiple CSS3 backgrounds, replace top layer

I have a button with a background-image property that sets 1) an icon for the button and 2) a CSS3 background gradient. I would now like to override the background gradient further down the page, so the icon remains the same and I can create many button colours by simply overriding the background gradients.
Is there currently a way to override a specific layer of a multiple background property?
http://gard.me/1ulmH
HTML:
<a class="newButton blue" href="#">hello world</a>
CSS:
.newButton /* Orange by default */
{
margin: 20px;
display: inline-block;
padding: 12px 20px;
background: none;
background-repeat: no-repeat;
background-position: 9px 5px;
background-position: 9px 5px, 0 0;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
border-width: 1px;
border-style: solid;
font-family: Verdana, Arial, Sans-Serif;
text-decoration: none;
text-align: center;
/* Orange stuff */
color: #FFECEA;
border-color: #A03E33;
background-position: 0 0;
background-color: #E46553;
background-image: url('http://www.waveclothing.co.uk/media/Shopping%20Cart.png'), -o-linear-gradient(bottom, #D15039 0%, #F27466 100%);
background-image: url('http://www.waveclothing.co.uk/media/Shopping%20Cart.png'), -moz-linear-gradient(bottom, #D15039 0%, #F27466 100%);
background-image: url('http://www.waveclothing.co.uk/media/Shopping%20Cart.png'), -webkit-linear-gradient(bottom, #D15039 0%, #F27466 100%);
background-image: url('http://www.waveclothing.co.uk/media/Shopping%20Cart.png'), -ms-linear-gradient(bottom, #D15039 0%, #F27466 100%);
background-image: url('http://www.waveclothing.co.uk/media/Shopping%20Cart.png'), -webkit-gradient(linear, left bottom, left top, color-stop(0, #D15039), color-stop(1, #F27466));
}
.newButton.blue { /* Blue */ /* Here I need to overwrite the button background colour */
background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0, #0B3661), color-stop(1, #0E4479));
}
enter code hereYou need to give it the full image usage just like the original definition, because the new definition is going to overwrite the whole background. So
.newButton.blue {
background-image: url('http://www.waveclothing.co.uk/media/Shopping%20Cart.png'), -webkit-gradient(linear, left bottom, left top, color-stop(0, #0B3661), color-stop(1, #0E4479));
}
Updated:
If you really want to individually switch the gradients, then you need to either put a span element in the a tag to place your icon image into and set that background independently on the icon (span) and gradient (a) OR since the gradients are new browser technology, do those on a :before or :after pseudoelement set to sit below the a tag. Something like:
a {
position: relative;
z-index: 1;
...icon related background code here...
}
a:after {
content: '';
display: block;
position: absolute;
z-index: -1;
top: 0;
bottom: 0;
left: 0;
right: 0;
...gradient related background code here...
}
EDIT: Note, as I reread your original question, it appears you may want the gradient above the icon. If so, you need to swap the background code for what I gave above.
When you set a new value for "background-image" it fully overrides its previous definition. Only the last definition applied will prevail.
I suggest you include the icon url for every background-image definition.