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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:33:53+00:00 2026-06-16T21:33:53+00:00

I’m using Sass to compile my SCSS stylesheets into a single assembled.css to reduce

  • 0

I’m using Sass to compile my SCSS stylesheets into a single assembled.css to reduce HTTP requests. To namespace individual pages for styling, I wrap each page-specific CSS file in an ID selector for that page’s <body> element – for example:

body#support {

    .introduction {
        @extend %dropcap;
    }

}

In nanoc (using ERB), I have a helper that assigns each page’s body a dash-separated unique ID based on the HTML folder structure, so the root pages will be #support or #products, while their sub-pages would have an ID like `#products-giantspacelaser’.

I want to make a set of SCSS rules that only apply to these ‘products’ sub-pages (not including the root-level #products page itself). Is there anything I should look out for regarding specificity if I use an attribute selector instead of an ID for this, as follows?

body[id^="products-"] {

    .introduction {
        @extend %dropcap;
    }

}

I really don’t want to use !important, but I do want to ensure that these page-specific rules take precedent over styles set in the ‘_base.scss’ partial that precedes them in the @import order. Seeing as I have full control over the HTML structure, I could also theoretically use Erb in the Sass files to substitute in a comma-separated list of IDs like so:

body#products-giantspacelaser,
body#products-laboratorycamouflage,
body#products-resurrecteddinosaur {

    .introduction {
        @extend %dropcap;
    }

}

– but that seems quite inelegant. Thanks in advance.

EDIT:

I’ve written my other styles in a really cascade-reliant way:

  1. Normalise CSS
  2. HTML5 Boilerplate’s & my own sensible house rules
  3. CSS Libraries (in this case Bourbon & Neat)
  4. A “_source.scss” which in turn imports its own mixins & placeholder selectors.
  5. A “_base.scss” which styles the default layout framework of every page.
  6. A series of .scss files for each page’s individual content styling – and, I hoped, overrides of base.scss layout decisions when necessary (if the page needs to take a serious departure from the norm).

Either way, these individual page stylesheets would need to definitely have a higher specificity than earlier defaults, as they were written for a specific purpose & page.
I’m intentionally not using any ID selectors except for this one specific purpose – namespaceing page stylesheets.

Using, say

.services .sharktraining .introduction .disarmingJoke {}  --0,0,4,0

in “_base.scss” would surpass

body[id^="products-"] .disarmingJoke {}                   --0,0,2,1

in a further-down-the-cascade “products.scss”, wouldn’t it? (N.B. I know needing to use four classes is awful practice, I just don’t want to worry about something slipping through the namespace).

I suppose there’s another – really dirty – option: to repeat the body[id^="products-"] selector many times, to simply outnumber even the most specific class-strength rule.

  • 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-06-16T21:33:54+00:00Added an answer on June 16, 2026 at 9:33 pm

    It’s going to have to depend on how you’ve written your other styles and whether or not they should take precedence (see: http://coding.smashingmagazine.com/2007/07/27/css-specificity-things-you-should-know/).

    If you match the selector exactly but prefix one of them with your body selector, the prefixed one will be specific enough to take precedence no matter what (even if the order was reversed):

    body[id^="products-"] .widget {
        color: green;
    }
    
    .widget {
        color: red;
    }
    

    The .widget will be green because the first selector is more specific than the second.

    The only problem with using attribute selectors over ids is if you care about IE6. If that’s a concern for you, the IE7 JS library by Dean Edwards can help you out: http://code.google.com/p/ie7-js/

    If changing how the page information is attached to the body element is an option, my recommendation would be to have the parent directory be an id and the child pages be classes:

    <body id="products" class="giantspacelaser" />
    

    This way you can retain the specificity of the id:

    // excludes the body#products page, which wouldn't have a class set at all
    body[class]#products { 
        // styling here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am using JSon response to parse title,date content and thumbnail images and place
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
this is what i have right now Drawing an RSS feed into the php,
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a French site that I want to parse, but am running into

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.