diff options
| author | lucascono <[email protected]> | 2017-10-04 05:33:17 -0300 |
|---|---|---|
| committer | lucascono <[email protected]> | 2017-10-04 05:33:17 -0300 |
| commit | 8c04a74c8c7f0174ea08bc02fa3762f49bf615a3 (patch) | |
| tree | db9d6923c082243d765c57885992db8dd26a70b5 /docs/4.0/getting-started | |
| parent | 9aff890efa3798f831b714c41794c9fee0684bae (diff) | |
| parent | b29b1e155880ac953899889c9cbb67f7f7df0529 (diff) | |
| download | bootstrap-8c04a74c8c7f0174ea08bc02fa3762f49bf615a3.tar.xz bootstrap-8c04a74c8c7f0174ea08bc02fa3762f49bf615a3.zip | |
Merge remote-tracking branch 'refs/remotes/twbs/v4-dev' into v4-dev
Diffstat (limited to 'docs/4.0/getting-started')
| -rw-r--r-- | docs/4.0/getting-started/best-practices.md | 1 | ||||
| -rw-r--r-- | docs/4.0/getting-started/browsers-devices.md | 31 | ||||
| -rw-r--r-- | docs/4.0/getting-started/build-tools.md | 14 | ||||
| -rw-r--r-- | docs/4.0/getting-started/download.md | 54 | ||||
| -rw-r--r-- | docs/4.0/getting-started/introduction.md | 39 | ||||
| -rw-r--r-- | docs/4.0/getting-started/javascript.md | 11 | ||||
| -rw-r--r-- | docs/4.0/getting-started/options.md | 115 | ||||
| -rw-r--r-- | docs/4.0/getting-started/theming.md | 287 | ||||
| -rw-r--r-- | docs/4.0/getting-started/webpack.md | 8 |
9 files changed, 371 insertions, 189 deletions
diff --git a/docs/4.0/getting-started/best-practices.md b/docs/4.0/getting-started/best-practices.md index 0e4792513..feb751cab 100644 --- a/docs/4.0/getting-started/best-practices.md +++ b/docs/4.0/getting-started/best-practices.md @@ -12,6 +12,7 @@ We've designed and developed Bootstrap to work in a number of environments. Here {% endcallout %} ### General outline + - Working with CSS - Working with Sass files - Building new CSS components diff --git a/docs/4.0/getting-started/browsers-devices.md b/docs/4.0/getting-started/browsers-devices.md index 426692b32..6ffb73792 100644 --- a/docs/4.0/getting-started/browsers-devices.md +++ b/docs/4.0/getting-started/browsers-devices.md @@ -1,7 +1,7 @@ --- layout: docs title: Browsers and devices -description: Learn about the browsers and devices, from modern to told, that are supported by Bootstrap, including known quirks and bugs for each. +description: Learn about the browsers and devices, from modern to old, that are supported by Bootstrap, including known quirks and bugs for each. group: getting-started toc: true --- @@ -101,32 +101,10 @@ For a list of some of the browser bugs that Bootstrap has to grapple with, see o ## Internet Explorer -Internet Explorer 10+ is supported; IE9 and down is not. Please be aware that some CSS3 properties and HTML5 elements are not fully supported in IE10, or require prefixed properties for full functionality. Visit [Can I use...](http://caniuse.com/) for details on browser support of CSS3 and HTML5 features. +Internet Explorer 10+ is supported; IE9 and down is not. Please be aware that some CSS3 properties and HTML5 elements are not fully supported in IE10, or require prefixed properties for full functionality. Visit [Can I use...](https://caniuse.com/) for details on browser support of CSS3 and HTML5 features. **If you require IE8-9 support, use Bootstrap 3.** It's the most stable version of our code and is still supported by our team for critical bugfixes and documentation changes. However, no new features will be added to it. -## Internet Explorer 10 in Windows Phone 8 - -Internet Explorer 10 in Windows Phone 8 versions older than [Update 3 (a.k.a. GDR3)](https://blogs.windows.com/buildingapps/2013/10/14/introducing-windows-phone-preview-for-developers/) doesn't differentiate **device width** from **viewport width** in `@-ms-viewport` at-rules, and thus doesn't properly apply the media queries in Bootstrap's CSS. To address this, you'll need to **include the following JavaScript to work around the bug**. - -{% highlight js %} -// Copyright 2014-2017 The Bootstrap Authors -// Copyright 2014-2017 Twitter, Inc. -// Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) -if (navigator.userAgent.match(/IEMobile\/10\.0/)) { - var msViewportStyle = document.createElement('style') - msViewportStyle.appendChild( - document.createTextNode( - '@-ms-viewport{width:auto!important}' - ) - ) - document.head.appendChild(msViewportStyle) -} -{% endhighlight %} - -For more information and usage guidelines, read [Windows Phone 8 and Device-Width](https://timkadlec.com/2013/01/windows-phone-8-and-device-width/). - -As a heads up, we include this in all of Bootstrap's documentation and examples as a demonstration. ## Modals and dropdowns on mobile @@ -147,6 +125,7 @@ The `.dropdown-backdrop` element isn't used on iOS in the nav because of the com Page zooming inevitably presents rendering artifacts in some components, both in Bootstrap and the rest of the web. Depending on the issue, we may be able to fix it (search first and then open an issue if need be). However, we tend to ignore these as they often have no direct solution other than hacky workarounds. ## Sticky `:hover`/`:focus` on mobile + Even though real hovering isn't possible on most touchscreens, most mobile browsers emulate hovering support and make `:hover` "sticky". In other words, `:hover` styles start applying after tapping an element and only stop applying after the user taps some other element. On mobile-first sites, this behavior is normally undesirable. Bootstrap includes a workaround for this, although it is disabled by default. By setting `$enable-hover-media-query` to `true` when compiling from Sass, Bootstrap will use [mq4-hover-shim](https://github.com/twbs/mq4-hover-shim) to disable `:hover` styles in browsers that emulate hovering, thus preventing sticky `:hover` styles. There are some caveats to this workaround; see the shim's documentation for details. @@ -155,7 +134,7 @@ Bootstrap includes a workaround for this, although it is disabled by default. By Even in some modern browsers, printing can be quirky. -As of Safari v8.0, use of the fixed-width `.container` class can cause Safari to use an unusually small font size when printing. See [issue #14868](https://github.com/twbs/bootstrap/issues/14868) and [WebKit bug #138192](https://bugs.webkit.org/show_bug.cgi?id=138192) for more details. One potential workaround is the following CSS: +As of Safari v8.0, use of the fixed-width `.container` class can cause Safari to use an unusually small font size when printing. See [issue #14868]({{ site.repo }}/issues/14868) and [WebKit bug #138192](https://bugs.webkit.org/show_bug.cgi?id=138192) for more details. One potential workaround is the following CSS: {% highlight css %} @media print { @@ -189,7 +168,7 @@ Want to see an example? [Check out this JS Bin demo.](http://jsbin.com/OyaqoDO/2 ## Validators -In order to provide the best possible experience to old and buggy browsers, Bootstrap uses [CSS browser hacks](http://browserhacks.com) in several places to target special CSS to certain browser versions in order to work around bugs in the browsers themselves. These hacks understandably cause CSS validators to complain that they are invalid. In a couple places, we also use bleeding-edge CSS features that aren't yet fully standardized, but these are used purely for progressive enhancement. +In order to provide the best possible experience to old and buggy browsers, Bootstrap uses [CSS browser hacks](http://browserhacks.com/) in several places to target special CSS to certain browser versions in order to work around bugs in the browsers themselves. These hacks understandably cause CSS validators to complain that they are invalid. In a couple places, we also use bleeding-edge CSS features that aren't yet fully standardized, but these are used purely for progressive enhancement. These validation warnings don't matter in practice since the non-hacky portion of our CSS does fully validate and the hacky portions don't interfere with the proper functioning of the non-hacky portion, hence why we deliberately ignore these particular warnings. diff --git a/docs/4.0/getting-started/build-tools.md b/docs/4.0/getting-started/build-tools.md index dd3cac0be..64b032021 100644 --- a/docs/4.0/getting-started/build-tools.md +++ b/docs/4.0/getting-started/build-tools.md @@ -8,14 +8,14 @@ toc: true ## Tooling setup -Bootstrap uses [NPM scripts](https://docs.npmjs.com/misc/scripts) for its build system. Our [package.json](https://github.com/twbs/bootstrap/blob/v4-dev/package.json) includes convenient methods for working with the framework, including compiling code, running tests, and more. +Bootstrap uses [NPM scripts](https://docs.npmjs.com/misc/scripts) for its build system. Our [package.json]({{ site.repo }}/blob/v{{ site.current_version }}/package.json) includes convenient methods for working with the framework, including compiling code, running tests, and more. To use our build system and run our documentation locally, you'll need a copy of Bootstrap's source files and Node. Follow these steps and you should be ready to rock: -1. [Download and install Node](https://nodejs.org/download/), which we use to manage our dependencies. -2. Navigate to the root `/bootstrap` directory and run `npm install` to install our local dependencies listed in [package.json](https://github.com/twbs/bootstrap/blob/master/package.json). -4. [Install Ruby][install-ruby], install [Bundler][gembundler] with `gem install bundler`, and finally run `bundle install`. This will install all Ruby dependencies, such as Jekyll and plugins. - - **Windows users:** Read [this unofficial guide](http://jekyll-windows.juthilo.com/) to get Jekyll up and running without problems. +1. [Download and install Node.js](https://nodejs.org/download/), which we use to manage our dependencies. +2. Navigate to the root `/bootstrap` directory and run `npm install` to install our local dependencies listed in [package.json]({{ site.repo }}/blob/v{{ site.current_version }}/package.json). +3. [Install Ruby][install-ruby], install [Bundler][gembundler] with `gem install bundler`, and finally run `bundle install`. This will install all Ruby dependencies, such as Jekyll and plugins. + - **Windows users:** Read [this guide](https://jekyllrb.com/docs/windows/) to get Jekyll up and running without problems. When completed, you'll be able to run the various commands provided from the command line. @@ -24,7 +24,7 @@ When completed, you'll be able to run the various commands provided from the com ## Using NPM scripts -Our [package.json](https://github.com/twbs/bootstrap/blob/master/package.json) includes the following commands and tasks: +Our [package.json]({{ site.repo }}/blob/v{{ site.current_version }}/package.json) includes the following commands and tasks: | Task | Description | | --- | --- | @@ -36,7 +36,7 @@ Our [package.json](https://github.com/twbs/bootstrap/blob/master/package.json) i Bootstrap uses [Autoprefixer][autoprefixer] (included in our build process) to automatically add vendor prefixes to some CSS properties at build time. Doing so saves us time and code by allowing us to write key parts of our CSS a single time while eliminating the need for vendor mixins like those found in v3. -We maintain the list of browsers supported through Autoprefixer in a separate file within our GitHub repository. See [`/build/postcss.config.js`](https://github.com/twbs/bootstrap/blob/v4-dev/build/postcss.config.js) for details. +We maintain the list of browsers supported through Autoprefixer in a separate file within our GitHub repository. See [/package.json]({{ site.repo }}/blob/v{{ site.current_version }}/package.json) for details. ## Local documentation diff --git a/docs/4.0/getting-started/download.md b/docs/4.0/getting-started/download.md index 468575494..cce660178 100644 --- a/docs/4.0/getting-started/download.md +++ b/docs/4.0/getting-started/download.md @@ -1,42 +1,58 @@ --- layout: docs title: Download -description: Download Bootstrap to get the compiled CSS and JavaScript, source code, or include it with your favorite package managers like npm, Bower, RubyGems, and more. +description: Download Bootstrap to get the compiled CSS and JavaScript, source code, or include it with your favorite package managers like npm, RubyGems, and more. group: getting-started toc: true --- -## Bootstrap CSS and JS +## Compiled CSS and JS -**Download Bootstrap's ready-to-use code to easily drop into your project.** Includes compiled and minified versions of all our CSS bundles (default, grid only, or Reboot only) and JavaScript plugins. Doesn't include documentation or source files. +Download ready-to-use compiled code for **Bootstrap v{{ site.current_version}}** to easily drop into your project, which includes: -**Current version:** v{{ site.current_version}} +- Compiled and minified CSS bundles (default, grid-only, and Reboot-only) +- Compiled and minified JavaScript plugins -<a href="{{ site.download.dist }}" class="btn btn-bd-purple" onclick="ga('send', 'event', 'Getting started', 'Download', 'Download Bootstrap');">Download Bootstrap</a> +This doesn't include documentation, source files, or any optional JavaScript dependencies (jQuery and Popper.js). + +<a href="{{ site.download.dist }}" class="btn btn-bd-purple" onclick="ga('send', 'event', 'Getting started', 'Download', 'Download Bootstrap');">Download</a> ## Source files -**Want to compile Bootstrap with your project's asset pipeline?** Choose this option to download our source Sass, JavaScript, and documentation files. Requires a Sass compiler, [Autoprefixer](https://github.com/postcss/autoprefixer), and [some setup]({{ site.baseurl }}/docs/{{ site.docs_version }}/getting-started/build-tools/#tooling-setup). + +Compile Bootstrap with your own asset pipeline by downloading our source Sass, JavaScript, and documentation files. This option requires some additional tooling: + +- Sass compiler (Libsass or Ruby Sass is supported) for compiling your CSS. +- [Autoprefixer](https://github.com/postcss/autoprefixer) for CSS vendor prefixing + +Should you require [build tools]({{ site.baseurl }}/docs/{{ site.docs_version }}/getting-started/build-tools/#tooling-setup), they are included for developing Bootstrap and its docs, but they're likely unsuitable for your own purposes. <a href="{{ site.download.source }}" class="btn btn-bd-purple" onclick="ga('send', 'event', 'Getting started', 'Download', 'Download source');">Download source</a> ## Bootstrap CDN -Skip the download and use the Bootstrap CDN to deliver Bootstrap's compiled CSS and JS to your project. +Skip the download with the Bootstrap CDN to deliver cached version of Bootstrap's compiled CSS and JS to your project. {% highlight html %} <link rel="stylesheet" href="{{ site.cdn.css }}" integrity="{{ site.cdn.css_hash }}" crossorigin="anonymous"> <script src="{{ site.cdn.js }}" integrity="{{ site.cdn.js_hash }}" crossorigin="anonymous"></script> {% endhighlight %} +If you're using our compiled JavaScript, don't forget to include CDN versions of jQuery and Popper.js before it. + +{% highlight html %} +<script src="{{ site.cdn.jquery }}" integrity="{{ site.cdn.jquery_hash }}" crossorigin="anonymous"></script> +<script src="{{ site.cdn.popper }}" integrity="{{ site.cdn.popper_hash }}" crossorigin="anonymous"></script> +{% endhighlight %} + ## Package managers Pull in Bootstrap's **source files** into nearly any project with some of the most popular package managers. No matter the package manager, Bootstrap will **require a Sass compiler and [Autoprefixer](https://github.com/postcss/autoprefixer)** for a setup that matches our official compiled versions. ### npm -Install Bootstrap in your Node powered apps with [the npm package](https://www.npmjs.com/package/bootstrap): +Install Bootstrap in your Node.js powered apps with [the npm package](https://www.npmjs.com/package/bootstrap): -{% highlight bash %} +{% highlight sh %} npm install bootstrap@{{ site.current_version }} {% endhighlight %} @@ -52,36 +68,28 @@ Bootstrap's `package.json` contains some additional metadata under the following Install Bootstrap in your Ruby apps using [Bundler](https://bundler.io/) (**recommended**) and [RubyGems](https://rubygems.org/) by adding the following line to your [`Gemfile`](https://bundler.io/gemfile.html): {% highlight ruby %} -gem 'bootstrap', '~> 4.0.0.alpha6' +gem 'bootstrap', '~> 4.0.0.beta' {% endhighlight %} Alternatively, if you're not using Bundler, you can install the gem by running this command: -{% highlight bash %} -gem install bootstrap -v 4.0.0.alpha6 +{% highlight sh %} +gem install bootstrap -v 4.0.0.beta {% endhighlight %} [See the gem's README](https://github.com/twbs/bootstrap-rubygem/blob/master/README.md) for further details. ### Composer -You can also install and manage Bootstrap's Sass and JavaScript using [Composer](https://getcomposer.org): +You can also install and manage Bootstrap's Sass and JavaScript using [Composer](https://getcomposer.org/): -{% highlight bash %} +{% highlight sh %} composer require twbs/bootstrap:{{ site.current_version }} {% endhighlight %} -### Bower - -Install and manage Bootstrap's Sass and JavaScript using [Bower](https://bower.io). - -{% highlight bash %} -bower install bootstrap#v{{ site.current_version }} -{% endhighlight %} - ### NuGet -If you develop in .NET, you can also install and manage Bootstrap's [CSS](https://www.nuget.org/packages/bootstrap/) or [Sass](https://www.nuget.org/packages/bootstrap.sass/) and JavaScript using [NuGet](https://www.nuget.org): +If you develop in .NET, you can also install and manage Bootstrap's [CSS](https://www.nuget.org/packages/bootstrap/) or [Sass](https://www.nuget.org/packages/bootstrap.sass/) and JavaScript using [NuGet](https://www.nuget.org/): {% highlight powershell %} Install-Package bootstrap -Pre diff --git a/docs/4.0/getting-started/introduction.md b/docs/4.0/getting-started/introduction.md index 233c82883..8a3badc8d 100644 --- a/docs/4.0/getting-started/introduction.md +++ b/docs/4.0/getting-started/introduction.md @@ -10,21 +10,23 @@ redirect_from: toc: true --- -<!-- Bootstrap is the world's most popular framework for building responsive, mobile-first sites and applications. Inside you'll find high quality HTML, CSS, and JavaScript to make starting any project easier than ever. --> - -<!-- Here's how to quickly get started with the Bootstrap CDN and a template starter page. --> - ## Quick start Looking to quickly add Bootstrap to your project? Use the Bootstrap CDN, provided for free by the folks at MaxCDN. Using a package manager or need to download the source files? [Head to the downloads page.]({{ site.baseurl }}/docs/{{ site.docs_version }}/getting-started/download/) +### CSS + Copy-paste the stylesheet `<link>` into your `<head>` before all other stylesheets to load our CSS. {% highlight html %} <link rel="stylesheet" href="{{ site.cdn.css }}" integrity="{{ site.cdn.css_hash }}" crossorigin="anonymous"> {% endhighlight %} -Add our JavaScript plugins, jQuery, and Popper.js near the end of your pages, right before the closing `</body>` tag. Be sure to place jQuery and Popper.js first, as our code depends on them. While we use [jQuery's slim build](https://blog.jquery.com/2016/06/09/jquery-3-0-final-released/) in our docs, the full version is also supported. +### JS + +Many of our components require the use of JavaScript to function. Specifically, they require [jQuery](https://jquery.com), [Popper.js](https://popper.js.org/), and our own JavaScript plugins. Place the following `<script>`s near the end of your pages, right before the closing `</body>` tag, to enable them. jQuery must come first, then Popper.js, and then our JavaScript plugins. + +We use [jQuery's slim build](https://blog.jquery.com/2016/06/09/jquery-3-0-final-released/), but the full version is also supported. {% highlight html %} <script src="{{ site.cdn.jquery }}" integrity="{{ site.cdn.jquery_hash }}" crossorigin="anonymous"></script> @@ -32,16 +34,32 @@ Add our JavaScript plugins, jQuery, and Popper.js near the end of your pages, ri <script src="{{ site.cdn.js }}" integrity="{{ site.cdn.js_hash }}" crossorigin="anonymous"></script> {% endhighlight %} -And that's it—you're on your way to a fully Bootstrapped site. If you're at all unsure about the general page structure, keep reading for an example page template. +Curious which components explicitly require jQuery, our JS, and Popper.js? Click the show components link below. If you're at all unsure about the general page structure, keep reading for an example page template. + +<details> +<summary class="text-primary mb-3">Show components requiring JavaScript</summary> +{% markdown %} +- Alerts for dismissing +- Buttons for toggling states and checkbox/radio functionality +- Carousel for all slide behaviors, controls, and indicators +- Collapse for toggling visibility of content +- Dropdowns for displaying and positioning (also requires [Popper.js](https://popper.js.org/)) +- Modals for displaying, positioning, and scroll behavior +- Navbar for extending our Collapse plugin to implement responsive behavior +- Tooltips and popovers for displaying and positioning (also requires [Popper.js](https://popper.js.org/)) +- Scrollspy for scroll behavior and navigation updates +{% endmarkdown %} +</details> ## Starter template Be sure to have your pages set up with the latest design and development standards. That means using an HTML5 doctype and including a viewport meta tag for proper responsive behaviors. Put it all together and your pages should look like this: {% highlight html %} -<!DOCTYPE html> +<!doctype html> <html lang="en"> <head> + <title>Hello, world!</title> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> @@ -52,7 +70,8 @@ Be sure to have your pages set up with the latest design and development standar <body> <h1>Hello, world!</h1> - <!-- jQuery first, then Popper.js, then Bootstrap JS. --> + <!-- Optional JavaScript --> + <!-- jQuery first, then Popper.js, then Bootstrap JS --> <script src="{{ site.cdn.jquery }}" integrity="{{ site.cdn.jquery_hash }}" crossorigin="anonymous"></script> <script src="{{ site.cdn.popper }}" integrity="{{ site.cdn.popper_hash }}" crossorigin="anonymous"></script> <script src="{{ site.cdn.js }}" integrity="{{ site.cdn.js_hash }}" crossorigin="anonymous"></script> @@ -71,7 +90,7 @@ Bootstrap employs a handful of important global styles and settings that you'll Bootstrap requires the use of the HTML5 doctype. Without it, you'll see some funky incomplete styling, but including it shouldn't cause any considerable hiccups. {% highlight html %} -<!DOCTYPE html> +<!doctype html> <html lang="en"> ... </html> @@ -99,7 +118,7 @@ On the rare occasion you need to override it, use something like the following: } {% endhighlight %} -With the above snippet, nested elements—including generated content via `:before` and `:after`—will all inherit the specified `box-sizing` for that `.selector-for-some-widget`. +With the above snippet, nested elements—including generated content via `::before` and `::after`—will all inherit the specified `box-sizing` for that `.selector-for-some-widget`. Learn more about [box model and sizing at CSS Tricks](https://css-tricks.com/box-sizing/). diff --git a/docs/4.0/getting-started/javascript.md b/docs/4.0/getting-started/javascript.md index c4fb2366a..648132255 100644 --- a/docs/4.0/getting-started/javascript.md +++ b/docs/4.0/getting-started/javascript.md @@ -1,7 +1,7 @@ --- layout: docs title: JavaScript -description: Bring Bootstrap to life with our JavaScript plugins built on jQuery. Learn about each plugin, our data and programmatic API options, and more. +description: Bring Bootstrap to life with our optional JavaScript plugins built on jQuery. Learn about each plugin, our data and programmatic API options, and more. group: getting-started toc: true --- @@ -12,7 +12,9 @@ Plugins can be included individually (using Bootstrap's individual `*.js` files) ## Dependencies -Some plugins and CSS components depend on other plugins. If you include plugins individually, make sure to check for these dependencies in the docs. Also note that all plugins depend on jQuery (this means jQuery must be included **before** the plugin files). [Consult our `bower.json`]({{ site.repo }}/blob/v{{ site.current_version }}/bower.json) to see which versions of jQuery are supported. +Some plugins and CSS components depend on other plugins. If you include plugins individually, make sure to check for these dependencies in the docs. Also note that **all plugins depend on jQuery** (this means jQuery must be included **before** the plugin files). [Consult our `package.json`]({{ site.repo }}/blob/v{{ site.current_version }}/package.json) to see which versions of jQuery are supported. + +Our dropdowns, popovers and tooltips also depend on [Popper.js](https://popper.js.org/). ## Data attributes @@ -34,7 +36,7 @@ $(document).off('.alert.data-api') Bootstrap provides custom events for most plugins' unique actions. Generally, these come in an infinitive and past participle form - where the infinitive (ex. `show`) is triggered at the start of an event, and its past participle form (ex. `shown`) is triggered on the completion of an action. -All infinitive events provide [`preventDefault()`](https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault) functionality. This provides the ability to stop the execution of an action before it starts. +All infinitive events provide [`preventDefault()`](https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault) functionality. This provides the ability to stop the execution of an action before it starts. Returning false from an event handler will also automatically call `preventDefault()`. {% highlight js %} $('#myModal').on('show.bs.modal', function (e) { @@ -82,6 +84,7 @@ $('#myCarousel').carousel('2') // !! Will be ignored, as the transition to the s {% endhighlight %} ### Default settings + You can change the default settings for a plugin by modifying the plugin's `Constructor.Default` object: {% highlight js %} @@ -117,6 +120,6 @@ Bootstrap's plugins don't fall back particularly gracefully when JavaScript is d ## Util -All Bootstrap Javascript depend on `util.js` and it has to be included alongside the other JS files. If you're using the compiled (or minified) `bootstrap.js`, there is no need to include this—it's already there. +All Bootstrap's JavaScript files depend on `util.js` and it has to be included alongside the other JS files. If you're using the compiled (or minified) `bootstrap.js`, there is no need to include this—it's already there. `util.js` includes utility functions and a basic helper for `transitionEnd` events as well as a CSS transition emulator. It's used by the other plugins to check for CSS transition support and to catch hanging transitions. diff --git a/docs/4.0/getting-started/options.md b/docs/4.0/getting-started/options.md deleted file mode 100644 index 4788c847a..000000000 --- a/docs/4.0/getting-started/options.md +++ /dev/null @@ -1,115 +0,0 @@ ---- -layout: docs -title: Customization options -description: Customize Bootstrap 4 with our new built-in Sass variables for global style preferences for easy theming and component changes. -group: getting-started -toc: true ---- - -## Customizing variables - -Every Sass variable in Bootstrap 4 includes the `!default` flag, meaning you can override that default value in your own Sass even after that original variable's been defined. Copy and paste variables as needed, modify the values, remove the `!default` flag, and recompile. - -For example, to change out the `background-color` and `color` for the `<body>`, you'd do the following: - -{% highlight scss %} -$body-bg: $gray-900; -$body-color: $gray-600; -{% endhighlight %} - -Do the same for any variable you need to override, including the global options listed below. - -## Global options - -Customize Bootstrap 4 with our built-in custom variables file and easily toggle global CSS preferences with new `$enable-*` Sass variables. Override a variable's value and recompile with `npm run test` as needed. - -You can find and customize these variables for key global options in our `_variables.scss` file. - -| Variable | Values | Description | -| --------------------------- | ---------------------------------- | -------------------------------------------------------------------------------------- | -| `$spacer` | `1rem` (default), or any value > 0 | Specifies the default spacer value to programmatically generate our [spacer utilities](/utilities/spacing/). | -| `$enable-rounded` | `true` (default) or `false` | Enables predefined `border-radius` styles on various components. | -| `$enable-shadows` | `true` or `false` (default) | Enables predefined `box-shadow` styles on various components. | -| `$enable-gradients` | `true` or `false` (default) | Enables predefined gradients via `background-image` styles on various components. | -| `$enable-transitions` | `true` (default) or `false` | Enables predefined `transition`s on various components. | -| `$enable-hover-media-query` | `true` or `false` (default) | ... | -| `$enable-grid-classes` | `true` (default) or `false` | Enables the generation of CSS classes for the grid system (e.g., `.container`, `.row`, `.col-md-1`, etc.). | -| `$enable-print-styles` | `true` (default) or `false` | Enables styles for optimizing printing. | - -## Color - -Many of Bootstrap's various components and utilities are built through a series of colors defined in a Sass map. This map can be looped over in Sass to quickly generate a series of rulesets. - -### All colors - -All colors available in Bootstrap 4, available as Sass variables and a Sass map in our `scss/_variables.scss` file. This will be expanded upon in subsequent minor releases to add additional shades, much like the [grayscale palette](#grays) we already include. - -<div class="row"> - {% for color in site.data.colors %} - <div class="col-md-4"> - {% unless color.name == "white" or color.name == "gray" or color.name == "gray-dark" %} - <div class="p-3 mb-3 swatch-{{ color.name }}">{{ color.name | capitalize }}</div> - {% endunless %} - </div> - {% endfor %} -</div> - -Here's how you can use these in your Sass: - -{% highlight scss %} -// With variable -.alpha { color: $purple; } - -// From the Sass map with our `color()` function -.beta { color: color("purple"); } -{% endhighlight %} - -[Color utility classes]({{ site.baseurl }}/docs/{{ site.docs_version }}/utilities/colors/) are also available for setting `color` and `background-color`. - -{% callout info %} -In the future, we'll aim to provide Sass maps and variables for shades of each color as we've done with the grayscale colors below. -{% endcallout %} - -### Theme colors - -We use a subset of all colors to create a smaller color palette for generating color schemes, also available as Sass variables and a Sass map in our `scss/_variables.scss` file. - -<div class="row"> - {% for color in site.data.theme-colors %} - <div class="col-md-4"> - <div class="p-3 mb-3 swatch-{{ color.name }}">{{ color.name | capitalize }}</div> - </div> - {% endfor %} -</div> - -### Grays - -An expansive set of gray variables and a Sass map in `scss/_variables.scss` for consistent shades of gray across your project. - -<div class="row mb-3"> - <div class="col-md-4"> - {% for color in site.data.grays %} - <div class="p-3 swatch-{{ color.name }}">{{ color.name | capitalize }}</div> - {% endfor %} - </div> -</div> - -Within `_variables.scss`, you'll find our color variables and Sass map. Here's an example of the `$colors` Sass map: - -{% highlight scss %} -$colors: ( - red: $red, - orange: $orange, - yellow: $yellow, - green: $green, - teal: $teal, - blue: $blue, - pink: $pink, - purple: $purple, - white: $white, - gray: $gray-600, - gray-dark: $gray-900 -) !default; -{% endhighlight %} - -Add, remove, or modify values within the map to update how they're used in many other components. Unfortunately at this time, not _every_ component utilizes this Sass map. Future updates will strive to improve upon this. Until then, plan on making use of the `${color}` variables and this Sass map. diff --git a/docs/4.0/getting-started/theming.md b/docs/4.0/getting-started/theming.md new file mode 100644 index 000000000..c4c50dc4b --- /dev/null +++ b/docs/4.0/getting-started/theming.md @@ -0,0 +1,287 @@ +--- +layout: docs +title: Theming Bootstrap +description: Customize Bootstrap 4 with our new built-in Sass variables for global style preferences for easy theming and component changes. +group: getting-started +toc: true +redirect_from: "/docs/4.0/getting-started/options/" +--- + +## Introduction + +In Bootstrap 3, theming was largely driven by variable overrides in LESS, custom CSS, and a separate theme stylesheet that we included in our `dist` files. With some effort, one could completely redesign the look of Bootstrap 3 without touching the core files. Bootstrap 4 provides a familiar, but slightly different approach. + +Now, theming is accomplished by Sass variables, Sass maps, and custom CSS. There's no more dedicated theme stylesheet anymore; instead, you can enable the built-in theme to add gradients, shadows, and more. + +## Sass + +Utilize our source Sass files to take advantage of variables, maps, mixins, and more. + +### File structure + +Whenever possible, avoid modifying Bootstrap's core files. For Sass, that means creating your own stylesheet that imports Bootstrap so you can modify and extend it. Assuming you've downloaded our source files or are using package manager, you'll have a file structure that looks like this: + +{% highlight plaintext %} +your-project/ +├── scss +│ └── custom.scss +└── node_modules/ + └── bootstrap + ├── js + └── scss +{% endhighlight %} + +In your `custom.scss`, you'll import Bootstrap's source Sass files. You have two options: include all of Bootstrap, or pick the parts you need. We encourage the latter, though be aware there are some requirements and dependencies across our components. You also will need to include some JavaScript for our plugins. + +{% highlight scss %} +// Custom.scss +// Option A: Include all of Bootstrap + +@import "node_modules/bootstrap/scss/bootstrap"; +{% endhighlight %} + +{% highlight scss %} +// Custom.scss +// Option B: Include parts of Bootstrap + +// Required +@import "node_modules/bootstrap/scss/functions"; +@import "node_modules/bootstrap/scss/variables"; +@import "node_modules/bootstrap/scss/mixins"; + +// Optional +@import "node_modules/bootstrap/scss/reboot"; +@import "node_modules/bootstrap/scss/type"; +@import "node_modules/bootstrap/scss/images"; +@import "node_modules/bootstrap/scss/code"; +@import "node_modules/bootstrap/scss/grid"; +{% endhighlight %} + +With that setup in place, you can begin to modify any of the Sass variables and maps in your `custom.scss`. You can also start to add parts of Bootstrap under the `// Optional` section as needed. + +### Variable defaults + +Every Sass variable in Bootstrap 4 includes the `!default` flag allowing you to override the variable's default value in your own Sass without modifying Bootstrap's source code. Copy and paste variables as needed, modify their values, and remove the `!default` flag. If a variable has already been assigned, then it won't be re-assigned by the default values in Bootstrap. + +Variable overrides within the same Sass file can come before or after the default variables. However, when overriding across Sass files, your overrides must come before you import Bootstrap's Sass files. + +Here's an example that changes the `background-color` and `color` for the `<body>` when importing and compiling Bootstrap via npm: + +{% highlight scss %} +// Your variable overrides +$body-bg: #000; +$body-color: #111; + +// Bootstrap and its default variables +@import "node_modules/bootstrap/scss/bootstrap"; +{% endhighlight %} + +Repeat as necessary for any variable in Bootstrap, including the global options below. + +### Maps and loops + +Bootstrap 4 includes a handful of Sass maps, key value pairs that make it easier to generate families of related CSS. We use Sass maps for our colors, grid breakpoints, and more. Just like Sass variables, all Sass maps include the `!default` flag and can be overridden and extended. + +For example, to modify an existing color in our `$theme-colors` map, add the following to your custom Sass file: + +{% highlight scss %} +$theme-colors: ( + "primary": #0074d9, + "danger": #ff4136 +); +{% endhighlight %} + +To add a new color to `$theme-colors`, add the new key and value: + +{% highlight scss %} +$theme-colors: ( + "custom-color": #900 +); +{% endhighlight %} + +### Functions + +Bootstrap utilizes several Sass functions, but only a subset are applicable to general theming. We've included three functions for getting values from the color maps: + +{% highlight scss %} +@function color($key: "blue") { + @return map-get($colors, $key); +} + +@function theme-color($key: "primary") { + @return map-get($theme-colors, $key); +} + +@function gray($key: "100") { + @return map-get($grays, $key); +} +{% endhighlight %} + +These allow you to pick one color from a Sass map much like how you'd use a color variable from v3. + +{% highlight scss %} +.custom-element { + color: gray("100"); + background-color: theme-color("dark"); +} +{% endhighlight %} + +We also have another function for getting a particular _level_ of color from the `$theme-colors` map. Negative level values will lighten the color, while higher levels will darken. + +{% highlight scss %} +@function theme-color-level($color-name: "primary", $level: 0) { + $color: theme-color($color-name); + $color-base: if($level > 0, #000, #fff); + $level: abs($level); + + @return mix($color-base, $color, $level * $theme-color-interval); +} +{% endhighlight %} + +In practice, you'd call the function and pass in two parameters: the name of the color from `$theme-colors` (e.g., primary or danger) and a numeric level. + +{% highlight scss %} +.custom-element { + color: theme-color-level(primary, -10); +} +{% endhighlight %} + +Additional functions could be added in the future or your own custom Sass to create level functions for additional Sass maps, or even a generic one if you wanted to be more verbose. + +## Sass options + +Customize Bootstrap 4 with our built-in custom variables file and easily toggle global CSS preferences with new `$enable-*` Sass variables. Override a variable's value and recompile with `npm run test` as needed. + +You can find and customize these variables for key global options in our `_variables.scss` file. + +| Variable | Values | Description | +| --------------------------- | ---------------------------------- | -------------------------------------------------------------------------------------- | +| `$spacer` | `1rem` (default), or any value > 0 | Specifies the default spacer value to programmatically generate our [spacer utilities]({{ site.baseurl }}/docs/{{ site.docs_version }}/utilities/spacing/). | +| `$enable-rounded` | `true` (default) or `false` | Enables predefined `border-radius` styles on various components. | +| `$enable-shadows` | `true` or `false` (default) | Enables predefined `box-shadow` styles on various components. | +| `$enable-gradients` | `true` or `false` (default) | Enables predefined gradients via `background-image` styles on various components. | +| `$enable-transitions` | `true` (default) or `false` | Enables predefined `transition`s on various components. | +| `$enable-hover-media-query` | `true` or `false` (default) | ... | +| `$enable-grid-classes` | `true` (default) or `false` | Enables the generation of CSS classes for the grid system (e.g., `.container`, `.row`, `.col-md-1`, etc.). | +| `$enable-caret` | `true` (default) or `false` | Enables pseudo element caret on `.dropdown-toggle`. | +| `$enable-print-styles` | `true` (default) or `false` | Enables styles for optimizing printing. | + +## Color + +Many of Bootstrap's various components and utilities are built through a series of colors defined in a Sass map. This map can be looped over in Sass to quickly generate a series of rulesets. + +### All colors + +All colors available in Bootstrap 4, available as Sass variables and a Sass map in our `scss/_variables.scss` file. This will be expanded upon in subsequent minor releases to add additional shades, much like the [grayscale palette](#grays) we already include. + +<div class="row"> + {% for color in site.data.colors %} + {% unless color.name == "white" or color.name == "gray" or color.name == "gray-dark" %} + <div class="col-md-4"> + <div class="p-3 mb-3 swatch-{{ color.name }}">{{ color.name | capitalize }}</div> + </div> + {% endunless %} + {% endfor %} +</div> + +Here's how you can use these in your Sass: + +{% highlight scss %} +// With variable +.alpha { color: $purple; } + +// From the Sass map with our `color()` function +.beta { color: color("purple"); } +{% endhighlight %} + +[Color utility classes]({{ site.baseurl }}/docs/{{ site.docs_version }}/utilities/colors/) are also available for setting `color` and `background-color`. + +{% callout info %} +In the future, we'll aim to provide Sass maps and variables for shades of each color as we've done with the grayscale colors below. +{% endcallout %} + +### Theme colors + +We use a subset of all colors to create a smaller color palette for generating color schemes, also available as Sass variables and a Sass map in our `scss/_variables.scss` file. + +<div class="row"> + {% for color in site.data.theme-colors %} + <div class="col-md-4"> + <div class="p-3 mb-3 swatch-{{ color.name }}">{{ color.name | capitalize }}</div> + </div> + {% endfor %} +</div> + +### Grays + +An expansive set of gray variables and a Sass map in `scss/_variables.scss` for consistent shades of gray across your project. + +<div class="row mb-3"> + <div class="col-md-4"> + {% for color in site.data.grays %} + <div class="p-3 swatch-{{ color.name }}">{{ color.name | capitalize }}</div> + {% endfor %} + </div> +</div> + +Within `_variables.scss`, you'll find our color variables and Sass map. Here's an example of the `$colors` Sass map: + +{% highlight scss %} +$colors: ( + "red": $red, + "orange": $orange, + "yellow": $yellow, + "green": $green, + "teal": $teal, + "blue": $blue, + "pink": $pink, + "purple": $purple, + "white": $white, + "gray": $gray-600, + "gray-dark": $gray-900 +) !default; +{% endhighlight %} + +Add, remove, or modify values within the map to update how they're used in many other components. Unfortunately at this time, not _every_ component utilizes this Sass map. Future updates will strive to improve upon this. Until then, plan on making use of the `${color}` variables and this Sass map. + +## Components + +Many of Bootstrap's components and utilities are built with `@each` loops that iterate over a Sass map. This is especially helpful for generating variants of a component by our `$theme-colors` and creating responsive variants for each breakpoint. As you customize these Sass maps and recompile, you'll automatically see your changes reflected in these loops. + +### Modifiers + +Many of Bootstrap's components are built with a base-modifier class approach. This means the bulk of the styling is contained to a base class (e.g., `.btn`) while style variations are confined to modifier classes (e.g., `.btn-danger`). These modifier classes are built from the `$theme-colors` map to make customizing the number and name of our modifier classes. + +Here are two examples of how we loop over the `$theme-colors` map to generate modifiers to the `.alert` component and all our `.bg-*` background utilities. + +{% highlight scss %} +// Generate alert modifier classes +@each $color, $value in $theme-colors { + .alert-#{$color} { + @include alert-variant(theme-color-level($color, -10), theme-color-level($color, -9), theme-color-level($color, 6)); + } +} + +// Generate `.bg-*` color utilities +@each $color, $value in $theme-colors { + @include bg-variant('.bg-#{$color}', $value); +} +{% endhighlight %} + +### Responsive + +These Sass loops aren't limited to color maps, either. You can also generate responsive variations of your components or utilities. Take for example our responsive text alignment utilities where we mix an `@each` loop for the `$grid-breakpoints` Sass map with a media query include. + +{% highlight scss %} +@each $breakpoint in map-keys($grid-breakpoints) { + @include media-breakpoint-up($breakpoint) { + $infix: breakpoint-infix($breakpoint, $grid-breakpoints); + + .text#{$infix}-left { text-align: left !important; } + .text#{$infix}-right { text-align: right !important; } + .text#{$infix}-center { text-align: center !important; } + } +} +{% endhighlight %} + +Should you need to modify your `$grid-breakpoints`, your changes will apply to all the loops iterating over that map. diff --git a/docs/4.0/getting-started/webpack.md b/docs/4.0/getting-started/webpack.md index 84ad74c7f..04af8d4f6 100644 --- a/docs/4.0/getting-started/webpack.md +++ b/docs/4.0/getting-started/webpack.md @@ -8,11 +8,11 @@ toc: true ## Installing Bootstrap -[Install bootstrap](/getting-started/download/#npm) as a node module using npm. +[Install bootstrap]({{ site.baseurl }}/docs/{{ site.docs_version }}/getting-started/download/#npm) as a Node.js module using npm. ## Importing JavaScript -Import [Bootstrap's JavaScript](/getting-started/javascript/) by adding this line to your app's entry point (usually `index.js` or `app.js`): +Import [Bootstrap's JavaScript]({{ site.baseurl }}/docs/{{ site.docs_version }}/getting-started/javascript/) by adding this line to your app's entry point (usually `index.js` or `app.js`): {% highlight js %} import 'bootstrap'; @@ -51,11 +51,11 @@ Notice that if you chose to **import plugins individually**, you must also insta ## Importing Styles -### Importing Precompiled SASS +### Importing Precompiled Sass To enjoy the full potential of Bootstrap and customize it to your needs, use the source files as a part of your project's bundling process. -First, create your own `_custom.scss` and use it to override the [built-in custom variables](/getting-started/options/). Then, use your main sass file to import your custom variables, followed by Bootstrap: +First, create your own `_custom.scss` and use it to override the [built-in custom variables]({{ site.baseurl }}/docs/{{ site.docs_version }}/getting-started/options/). Then, use your main sass file to import your custom variables, followed by Bootstrap: {% highlight scss %} @import "custom"; @import "~bootstrap/scss/bootstrap"; |
