ការពង្រីក Bootstrap

ពង្រីក Bootstrap ដើម្បីទាញយកអត្ថប្រយោជន៍ពីរចនាប័ទ្ម និងសមាសធាតុរួមបញ្ចូល ក៏ដូចជាអថេរតិច និង mixins ។

CSS តិច

Bootstrap ត្រូវ​បាន​បង្កើត​ឡើង​ដោយ​ប្រើ LESS ជា​ស្នូល​របស់​វា ជា​ភាសា​រចនាប័ទ្ម​ថាមវន្ត​ដែល​បង្កើត​ដោយ​មិត្ត​ល្អ​របស់​យើង Alexis Sellier ។ វាធ្វើឱ្យការបង្កើត CSS ផ្អែកលើប្រព័ន្ធកាន់តែលឿន ងាយស្រួល និងរីករាយជាងមុន។

ហេតុអ្វី LESS?

អ្នកបង្កើត Bootstrap ម្នាក់បានសរសេរ ប្រកាសប្លក់ រហ័ស អំពីរឿងនេះ ដោយសង្ខេបនៅទីនេះ៖

  • Bootstrap ចងក្រងលឿនជាងមុន ~ 6x លឿនជាងមុនជាមួយនឹង Less បើប្រៀបធៀបទៅនឹង Sass
  • តិចជាងនេះត្រូវបានសរសេរនៅក្នុង JavaScript ដែលធ្វើឱ្យវាកាន់តែងាយស្រួលសម្រាប់ពួកយើងក្នុងការជ្រមុជទឹក និងបំណះបើប្រៀបធៀបទៅនឹង Ruby ជាមួយ Sass ។
  • តិចគឺច្រើន; យើងចង់មានអារម្មណ៍ថាយើងកំពុងសរសេរ CSS និងធ្វើឱ្យ Bootstrap ងាយស្រួលសម្រាប់ទាំងអស់គ្នា។

រួមបញ្ចូលអ្វីខ្លះ?

ក្នុងនាមជាផ្នែកបន្ថែមនៃ CSS, LESS រួមបញ្ចូលអថេរ, mixins សម្រាប់ព័ត៌មានខ្លីៗនៃកូដដែលអាចប្រើឡើងវិញបាន ប្រតិបត្តិការសម្រាប់គណិតវិទ្យាសាមញ្ញ ការដាក់សំបុក និងសូម្បីតែមុខងារពណ៌។

ស្វែង​យល់​បន្ថែម

សូមចូលមើលគេហទំព័រផ្លូវការនៅ http://lesscss.org/ ដើម្បីស្វែងយល់បន្ថែម។

ដោយសារ CSS របស់យើងត្រូវបានសរសេរដោយ Less និងប្រើប្រាស់អថេរ និង mixins វាចាំបាច់ត្រូវតែចងក្រងសម្រាប់ការអនុវត្តផលិតកម្មចុងក្រោយ។ នេះជារបៀប។

ចំណាំ៖ ប្រសិនបើអ្នកកំពុងដាក់សំណើរទាញទៅកាន់ GitHub ជាមួយនឹង CSS ដែលបានកែប្រែ អ្នក ត្រូវតែ ចងក្រង CSS ឡើងវិញតាមរយៈវិធីសាស្រ្តទាំងនេះ។

ឧបករណ៍សម្រាប់ការចងក្រង

ថ្នាំងជាមួយ makefile

ដំឡើងកម្មវិធីចងក្រងបន្ទាត់ពាក្យបញ្ជា LESS JSHint, Recess និង uglify-js ជាសកលជាមួយ npm ដោយដំណើរការពាក្យបញ្ជាខាងក្រោម៖

$ npm ដំឡើង -g តិច jshint recess uglify-js

នៅពេលដំឡើងរួច គ្រាន់តែដំណើរការ makeពី root នៃ bootstrap directory របស់អ្នក ហើយអ្នករួចរាល់ហើយ។

លើសពីនេះ ប្រសិនបើអ្នកបាន ដំឡើង watchr អ្នកអាចដំណើរការ make watchដើម្បីឱ្យ bootstrap បង្កើតឡើងវិញដោយស្វ័យប្រវត្តិរាល់ពេលដែលអ្នកកែសម្រួលឯកសារនៅក្នុង bootstrap lib (នេះមិនទាមទារទេ គ្រាន់តែជាវិធីសាស្ត្រងាយស្រួលប៉ុណ្ណោះ)។

បន្ទាត់ពាក្យបញ្ជា

ដំឡើងឧបករណ៍បន្ទាត់ពាក្យបញ្ជា LESS តាមរយៈ Node ហើយដំណើរការពាក្យបញ្ជាខាងក្រោម៖

$ lessc ./less/bootstrap.less > bootstrap.css

ត្រូវប្រាកដថាបញ្ចូលទៅ --compressក្នុងពាក្យបញ្ជានោះ ប្រសិនបើអ្នកកំពុងព្យាយាមរក្សាទុកបៃមួយចំនួន!

JavaScript

Download the latest Less.js and include the path to it (and Bootstrap) in the <head>.

<link rel="stylesheet/less" href="/path/to/bootstrap.less">
<script src="/path/to/less.js"></script>

To recompile the .less files, just save them and reload your page. Less.js compiles them and stores them in local storage.

Unofficial Mac app

The unofficial Mac app watches directories of .less files and compiles the code to local files after every save of a watched .less file. If you like, you can toggle preferences in the app for automatic minifying and which directory the compiled files end up in.

More apps

Crunch

Crunch is a great looking LESS editor and compiler built on Adobe Air.

CodeKit

Created by the same guy as the unofficial Mac app, CodeKit is a Mac app that compiles LESS, SASS, Stylus, and CoffeeScript.

Simpless

Mac, Linux, and Windows app for drag and drop compiling of LESS files. Plus, the source code is on GitHub.

Quickly start any web project by dropping in the compiled or minified CSS and JS. Layer on custom styles separately for easy upgrades and maintenance moving forward.

Setup file structure

Download the latest compiled Bootstrap and place into your project. For example, you might have something like this:

   app/
       layouts/
       templates/
   public/
       css/
           bootstrap.min.css
       js/
           bootstrap.min.js
       img/
           glyphicons-halflings.png
           glyphicons-halflings-white.png

Utilize starter template

Copy the following base HTML to get started.

  1. <html>
  2. <head>
  3. <title>Bootstrap 101 Template</title>
  4. <!-- Bootstrap -->
  5. <link href="public/css/bootstrap.min.css" rel="stylesheet">
  6. </head>
  7. <body>
  8. <h1>Hello, world!</h1>
  9. <!-- Bootstrap -->
  10. <script src="public/js/bootstrap.min.js"></script>
  11. </body>
  12. </html>

Layer on custom code

Work in your custom CSS, JS, and more as necessary to make Bootstrap your own with your own separate CSS and JS files.

  1. <html>
  2. <head>
  3. <title>Bootstrap 101 Template</title>
  4. <!-- Bootstrap -->
  5. <link href="public/css/bootstrap.min.css" rel="stylesheet">
  6. <!-- Project -->
  7. <link href="public/css/application.css" rel="stylesheet">
  8. </head>
  9. <body>
  10. <h1>Hello, world!</h1>
  11. <!-- Bootstrap -->
  12. <script src="public/js/bootstrap.min.js"></script>
  13. <!-- Project -->
  14. <script src="public/js/application.js"></script>
  15. </body>
  16. </html>