SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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?
    All those who wander aren't lost.

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    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.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,722
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    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{}
    Always looking for web design/development work.
    http://www.CodeFundamentals.com

  4. #4
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    i m bad at naming convensions classes. i have like mainnav,submenu,etc
    All those who wander aren't lost.

  5. #5
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,722
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    No they are perfectly fine . They describe what is inside them/their job, thus fine
    Always looking for web design/development work.
    http://www.CodeFundamentals.com

  6. #6
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,283
    Mentioned
    51 Post(s)
    Tagged
    2 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •