Gunakan atribut `margin` pada elemen `tetap` dan `z-index: 1`
P粉986028039
P粉986028039 2023-09-17 21:44:03
0
1
663

Mempunyai senarai dan ruangan komen. Medan ulasan ditetapkan ke bahagian bawah halaman. Apabila senarai panjang, tatal halaman digunakan. fixed 到页面底部。当列表很长时,会应用页面滚动。

我希望列表底部始终与评论字段顶部保持一定的垂直距离。当然,我可以将 margin-bottom 属性应用于 .meaning 类(它形成列表),但是如果注释字段包含 2 或 3 行文本(即,对于设置边距来说太高了)。

因此,在我看来,将 margin-top 设置为 comment 字段更有意义。但是,可能由于评论字段的 z-index: 1 属性,margin-top

Saya mahu bahagian bawah senarai sentiasa berada dalam jarak menegak dari bahagian atas medan ulasan. Sudah tentu, saya boleh menggunakan atribut margin-bottom pada kelas .meaning (yang membentuk senarai), tetapi jika medan ulasan mengandungi 2 atau 3 baris teks ( iaitu, untuk menetapkan margin terlalu tinggi untuk jarak).

🎜🎜Jadi, pada pendapat saya, lebih masuk akal untuk menetapkan margin-top kepada medan ulasan. Walau bagaimanapun, mungkin disebabkan oleh atribut z-index: 1 bagi medan ulasan, margin-top juga tidak berfungsi. 🎜 🎜Inilah Tong JS, untuk berjaga-jaga. 🎜 🎜
      .meaning {
        list-style-type: none;
        counter-reset: item;
        hyphens: auto;
        font-size: calc(0.7em + 1.5vw);
      }

      .meaning > li {
        position: relative;
      }

      .meaning > li::before {
        content: counter(item);
        counter-increment: item;
        position: absolute;
        top: 0;
        text-align: center;
        margin-left: calc(-0.7em - 2.5vw);          
      }

      .meaning-word {
        margin-top: 50px;
      }

      .sentences {
        list-style-type: none;
        padding-left: 0;
        font-size: calc(0.7em + 1.5vw);
        margin-top: 30px;                   
      }

      .sentences > li.sentence-en {
        color: #5d78e5;
      }

      .sentences > li.sentence-de {
        margin-top: 5px;
      }

      .comment {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        background-color: #fdf1d1;
        color: #f92504;
        font-size: calc(0.5em + 2vw);
        margin: 0;
        padding: 5px 4vw;
        box-sizing: border-box;
        z-index: 1;
      }
<!DOCTYPE html>
<html>
<body>
    
  <ol class="meaning">
    <li class="meaning-word">Meaning1</li>
      <ul class="sentences">
        <li class="sentence-en">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum</li>
        <li class="sentence-de">Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</li>
      </ul>
    <li class="meaning-word">Meaning2</li>
      <ul class="sentences">
        <li class="sentence-en">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum</li>
        <li class="sentence-de">Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</li>
    </ul>
  </ol>
  
    <div class="comment">
    <p>This is line 1 of text information.</p>
  </div>

</body>
</html>
🎜
P粉986028039
P粉986028039

membalas semua(1)
P粉605233764

Gunakan position: sticky 替代,然后你可以轻松地设置 margin-top kerana elemen kekal dalam aliran

.meaning {
  list-style-type: none;
  counter-reset: item;
  hyphens: auto;
  font-size: calc(0.7em + 1.5vw);
}

.meaning>li {
  position: relative;
}

.meaning>li::before {
  content: counter(item);
  counter-increment: item;
  position: absolute;
  top: 0;
  text-align: center;
  margin-left: calc(-0.7em - 2.5vw);
}

.meaning-word {
  margin-top: 50px;
}

.sentences {
  list-style-type: none;
  padding-left: 0;
  font-size: calc(0.7em + 1.5vw);
  margin-top: 30px;
}

.sentences>li.sentence-en {
  color: #5d78e5;
}

.sentences>li.sentence-de {
  margin-top: 5px;
}

.comment {
  position: sticky;
  bottom: 0;
  background-color: #fdf1d1;
  color: #f92504;
  font-size: calc(0.5em + 2vw);
  margin-top: 40px;
  padding: 5px 4vw;
  box-sizing: border-box;
}
<ol class="meaning">
    <li class="meaning-word">Meaning1</li>
    <ul class="sentences">
      <li class="sentence-en">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
        It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with
        desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum</li>
      <li class="sentence-de">Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked
        up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus
        Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a
        line in section 1.10.32.</li>
    </ul>
    <li class="meaning-word">Meaning2</li>
    <ul class="sentences">
      <li class="sentence-en">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
        It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with
        desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum</li>
      <li class="sentence-de">Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked
        up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus
        Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a
        line in section 1.10.32.</li>
    </ul>
  </ol>

  <div class="comment">
    <p>This is line 1 of text information.</p>
  </div>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan