Gradient style for <select> tag? - css

I'm trying to create a form where the background of the input fields are styled with a gradient background. It succeds for all <input> tags, but not for the <select> tag. Can this be done? Am I doing something wrong?
The CSS I'm using:
form#contact input[type="text"], input[type="url"],
input[type="email"], input[type="tel"], textarea, select {
margin: 3px 0 0 0;
padding: 6px;
width: 260px;
font-family: arial, sans-serif;
font-size: 12px;
border: 1px solid #ccc;
background: -webkit-gradient(linear, left top, left 15, from(#FFFFFF), color-stop(4%, #f4f4f4), to(#FFFFFF));
background: -moz-linear-gradient(top, #FFFFFF, #f4f4f4 1px, #FFFFFF 15px);
}
See the image below.

Styling <select> is difficult since browsers try and render the control to match the OS. You could add -webkit-appearance: none; to enable the gradient but that will also remove the arrow.
See Add gradient to select box w/ CSS3 in chrome? and Background Image for Select (dropdown) does not work in Chrome
Or if you can use jQuery or Prototype, I highly recommend the excellent Chosen plugin in which the <select> is replaced by a dropdown that can be styled.
Edit: I have to add the styling form elements is sometimes frowned upon. Eric Meyer's article on the subject is good background reading.

You may have a problem with this due to the operating system and Internet Browser you are using.
One easy way of getting round this is by using a JQuery library called Uniform. It allows you to style form elements how you want and is cross-browser compatible.
You can find more information on this here: http://uniformjs.com/.
I hope that helps.

Have you tried to debug that in firebug?
How about making the backgrounds important?
form#contact input[type="text"], input[type="url"],
input[type="email"], input[type="tel"], textarea, select {
margin: 3px 0 0 0;
padding: 6px;
width: 260px;
font-family: arial, sans-serif;
font-size: 12px;
border: 1px solid #ccc;
background: -webkit-gradient(linear, left top, left 15, from(#FFFFFF), color-stop(4%, #f4f4f4), to(#FFFFFF)) !important;
background: -moz-linear-gradient(top, #FFFFFF, #f4f4f4 1px, #FFFFFF 15px) !important;
}

Related

asp:Button with a self-created icon on the left, text to the right, and gradient background

I have created a small (10px by 16px) .png icon with transparent background and want this to be on the left side of all my asp:Button elements. The button text shall then appear to the right of this icon. The problem is that I'm using a background gradient and don't know if what I want is possible (for me) at all. Maybe you can help me out. Here is an example that I tried to copy, but it didn't work; the background was at first repeated and I didn't see transparency at all; setting background-repeat: no-repeat fixed the repeating but not the transparency (there was neither text nor gradient background to be seen). Here's the code I tried (it's for IE10+ only):
<style type="text/css">
.myButton {
vertical-align: central;
font-family: Consolas;
font-size: 14px;
font-weight: 500;
border-top-right-radius: 5px;
background: -ms-linear-gradient(top, #ff0000 0%,#00ff00 100%);
background-image: url("MyIcon.png");
background-repeat: no-repeat;
color: white;
border: none;
padding-top: 5px;
padding-right: 5px;
padding-bottom: 0px;
padding-left: 0px;
}
.myButton:hover {
background: -ms-linear-gradient(top, #374a9a 50%,#061671 100%);
}
</style>
As an example of how it's supposed to look, check this. There are some dark blue buttons that have an icon on the left like I need it. Do I maybe have to use an ImageButton instead of a simple Button (which I wouldn't like), or is there an easier solution?

Why would the same browser render two buttons with the same CSS differently?

I need button which has more bling than a standard browser rendering, and because I am not a designer, I thought I'd use an existing solution. So, I went to a button maker I found on the Internet, and it made me a button which looks good. I copied the CSS, and my own button looks differently in my browser. On Inspect Element, the CSS is the same.
Their button looks like this:
And it has following rules applied:
My button looks uglier, because it gets a large border on all sides:
But when I look at the CSS, there is no difference to the applied rules. And while my element is an input, I also have "real" buttons on my page, and they show the same behavior.
I tried running my page with or without a resetting CSS, but this made no difference. I always get the ugly look.
When I run their code in a fiddle, I get the same ugly result.
This happens in two different tabs of the same browser on the same machine, a Firefox 29.
Here again the problematic code:
button {
border-top: 1px solid #bfd1ed;
background: #5987d1;
background: -webkit-gradient(linear, left top, left bottom, from(#2662c3), to(#5987d1));
background: -webkit-linear-gradient(top, #2662c3, #5987d1);
background: -moz-linear-gradient(top, #2662c3, #5987d1);
background: -ms-linear-gradient(top, #2662c3, #5987d1);
background: -o-linear-gradient(top, #2662c3, #5987d1);
padding: 5px 10px;
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
-webkit-box-shadow: rgba(0,0,0,1) 0 1px 0;
-moz-box-shadow: rgba(0,0,0,1) 0 1px 0;
box-shadow: rgba(0,0,0,1) 0 1px 0;
text-shadow: rgba(0,0,0,.4) 0 1px 0;
color: #ffffff;
font-size: 14px;
font-family: Georgia, serif;
text-decoration: none;
vertical-align: middle;
}
button:hover {
border-top-color: #2662c3;
background: #2662c3;
color: #bdbdbd;
}
button:active {
border-top-color: #2662c3;
background: #2662c3;
}
body {
background-color: #555555;
}
The difference is you're using a button element.
Us a span element and you'll get the same result.
Demonstration
You might also take the opposite approach and try to reset the button's style but in my opinion it's easier to style a span than to remove those styles.
Just put border: none; on your button:
http://jsfiddle.net/wn7vh/
Hope that helps.
Thats because you use the wrong HTML tag
the css in your example is for an element with the class "button"
and if you look at the example in the button builder, you will see that they don't use:
<button name="My button"> A button! </button>
but they use a link tag and style it like a button:
<a class="button" name="My button" href="#">A button!</a>
so if you use the second version for the button, it will look like the example in the button builder

input[type="button"], input[type="submit"], button CSS not behaving properly

I'm trying to get this to work but there's still something not right.
I want to style the submit buttons with css to match the ones i already have.
<input type="submit" name="save_settings" value="Opslaan">
Style:
input[type="button"], input[type="submit"], button
{
background: url("http://gasterijdebakker.nl/email/php/pages/images/layout/bg-btn-left.png") no-repeat scroll left top transparent;
display: inline-block;
line-height: 35px;
padding:7px 0 15px 12px;
margin:0;
border:0;
color: #FFFFFF;
font-size: 15px;
font-weight: bold;
letter-spacing: -1px;
text-shadow: 0 1px 1px #70A7E0;
}
jsFiddle
You would be better off not using the background image and using css3 gradient instead. Something like:
input[type="button"], input[type="submit"], button
{
background-color: #a3d4ff;
background-image: -webkit-gradient(linear, left top, left bottom, from(#a3d4ff), to(#88bcf2));
background-image: -webkit-linear-gradient(top, #a3d4ff, #88bcf2);
background-image: -moz-linear-gradient(top, #a3d4ff, #88bcf2);
background-image: -o-linear-gradient(top, #a3d4ff, #88bcf2);
background-image: linear-gradient(to bottom, #a3d4ff, #88bcf2);
border-radius:3px;
display: inline-block;
line-height: 22px;
padding:7px 12px;
margin:0;
border: 1px solid #88bcf2;
color: #FFFFFF;
font-size: 15px;
font-weight: bold;
letter-spacing: -1px;
text-shadow: 0 1px 1px #70A7E0;
cursor:pointer;
}​
input elements can't be styled completely.
Instead, use a button element.
button elements are much easier to style than input elements. You can add inner HTML content (think em, strong or even img), and make use of :after and :before pseudo-element to achieve complex rendering while input only accept a text value attribute.
source:
Mozilla Developer Network
https://developer.mozilla.org/en-US/docs/HTML/Element/button

CSS3 button renders differently on web vs iOS

I found some code for generating CSS3 buttons which I'm using on my site. The buttons look great when viewed in the browser. However, on the mobile web version of my site (which uses the same styles) the buttons render differently. Even stranger, if I use Safari and view my site with User Agent of iPhone the buttons look as they should. However in iOS Simulator they don't. Can someone help me understand why?
Here's the code I'm using:
.button, #button .button, li.button .button {
display: inline-block;
zoom: 1;
*display: inline;
vertical-align: baseline;
outline: none;
cursor: pointer;
text-align: center;
text-decoration: none;
font: 14px/100% Arial, Helvetica, sans-serif;
padding: .5em 1.5em .55em;
text-shadow: 0 1px 1px rgba(0,0,0,.3);
-webkit-border-radius: .5em;
-moz-border-radius: .5em;
border-radius: .5em;
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.2);
-moz-box-shadow: 0 1px 2px rgba(0,0,0,.2);
box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.orange, #button .orange {
color: #fef4e9;
border: solid 1px #da7c0c;
background: #f78d1d;
background: -webkit-gradient(linear, left, top, left bottom, from(#faa51a), to(#f47a20));
background: -moz-linear-gradient(top, #faa51a, #f47a20);
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#faa51a', endColorstr='#f47a20');
}
Here is how it renders in the browser:
And here is how it renders on an iPhone:
Apply "-webkit-appearance:none;" on your css properties and add this line
"input[type=submit], input[type=Reset]{ -webkit-appearance:none; }".
As Shakti says you should just put the following css for the button.
-webkit-appearance: none;
This is explained further in this question:
'CSS submit button weird rendering on iPad/iPhone'
It seems that on iOS the buttons have the default iOS rounded look if you supply just a simple background color :
background: orange
But if you supply a gradient then this is effectively overriding the appearance css property to use a custom style.
But because you had the wrong syntax it was giving you the iOS look.
I caught my mistake. I had the wrong syntax for -webkit-gradient. Instead of:
-webkit-gradient(linear, left, top, left bottom, from(#faa51a), to(#f47a20));
It's...
-webkit-gradient(linear, left top, left bottom, from(#faa51a), to(#f47a20));
I had a comma between left and top where it shouldn't have been.
Have you tried using an SVG as your background image (generator can be found here)? Using this worked on an iPhone 3G I have lying around (jsFiddle link here):
background-image:url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIHZpZXdCb3g9IjAgMCAxIDEiIHByZXNlcnZlQXNwZWN0UmF0aW89Im5vbmUiPgo8bGluZWFyR3JhZGllbnQgaWQ9Imc5MDQiIGdyYWRpZW50VW5pdHM9InVzZXJTcGFjZU9uVXNlIiB4MT0iMCUiIHkxPSIwJSIgeDI9IjEwMCUiIHkyPSIxMDAlIj4KPHN0b3Agc3RvcC1jb2xvcj0iI0ZBQTUxQSIgb2Zmc2V0PSIwIi8+PHN0b3Agc3RvcC1jb2xvcj0iI0Y0N0EyMCIgb2Zmc2V0PSIxIi8+CjwvbGluZWFyR3JhZGllbnQ+CjxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIGZpbGw9InVybCgjZzkwNCkiIC8+Cjwvc3ZnPg==);
This is compatible with IE9, Chrome, Safari and Opera. This will not work with IE7/8. What I suggest is using an IE specific stylesheet or adding to the .orange class instructions to apply the style to IE7 or IE8 and below. More info on that here.

How to create a button with gradient background and background image?

i'm trying to use some jquery client side validation for my asp.net 2.0 webform.
and it seems that the normal input submit button can easily trigger the validation on click.
but i'm currently using a three divs made up image button for this page, thus it doesn't auto trigger the validation.
i was looking at css3 and found that it now support gradient, it's all nice and good except for the fact that i need to show an arrow image on the right side of the button.
i've tested with normal background image and background color to setup a button and it works. but i can't seems to get the same thing to work for a gradient background and a background image.
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Droid Sans">
<style>
.button{
-webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.25, rgb(88,73,229)),
color-stop(0.63, rgb(115,103,255)),
color-stop(0.82, rgb(150,134,255))
);
-moz-linear-gradient(
center bottom,
rgb(88,73,229) 25%,
rgb(115,103,255) 63%,
rgb(150,134,255) 82%
);
color:#FCD3A5;
-webkit-border-radius: 5px;
-moz-border-radius: 10px;
font: 12px;
width:140px;
line-height: 28px;
height: 28px;
font-weight: bold;
font-family:"Droid Sans",serif;
}
.orange{
background:-moz-linear-gradient(center top , #FF9300, #FF6800) repeat scroll 0 0 transparent;
border:1px solid #CFCFCF;
color:#FFFFFF;
font: 12px;
width:140px;
line-height: 28px;
height: 28px;
font-family:"Droid Sans",serif;
background-image:url(arrow_right.png);
background-repeat: no-repeat;
background-position:right;
}
.button2{
background-color:#2daebf;
background-image:url(arrow_right.png);
font: 12px;
width:140px;
line-height: 28px;
height: 28px;
font-weight: bold;
color: white;
font-family:"Droid Sans",serif;
background-repeat: no-repeat;
background-position:120px;
border: 0px;
-webkit-border-radius: 5px;
-moz-border-radius: 10px;
-moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.25);
}
.button3{
background: green; /* fallback for older/unsupporting browsers */
background:-webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.25, rgb(88,73,229)),
color-stop(0.63, rgb(115,103,255)),
color-stop(0.82, rgb(150,134,255))
);
background:-moz-linear-gradient(
center bottom,
rgb(88,73,229) 25%,
rgb(115,103,255) 63%,
rgb(150,134,255) 82%
);
border-top: 1px solid white;
background-image:url(arrow_right.png);
background-repeat: no-repeat;
background-position:120px;
}
</style>
</head>
<input class="button3" type="submit" value="SUBMIT"/ >
</html>
any ideas?
Google's Gmail/Docs/etc UI buttons accomplish this using some CSS trickery. You can see someone else's implementation here:
http://todc.github.com/css3-google-buttons/#button
Basically the buttons are actual href anchors <a> with gradients applied to them. Then there is a separate style that sets the background to an image using the ::before psuedo-selector. It's a little tricky to re-implement but it's obviously possible.
Can't be done: see this article
Mozilla currently only supports CSS gradients as values of the background-image property, as well as within the shorthand background. You specify a gradient value instead of an image URL.
I'm sure webkit (safari/chrome) is probably the same way. IE doesn't support gradients.
My suggestion would be to wrap your submit button in a div element. Apply the gradient to the submit button, and the background image to the div and add a little padding to space it properly where needed. Or, use a <label> element for your submit button and apply the background images to the label.

Resources