Ich habe versucht, einige Elemente mit Übergang in CSS zu verschieben. Ich habe es gut gemacht, indem ich für jedes Element, das ich überführen möchte, einen separaten Selektor hinzufüge, aber es funktioniert nicht, wenn ich einen Selektor für alle verwende (sie landen sowieso an der gleichen Stelle). Kann mir bitte jemand erklären, warum es so nicht funktioniert?CSS-Übergänge - Ich brauche eine Erklärung
body {
\t \t text-align: center;
\t }
\t .block {
\t \t position: relative;
\t \t display: inline-block;
\t }
\t .part1 {
\t \t font-family: Arial;
\t \t font-size: 50px;
\t \t font-weight: bold;
\t \t opacity: 0.2;
\t \t position: relative;
\t \t z-index: 1;
\t }
\t .part {
\t \t font-family: Arial;
\t \t font-size: 50px;
\t \t font-weight: bold;
\t \t opacity: 0.2;
\t \t position: absolute;
\t \t transition: top 2s ease-in, left 2s ease-in, right 2s ease-in;
\t }
\t .block .part:nth-child(2) {
\t \t top: 100px;
\t \t left: 100px;
\t }
\t .block .part:nth-child(3) {
\t \t top: 0;
\t \t left: 200px;
\t }
\t .block .part:nth-child(4) {
\t \t top: 0;
\t \t right: 200px;
\t }
\t .block .part:last-child {
\t \t top: 100px;
\t \t right: 100px;
\t }
\t .block .part1:hover ~ .part {
\t \t top: 0;
\t \t left: 0;
\t \t right: 0;
\t }
<span class="block">
\t \t <span class="part1">O</span>
\t \t <span class="part">O</span>
\t \t <span class="part">O</span>
\t \t <span class="part">O</span>
\t \t <span class="part">O</span>
</span>
Wie Sie sehen können, ist die linke Eigenschaft nicht für das vierte und fünfte Element übergehen.
Hier ist der Arbeits Schnipsel:
body {
\t \t text-align: center;
\t }
\t .block {
\t \t position: relative;
\t \t display: inline-block;
\t }
\t .part1 {
\t \t font-family: Arial;
\t \t font-size: 50px;
\t \t font-weight: bold;
\t \t opacity: 0.2;
\t \t position: relative;
\t \t z-index: 1;
\t }
\t .part {
\t \t font-family: Arial;
\t \t font-size: 50px;
\t \t font-weight: bold;
\t \t opacity: 0.2;
\t \t position: absolute;
\t \t transition: top 2s ease-in, left 2s ease-in, right 2s ease-in;
\t }
\t .block .part:nth-child(2) {
\t \t top: 100px;
\t \t left: 100px;
\t }
\t .block .part:nth-child(3) {
\t \t top: 0;
\t \t left: 200px;
\t }
\t .block .part:nth-child(4) {
\t \t top: 0;
\t \t right: 200px;
\t }
\t .block .part:last-child {
\t \t top: 100px;
\t \t right: 100px;
\t }
\t .block .part1:hover ~ .part:nth-child(2) {
\t \t top: 0;
\t \t left: 0;
\t }
\t .block .part1:hover ~ .part:nth-child(3) {
\t \t left: 0;
\t }
\t .block .part1:hover ~ .part:nth-child(4) {
\t \t right: 0;
\t }
\t .block .part1:hover ~ .part:last-child {
\t \t top: 0;
\t \t right: 0;
\t }
<span class="block">
\t \t <span class="part1">O</span>
\t \t <span class="part">O</span>
\t \t <span class="part">O</span>
\t \t <span class="part">O</span>
\t \t <span class="part">O</span>
\t </span>
Warum dies geschieht? Ich konnte die Antwort in der Dokumentation nicht finden.
Ich dachte, dass der Übergang von Auto auf 0 sollte auch animiert werden. "Ich schätze, ich lag falsch ... Tnx @Juan – fpiskur