Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sass: Is it possible to add a class using Sass to an HTML-Element afterwards?

I hope somebody can help me with my question.

Lets say I have this:

            <div class="container">
                <div class="row">
                    <article>
                        <p class="story-image">
                            <a href="#">
                                <img src="../media/images/awesomeness.jpg" alt="image1" class="img-responsive">
                            </a>
                        </p>
                        <section>
                            <h3>Companies</h3>
                            <h2>
                                <a href="#">
                                    Awesome-O beherrscht die Welt
                                </a>
                            </h2>
                            <p>
                                Last year, was pretty medium. But I know, by the power of my thought and my willpower, that I will make two companies and earn millions.
                            </p>
                        </section>
                    </article>
                </div>
           </div>

So, when using Twitter Bootstrap, I can apply the grid system to my HTML. Is it possible by using sass to apply a class to the article, even if it wasn't applied in the HTML from the beginning?

for example somehow like this:

 html{
      body {
           article {
                addclass --> col-lg-4 col-md-4 col-sm-6 col-xs-12;
           }
      }
 }

The reason I want to do it afterwards with sass, is that I have a bunch of articles, And I have to apply the grid system on them. But I am sure that I am going to revealuate at a later point the actual width and the ammount of the columns.

Is this possible with Sass and if yes, how?

like image 281
LoveAndHappiness Avatar asked Dec 23 '13 02:12

LoveAndHappiness


People also ask

Can Sass be used in HTML?

You can not "attach" a SASS/SCSS file to an HTML document. SASS/SCSS is a CSS preprocessor that runs on the server and compiles to CSS code that your browser understands.

How do I link a Sass file to HTML?

Add the following to the <head> tag of your HTML file. The extension we installed will compile the SASS file index. scss into CSS and store the compiled code in a new CSS file, also called index. css .

Can I use SCSS in CSS?

When you write Sass code in a . scss file, it is compiled into a regular CSS file that the browser will use to display it on the web page.


1 Answers

No. You can't add classes to HTML through CSS. You could look into using @extend though.

For example:

%grid-half {
  width: 50%;
}

.article {
  @extend %grid-half;
  color: purple;
}
like image 79
Bill Criswell Avatar answered Oct 21 '22 11:10

Bill Criswell