Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> HTML

Cách thêm lớp nội tuyến (inline layer) với thẻ ilayer trong HTML?

Thẻ <ilayer> (Netscape 4 proprietary) tạo lớp nội tuyến trong luồng văn bản. Đã lỗi thời hoàn toàn, không được hỗ trợ bởi bất kỳ trình duyệt hiện đại nào. Không sử dụng.

Thay thế hiện đại

Dùng CSS positioning:

  • position: relative + top/left — dịch chuyển nhưng vẫn chiếm chỗ.
  • position: absolute — khỏi luồng, định vị theo ancestor gần nhất position != static.
  • position: fixed — định vị theo viewport.
  • position: sticky — kết hợp relative + fixed.
  • z-index — thứ tự chồng lớp.

Ví dụ CSS tương đương

<!DOCTYPE html>
<html>
  <head>
    <style>
      .shift-down { position: relative; top: 4px; }
      .shift-right { position: relative; left: 10px; }
      .shift-up { position: relative; top: -4px; }
      .shift-left { position: relative; left: -10px; }
    </style>
  </head>
  <body>
    Từ này <span class="shift-down">xuống</span>, từ này <span class="shift-right">sang phải</span>.
    Với giá trị âm: <span class="shift-up">lên</span> và <span class="shift-left">trái</span>.
  </body>
</html>

Lưu ý

  • <ilayer> chỉ từng hoạt động trên Netscape Navigator 4 (năm 1997).
  • Tham khảo lịch sử: <layer>, <ilayer> là tiền thân của CSS Positioning.