CSS styles for dynamic input elements

I have:

    <input type="text" id="email[1]" name="email[1]"> 
    <input type="text" id="email[2]" name="email[2]">
.
. 

This has been populated with php. Inside the for loop there is:

echo "<input type='text' id='email[".$i."]' name='email[".$i."]'> ";

How I don’t know the number of inputs to be created, how can I give them styles?

+3
source share
2 answers

If they all have the same style, you can use classes. For instance:

echo "<input type='text' class='emailinput' id='email[".$i."]' name='email[".$i."]' /> ";


And in CSS you can style these elements:

.emailinput
{
    width:              20px;
    background-color:   red;
}


By the way, I added a slash to the end of the input element. This is for valid XHTML code. You must do this for all input elements ( />).

+5
source

HTML:

<input class="anything you want" ... />

CSS

.anything {
...
}
.you {
...
}
.want {
...
}
+4
source

All Articles