Created
April 9, 2021 18:35
-
-
Save Ankhena/ada4232ccaf70c7df019ab7a13cd1b0d to your computer and use it in GitHub Desktop.
Tooltip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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! | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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')); | |
e.target.parentElement.classList.toggle('tooltip--open'); | |
})) | |
// закроем по клику мимо | |
document.addEventListener('mouseup', function (evt) { | |
if (evt.target.closest('.tooltip') === null) { | |
tooltip.forEach(tooltip => tooltip.classList.remove('tooltip--open')); | |
} | |
}); | |
// end tooltip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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