Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1004571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:09:19+00:00 2026-05-16T08:09:19+00:00

I wonder what fits better into the CSS philosophy: CSS classes mark entities –

  • 0

I wonder what fits better into the CSS philosophy:

  1. CSS classes mark entities
    – OR –
  2. CSS classes mark aspects

For example let’s take the cell for a product price sheet and a footer cell which contains the sum of all prices.

In the first case each of the cells would only have one class: product-price resp. product-price-sum (or price and the row for example has a product class)
In other words: Classes identify things.

In case two the cells would have many classes, which define the properties/aspects of a product price, for example numeric and currency and an additional sum class for the footer. numeric would define the text to be right aligned, sum would mark the cell bold.
In other words: Classes describe things.

I can’t decide which approach is better. In the past I used a mixture of both which quickly led to an ugly pile of unstructured CSS classes with conflicting styles and some ugly !important hacks.

The first approach obviously has some redundancy, because one would have many classes (product-*) and most of them would share common CSS properties.

The second one has problems when it comes to format just one place differently, let’s say the product price sum. It can be possible that there are other places which also have the exact same three classes assigned, but don’t have anything to do with a product price. In that case one would have to use the surrounding HTML tags to somehow “address” the specific place in the HTML file.

Are there any rules of thumb, guidelines, proven concepts, etc on how to handle this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:09:20+00:00Added an answer on May 16, 2026 at 8:09 am

    Just an observation… People tend to forget that CSS is hierarchical. Let me give you a very simple sample (please the tags are reduced to the minimum):

    <table class="product">
        <thead>
            <tr><th>Name</th><th class="price">Price</th></tr>
        </thead>
        <tbody>
            <tr><td>Product 1</td><td class="price">1</td></tr>
            <tr><td>Product 2</td><td class="price">2</td></tr>
            <tr><td>Product 3</td><td class="price">3</td></tr>
        </tbody>
        <tfoot>
            <tr><td>Total</td><td class="price">6</td></tr>
        </tfoot>
    </table>
    

    you can compose class styles with tag style to pin where the style will be aplied:

    table { /* styles for all tables */ }
    .product { /* styles for the product table */ }
    .product thead { /* styles for the all product table header row */ }
    .product thead th{ /* styles for header row generic column */ }
    .product thead .price { /* styles for header row price column */ }
    .product tbody { /* styles for the all product table data row */ }
    .product tbody td { /* styles for data row generic column */ }
    .product tbody .price { /* styles for data row price column */ }
    .product tfoot { /* styles for the all product table summarize row */ }
    .product tfoot td { /* styles for summarize row generic column */ }
    .product tfoot .price { /* styles summarize row price column */ }
    

    Or you can use only simple table tags (no th, thead, tbody and tfoot tags) like this:

    <table class="product">
        <tr class="header"><td>Name</td><td class="price">Price</td></tr>
        <tr class="data"><td>Product 1</td><td class="price">1</td></tr>
        <tr class="data"><td>Product 2</td><td class="price">2</td></tr>
        <tr class="data"><td>Product 3</td><td class="price">3</td></tr>
        <tr class="footer"><td>Total</td><td class="price">6</td></tr>
    </table>
    

    And the CSS would be

    .product { /* styles for the product table */ }
    .product .header { /* styles for the all product table header row */ }
    .product .header td{ /* styles for header row generic column */ }
    .product .header .price { /* styles for header row price column */ }
    .product .data { /* styles for the all product table data row */ }
    .product .data td { /* styles for data row generic column */ }
    .product .data .price { /* styles for data row price column */ }
    .product .footer { /* styles for the all product table summarize row */ }
    .product .footer td { /* styles for summarize row generic column */ }
    .product .footer .price { /* styles summarize row price column */ }
    

    This is not a final solution. Just a new approach to the problem.

    Remember also that you can indicate some states or additional information to the CSS using custom attributes. See this sample:

    <table class="product">
        <tr class="header"><td>Name</td><td class="price">Price</td></tr>
        <tr class="data"><td>Product 1</td><td class="price">1</td></tr>
        <tr class="data" selected="selected"><td>Product 2</td><td class="price">2</td></tr>
        <tr class="data"><td>Product 3</td><td class="price">3</td></tr>
        <tr class="footer"><td>Total</td><td class="price">6</td></tr>
    </table>
    

    See that the “selected” attribute at the “tr” tag has no effect in the standard renderization of the table since it is not a recognized attribute of the tag, but it can be identified by the CSS (and also by the javascript which is not the case here). Like this:

    .product tr[selected=selected] { /* styles for the selected row */ }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 545k
  • Answers 545k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • added an answer Well, start off by thinking of which bits of data… May 17, 2026 at 9:17 am
  • added an answer For this task it is a good idea to use… May 17, 2026 at 9:15 am
  • added an answer This is exactly how the Skyhook database (built into many… May 17, 2026 at 9:15 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.