Re-examining the correctness of the circle sequence
P粉921165181
P粉921165181 2024-02-04 09:20:06
0
1
400

I expected the circles to be 1,2,3 and 4, but the output is 4,1,2 and 3. I don't know if position:absolute; is causing it to happen. Any feedback is welcome.

<template>
  <q-page class="column flex-center">
    <q-card class="my-card">
      <q-card-section>
        <div class="text-h6">Our Changing Planet</div>
        <div class="text-subtitle2">by John Doe</div>
      </q-card-section>

      <div
        v-for="index in 4"
        :key="index"
        class="circle"
        :style="`background-color: ${[index]}`"
      >
        {{ index }}
      </div>
    </q-card>
  </q-page>
</template>

<script setup></script>
<style lang="scss">
.my-card {
  width: 200px;
  height: 200px;
}

.circle {
  position: absolute;
  top: 20px;
  right: 0;
  background-color: $positive;
  width: 20px;
  height: 20px;
  border-radius: 50% !important;
  z-index: 1;
}

.circle:nth-child(2) {
  top: 40px;
  background-color: $negative;
}

.circle:nth-child(3) {
  top: 60px;
  background-color: orange;
}

.circle:nth-child(4) {
  top: 100px;
  background-color: grey;
}
</style>

https://stackblitz.com/edit/quasarframework-bybqfg?file=src/pages/IndexPage.vue

P粉921165181
P粉921165181

reply all(1)
P粉155710425

.circle:nth-child(n) Select elements that meet the following conditions:

  • 有级circle
  • is the nth child of its parent.

Your DOM looks like this:

  • .q-card__section // :nth-child(1)
  • .circle:Content 1 // :nth-child(2)
  • .circle:Content 2 // :nth-child(3)
  • .circle:Content 3 // :nth-child(4)
  • .circle:Content 4 // :nth-child(5)

You may get the expected result by wrapping .circle in a separate container:

  • .q-card__section // :nth-child(1)
  • div // :nth-child(2)
    • .circle:Content 1 // :nth-child(1)
    • .circle:Content 2 // :nth-child(2)
    • .circle:Content 3 // :nth-child(3)
    • .circle:Content 4 // :nth-child(4)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template