Slide background color transition - html

I found this example from a thread here in stackoverflow.
aosgibmoa bnocibnas
a{
display:inline-block;
background:#fff;
position:relative;
padding:2px 5px;
background:-webkit-gradient(linear, left top, right top, color-stop(0.5, #fff), color-stop(0.5, #000));
background-size:200% 100%;
background-position:0 0;
-webkit-transition:background-position .3s ease-out;
}
a:hover{
background-position:100% 0;
}
http://jsfiddle.net/nsfxE/1/
But I'm not sure how to change the -webkit-gradient to other vendor prefix and the normal standard one.
I want to make sure that it is somewhat modern cross browser compatible.

background-image: -webkit-gradient(linear, left top, right top, color-stop(0.5, #fff), color-stop(0.5, #000));
background-image: -moz-linear-gradient(linear, left top, right top, color-stop(0.5, #fff), color-stop(0.5, #000));
background-image: -o-linear-gradient(linear, left top, right top, color-stop(0.5, #fff), color-stop(0.5, #000));
background-image: linear-gradient(linear, left top, right top, color-stop(0.5, #fff), color-stop(0.5, #000));
I hope this is what you want.

Well, I tried out and this is my answer. Hope this can be a reference to whoever is needed.
a{
display:inline-block;
background:#fff;
position:relative;
padding:2px 5px;
background:-webkit-gradient(linear, left top, right top, color-stop(50%, #fff), color-stop(50%, #000));
background:-webkit-linear-gradient(left, #fff 50%, #000 50%);
background:-moz-linear-gradient(left, #fff 50%, #000 50%);
background:linear-gradient(to right, #fff 50%, #000 50%);
background-size:200% 100%;
background-position:0 0;
-webkit-transition:background-position .3s ease-out;
-moz-transition:background-position .3s ease-out;
transition:background-position .3s ease-out;
}
a:hover{
background-position:-100% 0;
}
http://jsfiddle.net/nsfxE/215/
Now it should work in most modern browsers.
I never put Opera prefix because I tried that and it doesn't work. Standard syntax works just fine on Opera.

Related

Navigation menu is transparent, but i'm not sure why. I want a background

I'm using a wordpress template.
I have just added particles.js as my background.
Now my navigation menu is taking the same color as my background, but i want it to be a different color. (I have defined the color in my code but its not working)
Here is the codes i'm using and what i'm seeing.
https://imgur.com/a/6U5e7
.main-nav {
background-color: #585858;
background-image: -webkit-gradient(linear, left top, left bottom, from(#585858), to(#3d3d3d));
background-image: -webkit-linear-gradient(top, #585858, #3d3d3d);
background-image: -moz-linear-gradient(top, #585858, #3d3d3d);
background-image: -ms-linear-gradient(top, #585858, #3d3d3d);
background-image: -o-linear-gradient(top, #585858, #3d3d3d);
background-image: linear-gradient(to top, #585858, #3d3d3d);
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#585858, endColorstr=#3d3d3d)";
}
Try this:
position: relative;
z-index: 100;

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

IE10 does not display my gradient over my background

I am using an gradient with opacity as an brightness effect for JUST my background. Now it works in Chrome and Firefox but doesn't seem to work in IE10, but I did put the -ms- version there.
Here is my JSFiddle: >>>JSFiddle<<<
Here is the code:
<div id="lol">
</div>
-
#lol {
background-image:url('http://www.gettyimages.com/CMS/Pages/PhotoDiscFrontdoor/StaticContent/fd_image_test.jpg');
width:700px;
height:465px;
}
#lol:hover {
background: -moz-linear-gradient(top, rgba(255,255,255,.1) 0%, rgba(255,255,255,.1) 100%), url('http://www.gettyimages.com/CMS/Pages/PhotoDiscFrontdoor/StaticContent/fd_image_test.jpg');
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,255,255,.1)), color-stop(100%,rgba(255,255,255,.1))), url('http://www.gettyimages.com/CMS/Pages/PhotoDiscFrontdoor/StaticContent/fd_image_test.jpg');
background: -webkit-linear-gradient(top, rgba(255,255,255,.1) 0%,rgba(255,255,255,.1) 100%), url('http://www.gettyimages.com/CMS/Pages/PhotoDiscFrontdoor/StaticContent/fd_image_test.jpg');
background: -o-linear-gradient(top, rgba(255,255,255,.1) 0%,rgba(255,255,255,.1) 100%), url('http://www.gettyimages.com/CMS/Pages/PhotoDiscFrontdoor/StaticContent/fd_image_test.jpg');
background: -ms-linear-gradient(top, rgba(255,255,255,.1) 0%,rgba(255,255,255,.1) 100%), url('http://www.gettyimages.com/CMS/Pages/PhotoDiscFrontdoor/StaticContent/fd_image_test.jpg');
background: linear-gradient(to bottom, rgba(255,255,255,.1) 0%,rgba(255,255,255,.1) 100%), url('http://www.gettyimages.com/CMS/Pages/PhotoDiscFrontdoor/StaticContent/fd_image_test.jpg');
}
Does anyone know what is wrong with this code? Why doesn't it work in Internet Explorer 10?
Thanks in advance.

Input type="button" not overriding styles with class, but normal button is?

I have a button class that I'm using that overrides the gradients of my default button or input type="button" elements. Here is the code for the defaults:
input[type="button"], input[type="submit"], input[type="reset"], button {
background:#05ABE0;
background:linear-gradient(to bottom, #87E0FD 0%, #53CBF1 25%, #05ABE0 50%);
background:-moz-linear-gradient(top, #87E0FD 0%, #53CBF1 25%, #05ABE0 50%);
background:-ms-linear-gradient(top, #87E0FD 0%, #53CBF1 25%, #05ABE0 50%);
background:-o-linear-gradient(top, #87E0FD 0%, #53CBF1 25%, #05ABE0 50%);
background:-webkit-gradient(linear, left top, left bottom, color-stop(0%, #87E0FD), color-stop(25%, #53CBF1), color-stop(50%, #05ABE0));
background:-webkit-linear-gradient(top, #87E0FD 0%, #53CBF1 25%, #05ABE0 50%);
border:solid 2px #0076A3;
border-radius:0.3em;
-moz-border-radius:0.3em;
-o-border-radius:0.3em;
-webkit-border-radius:0.3em;
font-size:1em;
padding:0.4em;
display:inline-block;
margin-right:5px;
margin-left:5px;
font-family:Helvetica Neue, Helvetica, Arial, sans-serif;
color:white;
vertical-align:middle;
text-shadow:rgba(0, 0, 0, 0.7) 0px 2px 2px;
box-shadow:inset 0 1px 1px white;
-moz-box-shadow:inset 0 1px 1px white;
-webkit-box-shadow:inset 0 1px 1px white;
background-size:100% 200%;
-moz-background-size:100% 200%;
-o-background-size:100% 200%;
-webkit-background-size:100% 200%;
-moz-transition:all 0.1s linear;
-o-transition:all 0.1s linear;
-webkit-transition:all 0.1s linear;
}
Here is the override class:
.orange {
border:2px solid #BF4619;
background: #FF7700;
background:linear-gradient(to bottom, #FFD0A8 0%, #FFAE68 25%, #FF7700 50%);
background:-moz-linear-gradient(top, #FFD0A8 0%, #FFAE68 25%, #FF7700 50%);
background:-ms-linear-gradient(top, #FFD0A8 0%, #FFAE68 25%, #FF7700 50%);
background:-o-linear-gradient(top, #FFD0A8 0%, #FFAE68 25%, #FF7700 50%);
background:-webkit-gradient(linear, left top, left bottom, color-stop(0%, #FFD0A8), color-stop(25%, #FFAE68), color-stop(50%, #FF7700));
background:-webkit-linear-gradient(top, #FFD0A8 0%, #FFAE68 25%, #FF7700 50%);
background-size:100% 200%;
-moz-background-size:100% 200%;
-o-background-size:100% 200%;
-webkit-background-size:100% 200%;
}
When I use <button type="button" class="orange">Orange button</button> it works fine, but when I use <input type="button" class="orange" value="Orange button" /> it reverts to the default styling that is not in the orange class. Why is this?
PS: How do I do a multiline-indent on Stackoverflow? That's why my code is all in the same block in the example.
Leniel Macaferi is right, but he doesn't explain why. The reason is specificity, which determines cascade order for rules with the same importance and origin; in both CSS2 and CSS3, input[type="button"] has specificity 11, as it has one attribute selector and one type selector, while .orange has specificity 10, as it has one class selector. In the case of the button selector, the specificity is 1 as button is an element type, thus .orange overrides it. (In the case where specificity is the same, later selectors in the document take priority.)
Fix: use .orange.orange instead of .orange to obtain a specificity of 20, as repeated simple selectors are explicitly allowed in CSS3 (so it should work in most modern browsers, and any old ones that don't try to be smart and not increase specificity for repeated simple selectors).
Alternate fix: [type="button"] instead of input[type="button"] would instead reduce the specificity of the first rule, but could create problems if non-input elements in your HTML have type="button" set, as shown in this JSFiddle.
Usage of !important for each property would also solve your problem, but that's only really useful when the rule has one or two properties as you have to apply !important to each property.
More info:
http://www.w3.org/TR/2011/REC-CSS2-20110607/cascade.html#specificity
http://www.w3.org/TR/selectors/#specificity
Because you have input[type="button"] in the first CSS rule.
Your second button is an <input> element and that matches that 1st CSS rule.
Because and attribute selector (input[type="button"]) has a greater specificity than a classname.

Gradient that stops at a particular height and continues further with a solid color

I want to have a gradient in HTML/CSS.
Assume some DIV is always more than 400px tall. I want to add the gradient so that it is #FFFFFF at the top and #EEEEEE at 300px. So the first 300px (height-wise) is a nice 'white to grey' gradient. After 300px, regardless of how tall the DIV goes, I want the background color to stay #EEEEEE.
I guess this has something to do with gradient stops (?)
How can I do it?
P.S. If it is not possible in IE I don't care. I am fine if gecko and webkit browsers show this properly.
background-color: #eee;
background-image: linear-gradient(top, #fff 0%, #eee 300px); /* W3C */
background-image: -moz-linear-gradient(top, #fff 0%, #eee 300px); /* FF3.6+ */
background-image: -webkit-linear-gradient(top, #fff 0%, #eee 300px); /* Chrome10+,Safari5.1+ */
This is according to the current Mozilla documentation: https://developer.mozilla.org/en/CSS/-moz-linear-gradient.
I've confirmed that it works in Firefox 3.6 and Chrome 15.
Alternative way
background-color: #eee;
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#fff), to(transparent));
background-image: -webkit-linear-gradient(top, #fff, transparent);
background-image: -moz-linear-gradient(top, #fff, transparent);
background-image: -o-linear-gradient(top, #fff, transparent);
background-image: linear-gradient(to bottom, #fff, transparent);
background-repeat:no-repeat;
background-size:100% 300px;
height: 400px;
background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#eee), color-stop(0.75, #eee));
You might have to play with 0.75 as it's a percentage of your height, but that should do the trick.
First, it's good to know that you can use more than 2 color-stop on gradients, but you can't use fixed pixels as coordinates, it has to be a percentage.
In your case, you can simply define your first color-stop at 0% and the second one at 50% or so. I suggest you to use a gradient generator because the implementation depends on the browser.
I came up with
background: #FFFFFF; /* old browsers*/
background: -moz-linear-gradient(top, #FFFFFF 0%, #EEEEEE 50%); /* firefox */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#FFFFFF), color-stop(50%,#EEEEEE)); /* webkit */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFFFFF', endColorstr='#EEEEEE', GradientType=0); /* ie */
background: -moz-linear-gradient(top, #d7d7d7 0px, #f3f3f3 178px);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0px,#d7d7d7), color-stop(178px,#f3f3f3));
background: -webkit-linear-gradient(top, #d7d7d7 0px,#f3f3f3 178px);
background: -o-linear-gradient(top, #d7d7d7 0px,#f3f3f3 178px);
background: -ms-linear-gradient(top, #d7d7d7 0px,#f3f3f3 178px);
background: linear-gradient(top, #d7d7d7 0px,#f3f3f3 178px);
this works for me
The easiest solution for the problem is to simply use multiple backgrounds and give the gradient part of the background a defined size, either in percentage or in pixels.
body {
background: linear-gradient(to right, green 0%, blue 100%), green;
background-size: 100px 100%, 100%;
background-repeat: no-repeat;
background-position: right;
}
html,
body {
height: 100%;
margin: 0;
}
Mix and match with browser prefixes as necessary.
You could do a:
<div id="bgGen"></div>
then
#bgGen{
height: 400px;
background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#eee), color-stop(0.75, #eee));
margin-bottom:-400px;
}
It is kinda cheating, but it works...
I had the same thing just now. I wanted to put a gradient on the main content div which varied significantly in height from page to page.
I ended up with this and it works great (and not too much extra code).
CSS:
.main-container {
position: relative;
width: 100%;
}
.gradient-container {
/* gradient code from 0% to 100% -- from colorzilla.com */
height: 115px; /* sets the height of my gradient in pixels */
position: absolute; /* so that it doesn't ruin the flow of content */
width: 100%;
}
.content-container {
position: relative;
width: 100%;
}
HTML:
<div class="main-container">
<div class="gradient-container"></div> <!-- the only thing added for gradient -->
<div class="content-container">
<!-- the rest of my page content goes here -->
</div>
</div>
I highly recommend using colorzilla's gradient-editor to generate the CSS. It makes cross-browser optimizing really easy (especially if you're used to Photoshop or Fireworks).
this worked for me
background: rgb(238, 239, 240) rgb(192, 193, 194) 400px;
background: -webkit-linear-gradient(rgba(192, 193, 194, 1), rgba(238, 239, 240, 1) 400px);
background: -moz-linear-gradient(rgba(192, 193, 194, 1), rgba(238, 239, 240, 1) 400px);
background: linear-gradient(rgba(192, 193, 194, 1), rgba(238, 239, 240, 1) 400px);
background-repeat:repeat-x; background-color:#eeeff0;
Also someone commented why not just make a gradient image and set it as the background. I prefer to go mostly css now too, with mobile design and limited data usage for visitors, try to limit as much images as possible. If it can be done with css than do it