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 1049617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:38:43+00:00 2026-05-16T16:38:43+00:00

Given <div class=foo> <span class=bar></span> </div> I’ve always defined the CSS classes as: .foo

  • 0

Given

<div class="foo">
    <span class="bar"></span>
</div>

I’ve always defined the CSS classes as:

.foo
{

}
.bar
{

}

Is specifying the object important, or ultimately for readability so you can quickly see which sort of element you are searching for when editing? IE:

div.foo
{

}
span.bar
{

}
  • 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-16T16:38:44+00:00Added an answer on May 16, 2026 at 4:38 pm

    It will be important for element specificity.

    .foo targets any element that has a class of "foo".

    div.foo targets only <div>s that have a class of "foo". That means other elements with that class aren’t selected.

    If you’re sure only one kind of element will ever bear a given class, I guess there’s nothing wrong with prefixing the class selector with the element name for readability, or leaving it out completely if you’re lazy to type.

    However, if you think other elements might bear this class — for instance if it’s a pretty generic name like left, larger-font or sep, it’s a good idea to do this so you’re sure you’re styling the right elements.

    If there are any common styles shared by any elements with a given class, you specify just the class selector and add the common styles there, then after that specify any styles that pertain to each individual element. For example:

    .foo { /* Generic styles for foo class */ }
    div.foo { /* Styles for <div>s with foo class */ }
    blockquote.foo { /* Styles for <blockquote>s with foo class */ }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following HTML: <div class=foo>howdy howdy howdy how</div> <div class=bar>Hello</div>​ and the following
Given the following mark-up... <div id=Header> <a href=# class=Highlight>foo</a> </div> And the following stylesheet...
Given the following html: <div id='foo'> <div class='prodbar'> <div class='title'>Group 1</div> <div class='product'>Product #1</div>
Given this HTML: <div id=TABLE1 class=tabs> <table> <tbody datasrc=Music> <tr id=randomid>lorem</tr> <tr id=foo>lorem</tr> <tr
Consider the following HTML: <div class=foo id=obj> I should be changed red <div class=bar
given the following div element <div class=info> <a href=/s/xyz.html class=title>title</a> <span class=a>123</span> <span class=b>456</span>
Given an element like <div class=A B></div> where the classes of the div are
Possible Duplicate: How to access this attribute using jquery, given a div defined by
Given markup like this: <div class=a>A</div> <div class=b>B</div> <div class=a>A</div> <div class=b>B</div> <div class=a>A</div>
Given this html: <div class=nation> <a href=library.php?type=nation&amp;id=America> <div class=nation-image> <img src=nations/America.png alt=snip /> </div>

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.