Tạo Tooltips cơ bản
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Enable Bootstrap Tooltips via JavaScript</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Bootstrap Font Icon CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
<style>
/* Some custom styles to beautify this example */
.bs-example{
margin: 60px 0;
}
a, button{
margin-right: 30px;
}
i{
font-size: 22px;
}
</style>
<script>
document.addEventListener("DOMContentLoaded", function(){
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
var tooltipList = tooltipTriggerList.map(function(element){
return new bootstrap.Tooltip(element);
});
});
</script>
</head>
<body>
<div class="mt-3 mx-5">
<h2>Tooltips on Links</h2>
<div class="bs-example">
<a href="#" data-bs-toggle="tooltip" title="Default tooltip">Tooltip</a>
<a href="#" data-bs-toggle="tooltip" title="Another tooltip">Another tooltip</a>
<a href="#" data-bs-toggle="tooltip" title="A much longer tooltip to demonstrate the max-width of the Bootstrap tooltip.">Large tooltip</a>
<a href="#" data-bs-toggle="tooltip" title="The last tip!">Last tooltip</a>
</div>
<h2>Tooltips on Buttons</h2>
<div class="bs-example">
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" title="Default tooltip">Tooltip</button>
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" title="Another tooltip">Another tooltip</button>
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" title="A much longer tooltip to demonstrate the max-width of the Bootstrap tooltip.">Large tooltip</button>
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" title="The last tip!">Last tooltip</button>
</div>
<h2>Tooltips on Icons</h2>
<div class="bs-example">
<a href="#" data-bs-toggle="tooltip" title="Edit"><i class="bi-pencil-fill"></i></a>
<a href="#" data-bs-toggle="tooltip" title="Save"><i class="bi-save-fill"></i></a>
<a href="#" data-bs-toggle="tooltip" title="Print"><i class="bi-printer-fill"></i></a>
<a href="#" data-bs-toggle="tooltip" title="Delete"><i class="bi-trash"></i></a>
<a href="#" data-bs-toggle="tooltip" title="Settings"><i class="bi-gear-fill"></i></a>
</div>
</div>
</body>
</html>
Thấy bài viết hữu ích?
Ủng hộ tác giả để có thêm nhiều bài viết chất lượng nhé!