Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

Frances Angulo
Frances Angulo
5,311 Points

CSS within rails lines vs. via div or span

When does one opt to add html: (CSS) inline with code vs. wrapping a div and referencing a stylesheet?

2 Answers

2,949 Points

I am not sure I understand your question.

If you are asking what is better - write inline code or include in .css, my answer is - always include in your stylesheets. Reasons:

  1. Code in one place - separated from html and clean.
  2. Easier to maintain.
  3. Faster for browser to read.

Please clarify if this is not what you are asking for ;)

Frances Angulo
Frances Angulo
5,311 Points

Thanks! What i mean is I see sometimes they write in an html tag directly in to a ruby/rails line of code and reference a class vs. using the stylesheet or a span/div.

Like this:

session_path(resource_name), html: {class: "well"} ) do