« Bootstrap 4 » : différence entre les versions
Apparence
(48 versions intermédiaires par le même utilisateur non affichées) | |||
Ligne 2 : | Ligne 2 : | ||
[[Category:Web]] | [[Category:Web]] | ||
= Liens = | = Liens = | ||
* [https://www.w3schools.com/bootstrap4/bootstrap_utilities.asp Bootstrap 4 Utilities] | * [https://www.w3schools.com/bootstrap4/bootstrap_utilities.asp Bootstrap 4 Utilities] | ||
* [https://codepen.io/nirmalkc/pen/JKjmVg Bootstrap Vertical Navigation with expand and collapse] | * [https://codepen.io/nirmalkc/pen/JKjmVg Bootstrap Vertical Navigation with expand and collapse] | ||
* [[fontawesome|Font Awesome]] | |||
= Description = | = Description = | ||
Ligne 13 : | Ligne 12 : | ||
= Layout = | = Layout = | ||
== [https://getbootstrap.com/docs/4. | == [https://getbootstrap.com/docs/4.5/layout/overview/ Container] == | ||
{| class="wikitable wtp wtmono1" | {| class="wikitable wtp wtmono1" | ||
! classe | ! classe | ||
Ligne 23 : | Ligne 22 : | ||
|} | |} | ||
== [http://getbootstrap.com/docs/4. | == [http://getbootstrap.com/docs/4.5/layout/grid/ Grid Layout] == | ||
{{info | Une page est divisé en 12 colonnes.}} | {{info | Une page est divisé en 12 colonnes.}} | ||
<kode lang='html'> | <kode lang='html'> | ||
Ligne 81 : | Ligne 80 : | ||
= Components = | = Components = | ||
== [https:// | == [https://getbootstrap.com/docs/4.5/components/buttons Button] == | ||
{| class="wikitable wtp" | {| class="wikitable wtp" | ||
|- style="font-family:monospace;" | |- style="font-family:monospace;" | ||
Ligne 95 : | Ligne 94 : | ||
</kode> | </kode> | ||
== [https://getbootstrap.com/docs/4. | == [https://getbootstrap.com/docs/4.5/components/alerts/ Alert] == | ||
<kode lang='html'> | <kode lang='html'> | ||
<div class="alert alert-danger" role="alert"> | <div class="alert alert-danger" role="alert"> | ||
Ligne 109 : | Ligne 108 : | ||
</kode> | </kode> | ||
== [https://getbootstrap.com/docs/4. | == [https://getbootstrap.com/docs/4.5/components/modal/ Modal - popup] == | ||
<kode lang='html'> | <kode lang='html'> | ||
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal"> | <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal"> | ||
Ligne 138 : | Ligne 137 : | ||
</div> | </div> | ||
</div> | </div> | ||
</kode> | |||
=== [https://stackoverflow.com/questions/19571955/how-to-make-modal-dialog-with-blur-background-using-twitter-bootstrap Blured background] === | |||
<kode lang='css'> | |||
body.modal-open { | |||
filter: blur(1px); | |||
} | |||
</kode> | </kode> | ||
Ligne 215 : | Ligne 221 : | ||
</kode> | </kode> | ||
== [https://getbootstrap.com/docs/4. | == [https://getbootstrap.com/docs/4.6/components/carousel Carousel] == | ||
* [https://getbootstrap.com/docs/4.6/components/carousel/#crossfade crossfade]: animate slides with a fade transition instead of a slide | |||
* {{boxx|1=data-interval="false"}}: not automatic cycle | |||
* <syntaxhighlight lang='css' inline>data-interval="false"</syntaxhighlight>: not automatic cycle | |||
== [https://getbootstrap.com/docs/4.6/components/spinners Spinner] == | |||
<kode lang='html'> | |||
<div id="spinner" class="text-center"> | |||
<div class="spinner-border text-info" role="status"> | |||
<span class="sr-only">Loading...</span> | |||
</div> | |||
</div> | |||
</kode> | |||
<kode lang='js'> | |||
$("#spinner").css("display", "none"); | |||
</kode> | |||
== [https://getbootstrap.com/docs/4.5/components/collapse Collapse] == | |||
<kode lang='html'> | |||
<a data-toggle="collapse" href="#filter" role="button" aria-expanded="false" aria-controls="filter"> | |||
<i class="fa fa-filter"></i> | |||
</a> | |||
<div class="collapse" id="filter"> | |||
</div> | |||
</kode> | |||
= Utilities = | = Utilities = | ||
== [https://getbootstrap.com/docs/4. | == [https://getbootstrap.com/docs/4.5/utilities/text/ Text] == | ||
{| class="wikitable wtp wtmono1" | {| class="wikitable wtp wtmono1" | ||
! classe | ! classe | ||
Ligne 230 : | Ligne 262 : | ||
|- | |- | ||
| text-uppercase || majuscules | | text-uppercase || majuscules | ||
|- | |||
| text-truncate || truncate the text with an ellipsis. Requires {{boxx|inline-block}} or {{boxx|block}} and {{boxx|width}} or {{boxx|max-width}} | |||
|} | |||
== [https://getbootstrap.com/docs/4.1/utilities/spacing Margin / Padding] == | |||
{| class="wikitable wtp wtmono1 wtmono2" | |||
! classe | |||
! Description | |||
|- | |||
| mt-0 || margin-top: 0 !important | |||
|- | |||
| mx-auto || margin-right: auto !important<br>margin-left: auto !important | |||
|- | |||
| p-3 || padding: $spacer !important | |||
|} | |||
{{info |1= Values from 0 to 5<br> | |||
{{boxx|1= 1=0.25rem}} {{boxx|1= 2=0.5rem}} {{boxx|1= 3=1rem}} {{boxx|1= 4=1.5rem}} {{boxx|1= 5=3rem}}<br> | |||
$spacer = 1rem, rem = root em = font-size defined in <html>}} | |||
== [https://getbootstrap.com/docs/4.1/utilities/colors Colors] == | |||
{| class="wikitable wtp wtmono1" | |||
! classe | |||
! Description | |||
|- | |||
| text-primary || blue | |||
|- | |||
| text-secondary || grey | |||
|- | |||
| text-success || green | |||
|- | |||
| text-danger || red | |||
|- | |||
| text-warning || yellow | |||
|- | |||
| text-info || light blue | |||
|- | |||
| bg-transparent || transparent | |||
|} | |||
== [https://getbootstrap.com/docs/4.1/utilities/flex Flex] == | |||
{| class="wikitable wtp wtmono1 wtmono2" | |||
! classe | |||
! Description | |||
|- | |||
| d-flex || display: flex | |||
|- | |||
| justify-content-around || justify-content: space-around | |||
|- | |||
| align-items-baseline || align-items: baseline | |||
|} | |||
== [https://getbootstrap.com/docs/4.5/utilities/borders Border] == | |||
{| class="wikitable wtp wtmono1 wtmono2" | |||
! classe | |||
! Description | |||
|- | |||
| border || border: 1px solid white | |||
|- | |||
| border-0 || border-width: 0px | |||
|- | |||
| border-primary || border-color: blue | |||
|- | |||
| rounded || border-radius: 0.25rem | |||
|} | |} | ||
Ligne 257 : | Ligne 352 : | ||
</kode> | </kode> | ||
= [ | = [https://getbootstrap.com/docs/4.1/components/tooltips/ Tooltip] = | ||
<kode lang='html'> | <kode lang='html'> | ||
< | <div data-toggle="tooltip" data-placement="top" title="Tooltip text"> | ||
Content text | |||
</div> | </div> | ||
</kode> | </kode> | ||
= [https:// | = Theme = | ||
{{ | * [https://themes.getbootstrap.com/collections/all Official paid themes] | ||
== [https://bootswatch.com/4/ Bootswatch: Free themes for Bootstrap] == | |||
* Download a theme ({{boxx|bootstrap.min.css}}) and replace the original bootstrap file | |||
* [https://bootswatch.com/help/ How to customize an existing theme] | |||
= [http://getbootstrap.com Installation] = | = [http://getbootstrap.com Installation] = | ||
< | Use [https://getbootstrap.com/docs/4.6/getting-started/introduction CDN] or [https://getbootstrap.com/docs/4.6/getting-started/download/ download] ready-to-use compiled code.<br> | ||
[https://getbootstrap.com/docs/versions versions] | |||
<kode lang='html'> | <kode lang='html'> | ||
<!doctype html> | <!doctype html> | ||
Ligne 289 : | Ligne 378 : | ||
<!-- Bootstrap CSS --> | <!-- Bootstrap CSS --> | ||
<link rel="stylesheet" href="https:// | <!-- option 1: CDN --> | ||
<link rel="stylesheet" | |||
href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" | |||
integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" | |||
crossorigin="anonymous"> | |||
<!-- option 2: file --> | |||
<link rel="stylesheet" href="css/bootstrap.min.css"> | |||
<title>Hello, world!</title> | <title>Hello, world!</title> | ||
Ligne 297 : | Ligne 392 : | ||
<!-- Optional JavaScript --> | <!-- Optional JavaScript --> | ||
<!-- jQuery first, then Popper.js | <!-- jQuery first, then bundle of Popper.js and Bootstrap.js --> | ||
<script src="https://code.jquery.com/jquery-3. | <!-- option 1: CDN --> | ||
<script src="https:// | <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" | ||
<script src=" | integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" | ||
crossorigin="anonymous"> | |||
</script> | |||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js" | |||
integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" | |||
crossorigin="anonymous"> | |||
</script> | |||
<!-- option 2: files --> | |||
<script src="js/jquery-3.5.1.slim.min.js"></script> | |||
<script src="js/bootstrap.bundle.min.js"></script> | |||
</body> | </body> | ||
</html> | </html> |
Dernière version du 29 mai 2021 à 15:53
Liens
Description
- Single Responsability Principle: les classes CSS ont 1 seul effet
- Normalisation: même rendu quelque soit le navigateur
- Responsive Design
Layout
Container
classe | Description |
---|---|
container | max-width, contenu centré |
container-fluid | width 100%, contenu centré |
Grid Layout
![]() |
Une page est divisé en 12 colonnes. |
<!-- définit une ligne -->
<div class="row">
<!-- définit 3 colonnes de même taille -->
<div class="col">...</div>
<div class="col">...</div>
<div class="col">...</div>
<div class="row">
<!-- définit 3 colonnes, la première 2x plus large que les autres. Il y a 12 colonnes (6-3-3) -->
<div class="col-6">...</div>
<div class="col">...</div>
<div class="col">...</div>
<!-- centrer verticalement tous les éléments de la ligne -->
<div class="row align-items-center">
<!-- centrer verticalement un élément de la ligne -->
<div class="col align-self-center">...</div>
<!-- centrer horizontalement la ligne -->
<div class="row justify-content-center">
|
classe | largeur max du conteneur |
---|---|
col- col-auto- | adaptation de la largeur au contenu |
col-sm- | 540px |
col-md- | 720px |
col-lg- | 960px |
col-xl- | 1140px |
Content
Tables
Classes | Description |
---|---|
table | séparateur entre chaque ligne |
table-striped | alternance de couleurs pour chaque ligne |
table-bordered | bordures autour des cellules |
table-hover | colore la ligne survolée par la sourie |
table-condensed | table plus petite |
Components
Button
btn-primary | btn-secondary | btn-success | btn-danger | btn-warning | btn-info | btn-light | btn-dark | btn-link |
bleu | gris | vert | rouge | jaune | cyan | blanc | noir | texte souligné bleu |
<a class="btn btn-danger" href="/delete.html">
<span class="glyphicon glyphicon-trash"></span>
</a>
|
Alert
<div class="alert alert-danger" role="alert">
Message d'alerte!
</div>
<div class="alert alert-warning alert-dismissible fade show" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
Message d'alerte!
</div>
|
Modal - popup
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Launch modal
</button>
<div class="modal fade" id="exampleModal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Modal body text goes here.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">Save changes</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
|
Blured background
body.modal-open {
filter: blur(1px);
}
|
<nav class="navbar navbar-inverse">
<div class="navbar-header">
<div class="navbar-brand">Navbar</a>
<button class="navbar-toggler" data-toggle="collapse" data-target="#navbarMenu">
<span class="navbar-toggler-icon"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="navbarMenu">
<ul class="nav navbar-nav"> <!-- aligné à gauche -->
<li><a asp-controller="MyController" asp-action="MyAction1">Link1</a></li>
<li class="navbar-text">Texte</li>
</ul>
<ul class="nav navbar-nav navbar-right"> <!-- aligné à droite -->
<li><a asp-controller="MyController" asp-action="MyAction2">Link2</a></li>
|
|
<nav id="menu" class="nav nav-pills nav-fill flex-column">
<a class="nav-item nav-link active" href="#">Active</a>
<a class="nav-item nav-link" href="#">Link</a>
<a class="nav-item nav-link" href="#">Link</a>
<a class="nav-item nav-link disabled" href="#">Disabled</a>
</nav>
|
#menu {
width: 200px;
}
|
Carousel
- crossfade: animate slides with a fade transition instead of a slide
- data-interval="false": not automatic cycle
data-interval="false"
: not automatic cycle
Spinner
<div id="spinner" class="text-center">
<div class="spinner-border text-info" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
|
$("#spinner").css("display", "none");
|
Collapse
<a data-toggle="collapse" href="#filter" role="button" aria-expanded="false" aria-controls="filter">
<i class="fa fa-filter"></i>
</a>
<div class="collapse" id="filter">
</div>
|
Utilities
Text
classe | Description |
---|---|
text-center | centrer le texte |
text-justify | justifier le texte |
font-weight-bold | gras |
text-uppercase | majuscules |
text-truncate | truncate the text with an ellipsis. Requires inline-block or block and width or max-width |
Margin / Padding
classe | Description |
---|---|
mt-0 | margin-top: 0 !important |
mx-auto | margin-right: auto !important margin-left: auto !important |
p-3 | padding: $spacer !important |
![]() |
Values from 0 to 5 1=0.25rem 2=0.5rem 3=1rem 4=1.5rem 5=3rem |
Colors
classe | Description |
---|---|
text-primary | blue |
text-secondary | grey |
text-success | green |
text-danger | red |
text-warning | yellow |
text-info | light blue |
bg-transparent | transparent |
Flex
classe | Description |
---|---|
d-flex | display: flex |
justify-content-around | justify-content: space-around |
align-items-baseline | align-items: baseline |
Border
classe | Description |
---|---|
border | border: 1px solid white |
border-0 | border-width: 0px |
border-primary | border-color: blue |
rounded | border-radius: 0.25rem |
Autres
classe | Description |
---|---|
float-left float-right | élément flottant |
d-block d-inline d-inline-block | display |
w-100 h-50 | width: 100%; height: 50%; |
Forms
<form>
<div class="form-group">
<label asp-for="MyProperty" class="control-label"></label>
<input asp-for="MyProperty" class="form-control" />
</div>
<div class="form-group">
<input type="submit" value="Save" class="btn btn-default" />
</div>
|
Tooltip
<div data-toggle="tooltip" data-placement="top" title="Tooltip text">
Content text
</div>
|
Theme
Bootswatch: Free themes for Bootstrap
- Download a theme (bootstrap.min.css) and replace the original bootstrap file
- How to customize an existing theme
Installation
Use CDN or download ready-to-use compiled code.
versions
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<!-- option 1: CDN -->
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css"
integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l"
crossorigin="anonymous">
<!-- option 2: file -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<title>Hello, world!</title>
</head>
<body>
<h1>Hello, world!</h1>
<!-- Optional JavaScript -->
<!-- jQuery first, then bundle of Popper.js and Bootstrap.js -->
<!-- option 1: CDN -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
crossorigin="anonymous">
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"
integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns"
crossorigin="anonymous">
</script>
<!-- option 2: files -->
<script src="js/jquery-3.5.1.slim.min.js"></script>
<script src="js/bootstrap.bundle.min.js"></script>
</body>
</html>
|
Images
<!-- responsive -->
<img src="..." class="img-fluid">
|