I would like to change the max width of a Bootstrap Tooltip without changing the others. I don’t use Sass or SCSS. I try many stuff based on the documentation:
tooltip-max-width="300px"
bs-tooltip-max-width="300px"
data-bs-tooltip-max-width="300px"
data-bs-max-width="300px"
The Tooltip is initialized in my JS code. I also try to add the custom parameter in the option, but it does not work.
this.buttonTooltip = new bootstrap.Tooltip(this.buttonImageEl, { html: true, maxWidth: "300px" });
Does any one know how to do this?
2
Answers
Use the data-bs-custom-class attribute
Bootstrap dynamically creates Tooltips with a unique ID and appends them to the end of the document body. So the easy way to change specific Tooltips is to add a custom class using the
data-bs-custom-class
attribute. Bootstrap adds the class name to the tooltip (not the target) when it is created.Add the attribute to the target:
Add css to change the width:
The snippet shows both a wide and default Tooltip.
Snippet
maxWidth
is not a member ofoptions
. So the code won’t work. But still you can usecustomClass
in theoptions
. You can set the value from both attribute and options.P.S: You should use the
!important
. Otherwise it’s getting overriden.