Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradient style for <select> tag?

Tags:

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.

See the image below

like image 602
Daniel Avatar asked Aug 15 '11 14:08

Daniel


People also ask

What are the three main types of gradients in CSS?

You can choose between three types of gradients: linear (created with the linear-gradient() function), radial (created with the radial-gradient() function), and conic (created with the conic-gradient() function).

What is gradient color in HTML?

CSS gradients let you display smooth transitions between two or more specified colors. CSS defines three types of gradients: Linear Gradients (goes down/up/left/right/diagonally) Radial Gradients (defined by their center)

Can we give gradient to text in CSS?

For example color: linear-gradient(yellow, red) won't work. But gradient text can be achieved in CSS, it just requires a few extra steps. It's best to start with some big bold text. This will make the gradient more visible and the text more readable.

How do you put a gradient on text in CSS?

To add a gradient overlay to a text element, we need to set three different CSS properties to the text we want to style: background-image: <gradient> background-clip: text. text-fill-color: transparent.


2 Answers

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.

like image 189
andyb Avatar answered Nov 09 '22 00:11

andyb


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.

like image 45
Adam Stacey Avatar answered Nov 09 '22 02:11

Adam Stacey