Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS styles for input elements named dynamically

Tags:

html

css

I have:

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

That's been populated using php. Inside a for loop there's:

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

As I don't know the number of inputs that are going to be created, how can I give styles to them?

like image 270
ADM Avatar asked Sep 13 '26 18:09

ADM


2 Answers

If they are all going to have the same style, you could use classes. For example:

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


And in the CSS you can style the elements like this:

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


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

like image 60
Michiel Pater Avatar answered Sep 16 '26 08:09

Michiel Pater


HTML:

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

CSS:

.anything {
...
}
.you {
...
}
.want {
...
}
like image 22
fabrik Avatar answered Sep 16 '26 06:09

fabrik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!