


Ruby on Rails Front-end Rápido com Frameworks CSS Classless ou Class-Light Usando CDN
If you are starting to develop for the web and your focus is not to specialize in the front-end, one of the barriers that can be most painful is being able to easily style your ugly HTML .
For those who have first contact, it is something enigmatic, mystical, supernatural trying to understand HTML that has a sequence of letters and numbers with predefined utility classes to apply styles to HTML, for example:
<summary class="flex cursor-pointer items-center justify-between rounded-lg px-4 py-2 text-gray-500 hover:bg-gray-100 hover:text-gray-700"> </summary>
CSS frameworks that use utility classes are excellent, versatile, responsive, elegant and have many other qualities, but Tailwind CSS is not the only solution. If you need something quick and simpler, using a classless or class-light CSS framework will be a better solution.
Classless CSS Frameworks style HTML elements directly, without classes. Class-light frameworks combine automatic styles with some optional utility classes for customization, which adds greater versatility to their use.
Using a classless or class-light approach you can quickly solve HTML styling with one, two or three lines.
We will see below:
- Use of the Ruby on Rails framework in version 8, with Propshaft and Importmap;
- Getting to know the file with the standard layout of HTML pages;
- Creating and adding content to 4 HTML pages to test styling with CSS;
- A brief mention of the routes created for the pages;
- Change the default layout to include the link to the created pages;
- Add 12 CSS frameworks via CDN to the default layout;
- Know how to identify whether the CSS frameworks have light and dark mode configured by default;
- Suggestions for next steps;
Start a new Rails application
- The time before the rails command is used to display its execution time at the end of the command execution. In the example below, it took 47 seconds.
$ rails -v Rails 8.0.0 $ time rails new classless-css-cdn --skip-test ... real 0m47.500s user 0m33.052s sys 0m4.249s
Rails 8, within its No Build philosophy, will use by default Propshaft as the asset pipeline library and Importmap as the JavaScript library. We ask you to skip the test library with --skip-test.
If necessary, you can process your JavaScript using esbuild by passing the --javascript esbuild parameter. Importmap does not perform any build or any type of processing on JavaScript.
Open the project with VSCode or your preferred editor
$ cd classless-css-cdn && code .
Knowing the default Rails layout app/views/layouts/application.html.erb.
Show more…
<summary class="flex cursor-pointer items-center justify-between rounded-lg px-4 py-2 text-gray-500 hover:bg-gray-100 hover:text-gray-700">
</summary>
Generate test pages, with a controller pages and the actions html_test_1, html_test_2, html_test_3 and html_test_4
Show more…
$ rails -v
Rails 8.0.0
$ time rails new classless-css-cdn --skip-test
...
real 0m47.500s
user 0m33.052s
sys 0m4.249s
Open the config/routes.rb file in VSCode
$ cd classless-css-cdn && code .
Displaying Rails routes
Using the terminal you can display the routes by specifying a controller (with -c), for example from controller pages Or you can display all routes withShow more…
<title></title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<link rel="icon" href="/icon.png" type="image/png">
<link rel="icon" href="/icon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="/icon.png">
<summary class="flex cursor-pointer items-center justify-between rounded-lg px-4 py-2 text-gray-500 hover:bg-gray-100 hover:text-gray-700">
</summary>
Let's create four pages with HTML content to test the CSS styles.
Ruby on Rails uses the MVC (Model-View-Controller) architecture by default to start organizing your project. Much of your code is organized in the following folders:
- When the code is related to domain/business logic and data, keep it in the app/models folder;
- The code related to the view (HTML, JSON, XML, etc...) will be in app/views;
- Code related to the request lifecycle, will be in app/controllers;
Insert the content of the html_test_1 page
Show more…
$ rails -v
Rails 8.0.0
$ time rails new classless-css-cdn --skip-test
...
real 0m47.500s
user 0m33.052s
sys 0m4.249s
Start the Rails server and see the ugly plain HTML?
Show more…
$ cd classless-css-cdn && code .
Reopen the app/views/layouts/application.html.erb page to include classless CSS styles via CDN
Show more…
<summary class="flex cursor-pointer items-center justify-between rounded-lg px-4 py-2 text-gray-500 hover:bg-gray-100 hover:text-gray-700">
</summary>
$ rails -v
Rails 8.0.0
$ time rails new classless-css-cdn --skip-test
...
real 0m47.500s
user 0m33.052s
sys 0m4.249s
Now yes, stylish HTML?
After saving the stylesheets above and starting the Rails server you will see your HTML styled with the chosen css frameworks.
Dark mode
Some styles have the option for dark mode. To confirm, change your computer's theme in the color customization options. Search in Windows for Enable dark mode for apps and switch between dark or light mode and the HTML page automatically changes after the change in the operating system al.
Next steps
- Organize the styles according to your preference;
- If you want to spend a little more time on the frontend, check out the customization options for your favorite style;
- Dynamically update changes made to the project in the browser using Rails Live Reload;
- Use styling from project CSS files, without using CDN;
- Replicate the capability of classless CSS framework using Tailwind;
References
- https://dev.to/leonardorafael/the-classless-and-class-light-css-aproaches-2b98
- https://prismic.io/blog/best-css-frameworks
- https://saeedesmaili.com/notes/classless-css-libraries/
- https://dev.to/logrocket/comparing-classless-css-frameworks-3267
- https://github.com/dbohdan/classless-css
- https://github.com/troxler/awesome-css-frameworks
The above is the detailed content of Ruby on Rails Front-end Rápido com Frameworks CSS Classless ou Class-Light Usando CDN. For more information, please follow other related articles on the PHP Chinese website!

