6

I'm using CSS to style my HTML page.

Can I with selector:

form input[type="text"]

change the form of one input the type text? Just one et the others are with this CSS?

5
  • 2
    please provide more info about your issue.. Commented Jun 25, 2015 at 10:53
  • 1
    Change the form of one input type text. What does that mean? With that selector you select ALL <input/> elements that are inside a <form> and have type="text" Commented Jun 25, 2015 at 10:54
  • yes, with this selector I select all the inputs of type text. Can I change the form, using another selector for just 1 input the type text? Commented Jun 25, 2015 at 10:57
  • I have add a class to this input, and it do the css with it, but it doesn't take my new css, just the general: form input[type="text"]! Commented Jun 25, 2015 at 10:59
  • So you have a class for that input but you are trying to apply more general CSS with the selector in your question? But the input is not picking up on that? Might be because your new selector is further down the CSS file or more specific than your class is Commented Jun 25, 2015 at 11:03

3 Answers 3

15

I don't really get your question. But you have a few options

Will style every input typed text. <input type="text" />

form input[type="text"] {}

Will style the level first only input typed text

form >input[type="text"] {}

Will style the first only input

form input[type="text"]:first-child {}

Will style the input typed text with class "foo"

form input.foo[type="text"] { }

So. Lets say you have a form

<form action="" method="POST">
<input type="text" name="text" class="foo" />
<input type="text" name="text2" class="bar" />
</form>

This will target all inputs

form input[type="text"] { border:2px solid #000000; }

This will target only the first input with the class "foo"

form input.foo[type="text"] { background-color:red; }

This will target the second input with the class "bar"

form input.bar[type="text"] { background-color:green; }

Click here to view on CodePen

Sign up to request clarification or add additional context in comments.

1 Comment

That's exactly what I had tried and it didn't work. But now it work! Thanks for your good explanations, I'm sorry for my stupid question!!
1

You can use

input[type="text"]
input[type="button"]
input[type="password"]
input[type="number"]
input[type="email"]

For Example

input[type="text"] {
    width: 150px;
    display: block;
    margin-bottom: 10px;
    background-color: yellow;
}

W3School Attribute Selector

2 Comments

This doesn't answer the question as OP already knows he/she can use that selector. And second, there is no input type="mail"it is email
@putvande thats what i explain with an example
0

Here's a method that resets all input elements of the form, as long as an input is type of text. It's part of search form, you can use console.log to view current element name/value For the instance, you could use similar approach to style elements from your form

resetForm(e) {
  const searchInput = this.formSearchUser.querySelectorAll('input[type="text"]');
  searchInput.forEach((elt) => {
    console.log(`${elt.name} = ${elt.value}`);
    if (elt.name !== "siteCode" || elt.name !== "expiredUsers") 
      elt.value = '';        
  });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.