Thẻ HTML <legend>
Định nghĩa và cách sử dụng thẻ <legend>
Thẻ <legend>
xác định chú thích cho phần tử <fieldset>
. Ví dụ sau nhóm các yếu tố liên quan trong một biểu mẫu:
<form action="/action_page.php">
<fieldset>
<legend>Thông tin cá nhân:</legend>
<label for="fname">Họ:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Tên:</label>
<input type="text" id="lname" name="lname"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
<label for="birthday">Ngày sinh:</label>
<input type="date" id="birthday" name="birthday"><br><br>
<input type="submit" value="Submit">
</fieldset>
</form>
Hỗ trợ trình duyệt
Phần tử <legend> | Google Chrome | MS Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Có | Có | Có | Có | Có |
Thuộc tính Global
Thẻ <legend>
cũng hỗ trợ các thuộc tính Global trong HTML.
Thuộc tính sự kiện
Thẻ <legend>
cũng hỗ trợ thuộc tính sự kiện trong HTML.
Các ví dụ khác
Để chú thích fieldset nổi ở bên phải (với CSS):
<form action="/action_page.php">
<fieldset>
<legend style="float:right">Thông tin cá nhân:</legend>
<label for="fname">Họ:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Tên:</label>
<input type="text" id="lname" name="lname"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
<label for="birthday">Ngày sinh:</label>
<input type="date" id="birthday" name="birthday"><br><br>
<input type="submit" value="Submit">
</fieldset>
</form>
Sử dụng CSS để tạo kiểu cho <fieldset>
và <legend>
:
<html>
<head>
<style>
fieldset {
background-color: #eeeeee;
}
legend {
background-color: gray;
color: white;
padding: 5px 10px;
}
input {
margin: 5px;
}
</style>
</head>
<body>
<form action="/action_page.php">
<fieldset>
<legend>Thông tin cá nhân:</legend>
<label for="fname">Họ:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Tên:</label>
<input type="text" id="lname" name="lname"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
<label for="birthday">Ngày sinh:</label>
<input type="date" id="birthday" name="birthday"><br><br>
<input type="submit" value="Submit">
</fieldset>
</form>
</body>
</html>
Cài đặt CSS mặc định
Hầu hết mọi trình duyệt sẽ hiển thị phần tử <legend>
với các giá trị mặc định sau:
legend {
display: block;
padding-left: 2px;
padding-right: 2px;
border: none;
}
399
Bài trước
Bạn nên đọc
Xác thực tài khoản!
Theo Nghị định 147/2024/ND-CP, bạn cần xác thực tài khoản trước khi sử dụng tính năng này. Chúng tôi sẽ gửi mã xác thực qua SMS hoặc Zalo tới số điện thoại mà bạn nhập dưới đây:
Số điện thoại chưa đúng định dạng!
0 Bình luận
Sắp xếp theo

Xóa Đăng nhập để Gửi

Cũ vẫn chất
-
Hàm COUNTIFS, cách dùng hàm đếm ô theo nhiều điều kiện trong Excel
Hôm qua -
Các cách làm, tùy chỉnh trong bài sẽ giúp tăng tốc Windows 10 của bạn "nhanh như gió"
Hôm qua 6 -
Cách sửa lỗi không thấy bộ điều hợp mạng trên Windows 10
Hôm qua -
Code Tiểu Yêu Tầm Đạo mới nhất
Hôm qua -
Cách dùng Terabox lưu trữ với 1TB miễn phí
Hôm qua 5 -
Cách nhận Cursed Dual Katana Blox Fruit
2 ngày -
Cách tắt đã đọc tin nhắn TikTok
2 ngày -
Cách đặt độ phân giải tùy chỉnh trong OBS
2 ngày -
Cách kiểm duyệt, chặn bình luận comment trên Fanpage Facebook
2 ngày -
Cách sao chép hoặc tạo bản sao toàn bộ trang tính trong Google Sheets
Hôm qua