Я хочу изменить стиль всплывающей подсказки (из tippy.js) и делаю именно так, как сказано в документах здесь:
Themes are created by including a class on the tippy-tooltip element as part of a selector in the form .tippy-tooltip.x-theme. Let's demonstrate this by creating our own theme called tomato:
.tippy-tooltip.tomato-theme {
background-color: tomato;
color: yellow;
}
To apply the theme, specify a theme prop without the -theme suffix:
tippy('button', {
theme: 'tomato',
});
Но по какой-то причине моя всплывающая подсказка остается цветом по умолчанию, почему?
Я добавил этот стиль:
.tippy-tooltip.tomato-theme {
background-color: tomato;
color: yellow;
}
.infosvg {
width: 20px;
}
tooltippy {
position: absolute;
top: 150px;
left: 300px;
}
Мой html
<span class = "tooltippy">
<img class = "infosvg" src = "assets/images/custom/icon_info.svg">
<div class = "tooltipcontent darktext">Test</div>
</span>
Мои JS:
$( ".tooltippy" ).each(function( i ) {
tippy(this, {
trigger: 'click',
allowHTML: true,
placement: 'right',
animation: 'scale-subtle',
interactive: true,
theme: 'tomato',
content: function (reference) {
return reference.querySelector('.tooltipcontent');
}
});
});
Что происходит не так? Я пробовал разные цвета в шестнадцатеричном формате или в тексте, как указано выше, но он остается всплывающей подсказкой по умолчанию.
Согласно документации вам нужно изменить эту строку:
.tippy-tooltip.tomato-theme {
к:
.tippy-box[data-theme~='tomato'] {
И, чтобы добавить стиль к стрелке, вам также нужно:
.tippy-box[data-theme~='tomato'][data-placement^='right'] > .tippy-arrow::before {
Фрагмент:
$( ".tooltippy" ).each(function( i ) {
tippy(this, {
trigger: 'click',
allowHTML: true,
placement: 'right',
animation: 'scale-subtle',
interactive: true,
theme: 'tomato',
content: function (reference) {
return reference.querySelector('.tooltipcontent');
}
});
});
.tippy-box[data-theme~='tomato'] {
background-color: tomato;
color: yellow;
}
.tippy-box[data-theme~='tomato'][data-placement^='right'] > .tippy-arrow::before {
border-right-color: tomato;
}
.infosvg {
width: 20px;
}
.tooltippy {
position: relative;
top: 150px;
left: 300px;
}
<script src = "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src = "https://unpkg.com/@popperjs/core@2/dist/umd/popper.min.js"></script>
<script src = "https://unpkg.com/tippy.js@6/dist/tippy-bundle.umd.js"></script>
<div>
<span class = "tooltippy">
<img class = "infosvg" src = "https://upload.wikimedia.org/wikipedia/commons/e/e4/Infobox_info_icon.svg">
<div class = "tooltipcontent darktext">Test</div>
</span>
</div>
Спасибо! Я смотрел не ту версию, лол.