3

I have an issue on styling different form fields with CSS

I have a CSS code:

#form input {border: 1px solid #FFFFFF;font-size: 16px;padding: 5px;width: 200px;}

Now this code styles all three of the Input fields I have (below) but also styles the image submit button I have

<input type="text" class="text" name="email" id="email">
<input type="password" value="" name="password" id="password">
<input name="button" type="image" src="go.jpg" alt="Submit" align="right">

So then I change the CSS and create:

#form input.text {border: 1px solid #FFFFFF;font-size: 16px;padding: 5px;width: 200px;}
#form input.button {border: 0px)

This prevents the CSS styling of the image submit button but now it is not styling the password field - so I tried:

#form input.text {border: 1px solid #FFFFFF;font-size: 16px;padding: 5px;width: 200px;}
#form input.password {border: 1px solid #FFFFFF;font-size: 16px;padding: 5px;width: 200px;}
#form input.button {border: 0px)

But this had no affect.

So the question is, how can I effectively allow the CSS styling on the input text and input password fields - but not to style the image submit button?

Thanks in advance!

Evan Teran
  • 87,561
  • 32
  • 179
  • 238
Geo Man
  • 31
  • 1
  • 1
  • 2

8 Answers8

1

What you need to research is css selectors: CSS selector for text input fields?.

#form input[type="text"] {
    border: 1px solid #FFFFFF;
    font-size: 16px;
    padding: 5px;width: 200px;
}
#form input[type="password"] {
    border: 1px solid #FFFFFF;
    font-size: 16px;
    padding: 5px;
    width: 200px;
}
#form input[type="button"] {
    border: 0px;
}
Community
  • 1
  • 1
Nicolás Ozimica
  • 9,481
  • 5
  • 38
  • 51
1

There is an option you can add

For your text fields

#form input[type=text] {}

For your password fields

#form input[type=password] {}

For your button fields

#form input[type=button] {}

Or just add a class to your password field, which is password.

Niels
  • 48,601
  • 4
  • 62
  • 81
0

FORM "inputs" in CSS:

Text input:

input[type="text"] {...} /* normal (one row) text input */
textarea {...} /* multiline text input */
input[type="password"] {...} /* password masked input */

Button:

input[type="button"] {...}
input[type="submit"] {...} /* type of button - submitting the form */
input[type="reset"] {...} /* clean (reset) whole form "inputs" */

Checkbox:

input[type="checkbox"] {...}

Radiogroup:

input[type="radio"] {...}

Dropdown list:

select {...}
select optgroup{...} /* group od values in dropdown list */
select option{...} /* value to choose in dropdown list */
procma
  • 1,174
  • 3
  • 14
  • 24
0

just remove second line on your css and add "text" class to your password type input. CORRECT VERSION BELOW:

CSS:

#form input.text {border: 1px solid #FFFFFF;font-size: 16px;padding: 5px;width: 200px;}
#form input.button {border: 0px)

HTML:

<input type="text" class="text" name="email" id="email">
<input type="password" value="" name="password" id="password">
<input name="button" type="image" src="go.jpg" alt="Submit" align="right">
v.orujov
  • 46
  • 1
  • 5
0

Use the type of the input as part of your selector:

#form input[type="text"] {
    border: 1px solid #FFFFFF;
    font-size: 16px;
    padding: 5px;
    width: 200px;
}

This is the attribute selector.

You could always just add a class for your input boxes:

<input type="text" class="styled" name="email" id="email">
<input type="password" value="" class="styled" name="password" id="password">

With:

#form input.styled {
    border: 1px solid #FFFFFF;
    font-size: 16px;
    padding: 5px;
    width: 200px;
}
Bojangles
  • 99,427
  • 50
  • 170
  • 208
0

You're missing the .password and .button classes on your html.

<input type="text" class="text" name="email" id="email">
<input type="password" class="password" value="" name="password" id="password">
<input name="button" class="button" type="image" src="go.jpg" alt="Submit" align="right">
Doozer Blake
  • 7,677
  • 2
  • 29
  • 40
0

You didn't put a class on your inputs? .passwords means class="password" in your html

0

You could do this

Do not style the input element on its own, but instead target only those elements you want.

First, get rid of this css

#form input {/* styles here*/}

Then do this

#form input.text, #form input#password{
    border: 1px solid #FFFFFF;
    font-size: 16px;
    padding: 5px;
    width: 200px;
}

The comma separates the two elements but applies the css to each.

Then you don't need to "reset" the border on the image submit button.

By the way, your password input has an id according to your code and not a class, so you need the # instead of the ..

Jason Gennaro
  • 34,535
  • 8
  • 65
  • 86