Comment centrer un élément avec Bootstrap ?

Réponses rédigées par Antoine
Dernière mise à jour : 2020-12-19 23:08:30
Question

Comment puis-je centrer un élément HTML avec Bootstrap ?

Réponse

Pour centrer un texte dans son bloc, de manière horizontale, avec Bootstrap, vous devez utiliser la CLASS .text-center :

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Comment centrer un texte avec Bootstrap ?</title>
<link rel="stylesheet" href= "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> 
</head>
<body>
<p class="text-center">Un texte centré</p>
</body>
</html>

Pour centrer un bloc dans son bloc, avec Bootstrap, vous devez utiliser la CLASS .d-flex align-item-center pour centrer le bloc de manière verticale, ou bien .d-flex justify-content-center pour le centrer de manière horizontale.