Image background-position dans le CSS

0

La question

Je suis actuellement en train de passer par un site web bannière via chrome developer tools(Inspecter). J'ai remarqué que l'un particulier de la bannière a le jeu de règles suivant dans son CSS:

 banner{ 
     background-position:bottom;
     background-position-x: center;
     background-position-y: center;
  }

Est-ce juste une formalité?. Parce que, quand j'ai enlevé les trois propriétés de l'arrière et de définir background-position: centerla bannière n'a pas été affecté en aucune façon.

À partir d'un développeur wannabe. Merci

background-image css html javascript
2021-11-24 02:09:29
1

La meilleure réponse

1

Cette bannière a juste mauvais CSS.
background-position est une abréviation pour, background-position-x et background-position-y.

Donc,

banner { 
  background-position: bottom;
  background-position-x: center; /* This is not doing anything, because x became 'center' when it was omitted above. */
  background-position-y: center; /* This will override the previously set 'bottom' */
}

Comme vous l'avez mentionné, background-position: center fait le même travail, puisque x et y sont 'centre'.

Il n'y a rien de mal avec l'aide de mots clés, mais si vous êtes juste de commencer avec les CSS, je vous recommande fortement de vous habituer à l'aide de pourcentages.
(Vous me remercierez plus tard, quand vous avez besoin de plus le positionnement précis à l'aide de calc().

background: 0% 100% = background: left bottom
background: 100% 0% = background: right top
background: 50% 50% = background: center center

Source: https://developer.mozilla.org/en-US/docs/Web/CSS/background-position

2021-11-24 02:48:59

Dans d'autres langues

Cette page est dans d'autres langues

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................