Linking CSS files to HTML can be achieved by using elements in part of HTML. 1) Use tags to link local CSS files. 2) Multiple CSS files can be implemented by adding multiple tags. 3) External CSS files use absolute URL links, such as. 4) Ensure the correct use of file paths and CSS file loading order, and optimize performance can use CSS preprocessor to merge files.

Choosing Flexbox or Grid depends on the layout requirements: 1) Flexbox is suitable for one-dimensional layouts, such as navigation bar; 2) Grid is suitable for two-dimensional layouts, such as magazine layouts. The two can be used in the project to improve the layout effect.

The best way to include CSS files is to use tags to introduce external CSS files in the HTML part. 1. Use tags to introduce external CSS files, such as. 2. For small adjustments, inline CSS can be used, but should be used with caution. 3. Large projects can use CSS preprocessors such as Sass or Less to import other CSS files through @import. 4. For performance, CSS files should be merged and CDN should be used, and compressed using tools such as CSSNano.

Yes,youshouldlearnbothFlexboxandGrid.1)Flexboxisidealforone-dimensional,flexiblelayoutslikenavigationmenus.2)Gridexcelsintwo-dimensional,complexdesignssuchasmagazinelayouts.3)Combiningbothenhanceslayoutflexibilityandresponsiveness,allowingforstructur

What does it look like to refactor your own code? John Rhea picks apart an old CSS animation he wrote and walks through the thought process of optimizing it.

CSSanimationsarenotinherentlyhardbutrequirepracticeandunderstandingofCSSpropertiesandtimingfunctions.1)Startwithsimpleanimationslikescalingabuttononhoverusingkeyframes.2)Useeasingfunctionslikecubic-bezierfornaturaleffects,suchasabounceanimation.3)For

@keyframesispopularduetoitsversatilityandpowerincreatingsmoothCSSanimations.Keytricksinclude:1)Definingsmoothtransitionsbetweenstates,2)Animatingmultiplepropertiessimultaneously,3)Usingvendorprefixesforbrowsercompatibility,4)CombiningwithJavaScriptfo

CSSCountersareusedtomanageautomaticnumberinginwebdesigns.1)Theycanbeusedfortablesofcontents,listitems,andcustomnumbering.2)Advancedusesincludenestednumberingsystems.3)Challengesincludebrowsercompatibilityandperformanceissues.4)Creativeusesinvolvecust


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
