Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
<div class="tooltip">
<button class="tooltip__btn" type="button" aria-label="Подробности"></button>
<div class="tooltip__text">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusantium, deserunt, distinctio dolorum eaque eius eveniet ipsam mollitia nostrum pariatur quibusdam quisquam quo quod reprehenderit velit voluptas? Magnam sequi totam voluptate!
// tooltip
let tooltip = document.querySelectorAll('.tooltip');
let tooltipBtn = document.querySelectorAll('.tooltip__btn');
tooltipBtn.forEach(btn => btn.addEventListener('click', (e) => {
tooltip.forEach(tooltip => tooltip.classList.remove('tooltip--open'));'tooltip--open');
// закроем по клику мимо
document.addEventListener('mouseup', function (evt) {
if ('.tooltip') === null) {
tooltip.forEach(tooltip => tooltip.classList.remove('tooltip--open'));
// end tooltip
.tooltip {
position: relative;
display: inline-block;
.tooltip--open {
.tooltip__text {
position: absolute;
top: calc(100% + 12px);
left: 50%;
transform: translateX(-50%);
display: block;
width: max-content;
max-width: 250px;
padding: 12px;
border-radius: 12px;
font-size: 12px;
box-shadow: 0 0 16px 0 #C1CDDF;
background: white;
z-index: 2;
.tooltip__btn {
@extend .btn;
@extend .btn--only-icon;
@extend .btn--question;
.tooltip__text {
display: none;
.btn {
display: inline-block;
padding: 0.6em 1em;
border: none;
border-radius: 4px;
font-size: 18px;
font-family: inherit;
font-weight: inherit;
line-height: normal;
text-decoration: none;
text-align: center;
cursor: pointer;
&:focus {
outline: none;
opacity: 0.8;
.btn--only-icon {
padding: 0;
background-color: transparent;
border-color: transparent;
.btn--question {
display: inline-flex;
justify-content: center;
align-items: center;
width: 1em;
height: 1em;
border: 1.5px solid #dbdbdb;
border-radius: 50%;
color: #dbdbdb;
&::before {
content: "?";
font-size: 0.6em;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment