Rumah > Soal Jawab > teks badan
P粉5390555262023-08-03 11:07:47
Mengasingkan beberapa elemen di bahagian atas halaman adalah sukar apabila menatal, jadi saya mencadangkan penyelesaian yang lebih mudah. "Melompat" bar melekit anda adalah kerana kedudukan awal bar melekit berbeza daripada tempat ia berada di bahagian atas halaman semasa menatal
Untuk mengelakkan garis jam anda hilang semasa menatal, saya akan meletakkan semua komponen yang anda mahu simpan di bahagian atas halaman dalam bekas, seperti div, dan kemudian menjadikan bekas itu melekit.
Masalah kedua ialah bar melekit anda agak rendah pada mulanya kerana tetapan margin badan lalai (10px). Kemudian kami menatal halaman - jidar badan telah ditatal, dan anda menetapkan bar melekit untuk berada di bahagian atas sepenuhnya (atas: 0;), jadi ia perlu melonjak 10px tambahan ke atas. Penyelesaian cepat adalah untuk menetapkan margin atas badan kepada 0 dan kemudian bar tampal anda akan sentiasa berada dalam kedudukan yang sama di bahagian atas halaman.
Di bawah ialah coretan kod yang dikemas kini.
body { margin-top: 0; } .sticky-container { position: sticky; top: 0; z-index: 1; background-color: white; } .word { padding: 1vw 3vw 2% 3vw; } .word-details { display: flex; justify-content: space-between; align-items: baseline; } .transcription { font-weight: normal; } .warning { color: red; margin-left: auto; } .line { border-top: 2px solid #fdb239; } .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-ru { margin-top: 15px; }
<html> <body> <div class="sticky-container"> <div class="word"> <span>Word</span> <div class="word-details"> <div class="transcription">/ transcription /</div> <div class="warning">COMMENT</div> </div> </div> <hr class="line"> </div> <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-ru">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> </ul> </ol> </body> </html>