Is having many classes for little things bad?

hey folks,
i needed to clear this out. i have different input type field as well as textarea’s, few of them are like very small and few like with big width. i classes them up making element for each. but my question is, is it ok to have classes for each item. like the scenario i described above.
apart from this. what should be naming conversion for classes. how to have more generic names?

how to have more generic names?

To tell the truth, even though I really despise these sorts of names, there are templates who use really generic names when there are a bunch of items with just different widths and things:

class=“w70” for something with a width of 70 somethings (likely px)

So, I have seen stuff like this:

/inputs/
.w10 {
width: 10px;
}
.w70 {
width: 70px;
}
.w100 {
width: 100px;
}

etc.

I don’t like them but if you have classes who exist simply to make all these different widths, that’s one way (it’s at least readable to the next guy).

In my forms, I sometimes have inputs who expect only 2 or 4 characters. I put the size attribute on those, in the HTML, because the size of the input is feedback for the user, coupled with a maxlength… so because I consider the size to be part of the content in that context (yeah, I’m stretching the meaning here), I do that. Mostly just inputs who expect a number like “5”.

Any other width adjustments I make, I do in CSS. I have one site where I have many different widths for select dropdowns. For those, often a div would wrap a group of them, and that div would have a class. All selects inside that classed div got certain styles. This prevented me from having like 5 selects all together with the same class on them.

No they are perfectly fine :). They describe what is inside them/their job, thus fine :slight_smile:

i m bad at naming convensions classes. i have like mainnav,submenu,etc

If you need to style things differently then by all means use classes :). It’s not a sin ;).

In the scenario you described above, where you need different widths, that’s fine. If widths can be repeated, then repeat the class.

Use whatever naming convention you want, it honestly is up to you. Just don’t use presentation in the c lass names, aka if you are only adding a class to set a font color of red, don’t name the class .red{} :slight_smile:

Is it ok? Sure. What you do is completely up to you. But remember you have to maintain it. So it is advisable to do things that help you glance at a piece of code and instantly know what to do 5 to 10 years down the road. What is easiest for you to maintain and handle.