-
-
Notifications
You must be signed in to change notification settings - Fork 79.1k
Add new Approach docs page #25165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
+71
−0
Merged
Add new Approach docs page #25165
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
271b591
Stub out a list for Approach docs page
mdo 2258295
Update approach.md
mdo 34f020c
flesh out a first pass at the approach docs page
mdo 953eac9
Update approach.md
XhmikosR 1e698c2
Merge branch 'v4-dev' into approach
XhmikosR 278971e
Rename section to classes and flesh out content there, mentioning typ…
mdo dc6636d
clarify, add more to responsive section, add more to modifiers
mdo 7799473
mention the good stuff
mdo 827e966
Merge branch 'v4-dev' into approach
XhmikosR 09b0089
Merge branch 'v4-dev' into approach
XhmikosR ed48548
copy tweaks
mdo 769cf0c
Merge branch 'v4-dev' into approach
XhmikosR ec5f671
Merge branch 'v4-dev' into approach
XhmikosR File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,76 @@ | ||
--- | ||
layout: docs | ||
title: Approach | ||
description: Learn about the guiding principles, strategies, and techniques used to build and maintain Bootstrap so you can more easily customize and extend it yourself. | ||
group: extend | ||
--- | ||
|
||
While the getting started pages provide an introductory tour of the project and what it offers, this document focuses on _why_ we do the things we do in Bootstrap. It explains our philosophy to building on the web so that others can learn from us, contribute with us, and help us improve. | ||
|
||
See something that doesn't sound right, or perhaps could be done better? [Open an issue](https://github.com/twbs/bootstrap/issues/new)—we'd love to discuss it with you. | ||
|
||
## Summary | ||
|
||
We'll dive into each of these more throughout, but at a high level, here's what guides our approach. | ||
|
||
- Components should be responsive and mobile-first | ||
- Components should be built with a base class and extended via modifier classes | ||
- Component states should obey a common z-index scale | ||
- Whenever possible, prefer a HTML and CSS implementation over JavaScript | ||
- Whenever possible, use utilities over custom styles | ||
- Whenever possible, avoid enforcing strict HTML requirements (children selectors) | ||
|
||
## Responsive | ||
|
||
Bootstrap's responsive styles are built to be responsive, an approach that's often referred to as _mobile-first_. We use this term in our docs and largely agree with it, but at times it can be too broad. While not every component _must_ be entirely responsive in Bootstrap, this responsive approach is about reducing CSS overrides by pushing you to add styles as the viewport becomes larger. | ||
|
||
Across Bootstrap, you'll see this most clearly in our media queries. In most cases, we use `min-width` queries that begin to apply at a specific breakpoint and carry up through the higher breakpoints. For example, a `.d-none` applies from `min-width: 0` to infinity. On the other hand, a `.d-md-none` applies from the medium breakpoint and up. | ||
|
||
At times we'll use `max-width` when a component's inherent complexity requires it. At times, these overrides are functionally and mentally clearer to implement and support than rewriting core functionality from our components. We strive to limit this approach, but will use it from time to time. | ||
|
||
## Classes | ||
|
||
Aside from our Reboot, a cross-browser normalization stylesheet, all our styles aim to use classes as selectors. This means steering clear of type selectors (e.g., `input[type="text"]`) and extraneous parent classes (e.g., `.parent .child`) that make styles too specific to easily override. | ||
|
||
As such, components should be built with a base class that houses common, not-to-be overridden property-value pairs. For example, `.btn` and `.btn-primary`. We use `.btn` for all the common styles like `display`, `padding`, and `border-width`. We then use modifiers like `.btn-primary` to add the color, background-color, border-color, etc. | ||
|
||
Modifier classes should only be used when there are multiple properties or values to be changed across multiple variants. Modifiers are not always necessary, so be sure you're actually saving lines of code and preventing unnecessary overrides when creating them. Good examples of modifiers are our theme color classes and size variants. | ||
|
||
## z-index scales | ||
|
||
There are two `z-index` scales in Bootstrap—elements within a component and overlay components. | ||
|
||
### Component elements | ||
|
||
- Some components in Bootstrap are built with overlapping elements to prevent double borders without modifying the `border` property. For example, button groups, input groups, and pagination. | ||
- These components share a standard `z-index` scale of `0` through `3`. | ||
- `0` is default (initial), `1` is `:hover`, `2` is `:active`/`.active`, and , `3` is `:focus`. | ||
- This approach matches our expectations of highest user priority. If an element is focused, it's in view and at the user's attention. Active elements are second highest because they indicate state. Hover is third highest because it indicates user intent, but nearly _anything_ can be hovered. | ||
|
||
### Overlay components | ||
|
||
Bootstrap includes several components that function as an overlay of some kind. This includes, in order of highest `z-index`, dropdowns, fixed and sticky navbars, modals, tooltips, and popovers. These components have their own `z-index` scale that begins at `1000`. This starting number is random and serves as a small buffer between our styles and your project's custom styles. | ||
|
||
Each overlay component increases it's `z-index` value slightly in such a way that common UI principles allow user focused or hovered elements to remain in view at all times. For example, a modal is document blocking (e.g., you cannot take any other action save for the modal's action), so we put that above our navbars. | ||
|
||
Learn more about this in our [`z-index` layout page](/docs/4.0/layout/overview/#z-index). | ||
|
||
## HTML and CSS over JS | ||
|
||
Whenever possible, we prefer to write HTML and CSS over JavaScript. In general, HTML and CSS are more prolific and accessible to more people of all different experience levels. HTML and CSS are also faster in your browser than JavaScript, and your browser general provides a great deal of functionality for you. | ||
|
||
This principle is our first-class JavaScript API is `data` attributes. You don’t need to write nearly any JavaScript to use our JavaScript plugins; instead, write HTML. Read more about this in [our JavaScript overview page](). | ||
|
||
Lastly, our styles build on the fundamental behaviors of common web elements. Whenever possible, we prefer to use what the browser provides. For example, you can put a `.btn` class on nearly any element, but most elements don’t provide any semantic value or browser functionality. So instead, we use `<button>`s and `<a>`s. | ||
|
||
The same goes for more complex components. While we *could* write our own form validation plugin to add classes to a parent element based on an input’s state, thereby allowing us to style the text say red, we prefer using the `:valid`/`:invalid` pseudo-elements every browser provides us. | ||
|
||
## Utilities | ||
|
||
Utility classes—formerly helpers in Bootstrap 3—are a powerful ally in combatting CSS bloat and poor page performance. A utility class is typically a single, immutable property-value pairing expressed as a class (e.g., `.d-block` represents `display: block;`). Their primary appeal is speed of use while writing HTML and limiting the amount of custom CSS you have to write. | ||
|
||
Specifically regarding custom CSS, utilities can help combat increasing file size by reducing your most commonly repeated property-value pairs into single classes. This can have a dramatic effect at scale in your projects. | ||
|
||
## Flexible HTML | ||
|
||
While not always possible, we strive to avoid being overly dogmatic in our HTML requirements for components. Thus, we focus on single classes in our CSS selectors and try to avoid immediate children selectors (`~`). This gives you more flexibility in your implementation and helps keep our CSS simpler and less specific. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also mention that we never do type selectors, and elements are styled through classes.