Maison > Article > interface Web > Comment définir l'image d'arrière-plan pour qu'elle soit centrée de manière adaptative en CSS
Comment définir le centrage adaptatif de l'image d'arrière-plan en CSS : Vous pouvez le définir à l'aide de l'attribut background-position, tel que [background-positiion:center;], la valeur de l'attribut center signifie centrage.

L'environnement d'exploitation de cet article : système Windows 10, CSS 3, ordinateur thinkpad t480.
Introduction à l'attribut :
En CSS, si nous voulons qu'une image soit affichée verticalement au centre, alors nous pouvons utiliser l'attribut background-position pour y parvenir.
Introduction à l'attribut :
L'attribut background-position définit la position de départ de l'image d'arrière-plan.
Par exemple, si nous voulons utiliser une image locale comme arrière-plan et la centrer, alors nous pouvons faire ceci :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文网(php.cn)</title>
<style>
body
{
background-image:url('smiley.gif');
background-repeat:no-repeat;
background-attachment:fixed;
background-position:center;
}
</style>
</head>
<body>
<p><b>注意:</b>该属性工作在 Firefox 和 Opera, background-attachment 属性会被设置为 "fixed"。</p>
</body>
</html>Recommandations associées : Tutoriel CSS
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!