Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS require Syntax

I have required CSS stylesheets many times in many of my RubyOnRails applications, and actually i need a few things demystified.

What is the difference between:

//=require mystyles

and

*=require mystyles

Both seem to work, so what is the difference?

And is this a part of the asset pipeline or a part of SASS or just plain CSS?

like image 930
Zippie Avatar asked Nov 29 '13 23:11

Zippie


People also ask

How do you give require in CSS?

The :required selector selects form elements which are required. Form elements with a required attribute are defined as required. Note: The :required selector only applies to the form elements: input, select and textarea. Tip: Use the :optional selector to select form elements which are optional.

What is the syntax for CSS?

The selector points to the HTML element you want to style. The declaration block contains one or more declarations separated by semicolons. Each declaration includes a CSS property name and a value, separated by a colon.

What are the three CSS syntax?

The CSS syntax consists of a set of rules. These rules have 3 parts: a selector, a property, and a value. You don't need to remember this in order to code CSS.

Why is CSS required?

It is the coding language that gives a website its look and layout. Along with HTML, CSS is fundamental to web design. Without it, websites would still be plain text on white backgrounds.


1 Answers

The two examples you gave are exactly the same for stylesheets, however the //= syntax is the only one that works for Javascript. You also need a standard CSS comment at the start (/*) and a close comment (*/) at the end of the require block to make it ignored to anything but the asset pipeline:

/* ...
*= require mystyles
*= require_self
*/

These require directives are only part of the asset pipeline, not CSS or SASS. To include a stylesheet for CSS or SASS, you would use a @import rule as Blieque stated in his comment.

Check out the manifest files and directives section of the Asset Pipeline guide on the Ruby on Rails guide site for a more detailed explanation of the difference. There is also a warning given there that might be of interest:

If you want to use multiple Sass files, you should generally use the Sass @import rule instead of these Sprockets directives. Using Sprockets directives all Sass files exist within their own scope, making variables or mixins only available within the document they were defined in.

like image 64
jvperrin Avatar answered Sep 21 '22 05:09

jvperrin