Main content ah kal rawh Docs navigation ah kal rawh
Check
in English

Hmanraw hman dan tur

Animation atan CSS3 hmanga CSS leh JavaScript hmanga custom Bootstrap tooltips dah belh dan tur documentation leh entirnan leh local title storage atan data-bs-attribute te.

A tlangpuiin

Tooltip plugin hman huna hriat tur awmte:

  • Tooltips hian positioning atan third party library Popper a ring tlat a ni. , hmain popper.min.js i dah tel tur a ni a , a nih loh leh Popper awmna bootstrap.jshmang tur a ni.bootstrap.bundle.min.js
  • Tooltips hi performance avanga opt-in a nih avangin nangmah ngeiin i initialize tur a ni .
  • Zero-length title nei tootip te hi a lang ngai lo.
  • container: 'body'Component complex zawk (kan input group, button group, etc)-a rendering problem awm loh nan specify rawh .
  • Hidden elements-a tooltips trigger hian hna a thawk dawn lo.
  • Tooltips for .disabledor disabledelements te chu wrapper element ah trigger tur a ni.
  • Line tam tak huam chhunga hyperlink atanga trigger a nih chuan tooltips te chu centered a ni ang. Hetiang thiltih hi pumpelh nan white-space: nowrap;i s hmangin hmang rawh .<a>
  • Tooltips te hi DOM atanga an element inmil te an paih hmain thup hmasak phawt a ngai a ni.
  • Shadow DOM chhunga element awm avangin tootips hi a trigger thei a ni.

Chutiang zawng zawng chu i nei em? A ropui hle mai, entirnan thenkhat nen an hnathawh dan i en ang u.

Default-ah chuan he component hian built-in content sanitizer a hmang a, chu chuan HTML element chiang taka phal loh zawng zawng a strip chhuak vek a ni. Kan JavaScript documentation-a sanitizer section-ah hian a chipchiar zawkin en rawh .
He component hian animation effect hi prefers-reduced-motionmedia query ah a innghat a ni. Kan accessibility documentation a reduced motion tih hi en la .

Entirna te

Tooltips te chu enable rawh

A chunga kan sawi tawh ang khan tooltips te hi i hman theih hmain i initialize hmasa phawt tur a ni. Page pakhata tooltip zawng zawng initialize dan pakhat chu an data-bs-toggleattribute hmanga thlan chhuah a ni ang, hetiang hian:

const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]')
const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))

A hnuaia link te hi hover la, tooltips i hmu ang:

Tooltips hmanga inline link thenkhat entir nan placeholder text . Hei hi tunah chuan filler mai a ni tawh a, killer a awm tawh lo. Hetah hian thuziak tak tak awmna entawn tur chauha dah content . Tin, chu zawng zawng chu khawvel tak tak dinhmuna hman a nih chuan toltips te hi engtin nge a awm ang tih ngaihtuahna pe turin chauh a ni. Chuvangin tunah chuan link-a heng tooltips te hi engtin nge practice-a a thawh theih tih i hmu tawh ngei ka beisei , vawi khat chu i site emaw project emaw-a i hman hnuah.

html tih a ni
<p class="muted">Placeholder text to demonstrate some <a href="#" data-bs-toggle="tooltip" data-bs-title="Default tooltip">inline links</a> with tooltips. This is now just filler, no killer. Content placed here just to mimic the presence of <a href="#" data-bs-toggle="tooltip" data-bs-title="Another tooltip">real text</a>. And all that just to give you an idea of how tooltips would look when used in real-world situations. So hopefully you've now seen how <a href="#" data-bs-toggle="tooltip" data-bs-title="Another one here too">these tooltips on links</a> can work in practice, once you use them on <a href="#" data-bs-toggle="tooltip" data-bs-title="The last tip!">your own</a> site or project.
</p>
Zalen takin i HTML ah titleemaw hmang thei ang che. data-bs-titleA hman hunah chuan Popper chuan element render a nih hunah titleautomatic in a thlak ang .data-bs-title

Custom tooltips te pawh a awm bawk

v5.2.0 ah dah belh a ni

CSS variable hmangin tooltips awm dan tur i siam danglam thei bawk . Kan custom appearance scope turin custom class kan set a data-bs-custom-class="custom-tooltip", local CSS variable override nan kan hmang bawk.

.custom-tooltip {
  --bs-tooltip-bg: var(--bs-primary);
}
html tih a ni
<button type="button" class="btn btn-secondary"
        data-bs-toggle="tooltip" data-bs-placement="top"
        data-bs-custom-class="custom-tooltip"
        data-bs-title="This top tooltip is themed via CSS variables.">
  Custom tooltip
</button>

Kawng zawh dan tur

A hnuaia button-te chungah hian hover la, tooltips direction pali: chunglam, dinglam, hnuai lam, leh veilam te chu i hmu ang. RTL a Bootstrap hman hian directions a mirror thin.

<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Tooltip on top">
  Tooltip on top
</button>
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="right" data-bs-title="Tooltip on right">
  Tooltip on right
</button>
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="bottom" data-bs-title="Tooltip on bottom">
  Tooltip on bottom
</button>
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="left" data-bs-title="Tooltip on left">
  Tooltip on left
</button>

Tin, custom HTML a dah belh bawk a:

<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-html="true" data-bs-title="<em>Tooltip</em> <u>with</u> <b>HTML</b>">
  Tooltip with HTML
</button>

SVG hmangin:

CSS a ni

Variables te pawh a awm

v5.2.0 ah dah belh a ni

Bootstrap-in CSS variables approach a kalpui mek zingah hian tunah chuan tooltipps hian local CSS variables on hmangin .tooltipreal-time customization tihchangtlun nan an hmang ta a ni. CSS variable hrang hrangte tana value te hi Sass hmanga set a nih avangin Sass customization pawh a la support reng bawk.

  --#{$prefix}tooltip-zindex: #{$zindex-tooltip};
  --#{$prefix}tooltip-max-width: #{$tooltip-max-width};
  --#{$prefix}tooltip-padding-x: #{$tooltip-padding-x};
  --#{$prefix}tooltip-padding-y: #{$tooltip-padding-y};
  --#{$prefix}tooltip-margin: #{$tooltip-margin};
  @include rfs($tooltip-font-size, --#{$prefix}tooltip-font-size);
  --#{$prefix}tooltip-color: #{$tooltip-color};
  --#{$prefix}tooltip-bg: #{$tooltip-bg};
  --#{$prefix}tooltip-border-radius: #{$tooltip-border-radius};
  --#{$prefix}tooltip-opacity: #{$tooltip-opacity};
  --#{$prefix}tooltip-arrow-width: #{$tooltip-arrow-width};
  --#{$prefix}tooltip-arrow-height: #{$tooltip-arrow-height};
  

Sass a danglam thei

$tooltip-font-size:                 $font-size-sm;
$tooltip-max-width:                 200px;
$tooltip-color:                     $white;
$tooltip-bg:                        $black;
$tooltip-border-radius:             $border-radius;
$tooltip-opacity:                   .9;
$tooltip-padding-y:                 $spacer * .25;
$tooltip-padding-x:                 $spacer * .5;
$tooltip-margin:                    null; // TODO: remove this in v6

$tooltip-arrow-width:               .8rem;
$tooltip-arrow-height:              .4rem;
// fusv-disable
$tooltip-arrow-color:               null; // Deprecated in Bootstrap 5.2.0 for CSS variables
// fusv-enable

Hman dan tur

Tooltip plugin hian content leh markup on demand a siam a, default-in tooltip te chu an trigger element hnuaiah a dah thin.

JavaScript hmangin tooltip chu trigger la:

const exampleEl = document.getElementById('example')
const tooltip = new bootstrap.Tooltip(exampleEl, options)
Overflow autolehscroll

Tooltip position hian parent container- in kan , a neih overflow: autoemaw, a duh emaw hunah automatic-in a thlak tum a , mahse original placement-a positioning chu a la vawng reng tho. Chumi chinfel nan chuan option (option hmanga flip modifier tan) chu HTMLElement eng pawhah set la, default value override turin, , chu chu :overflow: scroll.table-responsiveboundarypopperConfig'clippingParents'document.body

const tooltip = new bootstrap.Tooltip('#example', {
  boundary: document.body // or document.querySelector('#boundary')
})

Markup a ni

Tooltip atana markup mamawh chu dataattribute chauh a ni a title, HTML element-ah chuan tooltip neih i duh a ni. Tooltip pakhata markup siam chhuah chu a awlsam deuh a, mahse position (by default-ah topchuan plugin-in a set) a ngai a ni.

Keyboard leh assistive technology hmangtute tana hmanraw tangkai tak siam

HTML elements hmanlai keyboard-focusable leh interactive (link emaw form control ang chi)-ah chauh tooltips i dah tur a ni. Attribute dah belh hian arbitrary HTML elements ( <span>s ang chi) chu focusable-a siam theih ni mah se tabindex="0", hei hian keyboard hmangtute tan non-interactive element-ah tab stop tibuaitu leh buaithlak thei a dah belh ang a, tunah hian assistive technology tam zawk chuan hetiang dinhmunah hian tooltip hi an puang lo. hoverTin, i tooltip atana trigger atan chauh rinchhan suh , hei hian keyboard hmangtute tan i tooltip te chu trigger theih a nih loh phah dawn a ni.

<!-- HTML to write -->
<a href="#" data-bs-toggle="tooltip" data-bs-title="Some tooltip text!">Hover over me</a>

<!-- Generated markup by the plugin -->
<div class="tooltip bs-tooltip-top" role="tooltip">
  <div class="tooltip-arrow"></div>
  <div class="tooltip-inner">
    Some tooltip text!
  </div>
</div>

Elements tihtawp a ni

Attribute nei element te disabledhi interactive an ni lo a, chu chu user te chuan tooltip (or popover) trigger turin an focus thei lo va, an hover thei lo va, an click thei lo tihna a ni. Workaround atan chuan tooltip chu wrapper atanga trigger <div>emaw <span>, ideally made keyboard-focusable using tabindex="0".

html tih a ni
<span class="d-inline-block" tabindex="0" data-bs-toggle="tooltip" data-bs-title="Disabled tooltip">
  <button class="btn btn-primary" type="button" disabled>Disabled button</button>
</span>

Thil thlan theih a ni

Options chu data attribute emaw JavaScript hmanga pass theih a nih avangin option hming chu data-bs-, ah hian i append thei ang data-bs-animation="{value}". Data attribute hmanga options pass dawnin option hming case type chu “ camelCase ” atanga “ kebab-case ” ah thlak ngei ngei tur a ni. Entirnan, data-bs-custom-class="beautifier"tih aiah hmang data-bs-customClass="beautifier"rawh.

Bootstrap 5.2.0 atang khan component zawng zawng hian experimental reserved data attribute an support data-bs-configa, chu chuan JSON string angin component configuration awlsam tak a dah thei a ni. Element pakhatin data-bs-config='{"delay":0, "title":123}'leh data-bs-title="456"attribute a neih chuan a tawp ber titlevalue chu a ni ang a 456, data attribute hrang hrangte chuan , a value pekte chu a override ang data-bs-config. Chu bakah, data attribute awmsa te hian JSON value te chu data-bs-delay='{"show":0,"hide":150}'.

Security avang hian sanitize, sanitizeFn, leh allowListoption te hi data attribute hmangin supply theih a ni lo tih hre reng ang che.
Hming Lampang Hlawhchhamna Hrilhfiahna
allowList thil Default value a ni Object ah chuan attribute leh tag phalsak te a awm.
animation boolean a ni true Tooltip ah CSS fade transition hmangin apply rawh.
boundary string, element tih a ni 'clippingParents' Tooltip-a overflow constraint boundary (Popper-a preventOverflow modifier-ah chauh hman tur a ni). Default-ah chuan 'clippingParents'HTMLElement reference a ni a, a pawm thei bawk (JavaScript hmang chauh). Hriat belh duh chuan Popper-a detectOverflow docs en rawh.
container string, element, dik lo tihna a ni false Tooltip chu element bik pakhatah a append thin. Entirnan: container: 'body'. He option hi a bik takin a tangkai hle a, document flow-ah tooltip chu triggering element bulah dah theih a ni - chu chuan window resize laiin tooltip chu triggering element atanga hla taka a float loh nan a veng ang.
customClass string, hnathawh dan '' Tooltip a rawn lan hunah class te dah belh rawh. Template-a class tarlan zawng zawng bakah heng class te hi dah belh a ni ang tih hre reng ang che. Class tam tak dah belh tur chuan space hmangin then rawh: 'class-1 class-2'. Class hming dang awmna string pakhata rawn pe chhuak tur function pawh i pass thei bawk.
delay number, thil awm 0 Tooltip (ms) entir leh thup hun sawn hlat—manual trigger type-ah chuan a hman theih loh. Number supply a nih chuan hide/show pahnih ah delay a awm vek a ni. Thil awm dan chu: delay: { "show": 500, "hide": 100 }.
fallbackPlacements array a ni ['top', 'right', 'bottom', 'left'] Fallback placement te chu array-a placement list (a duh dan angin) pein define rawh. Hriat belh duh chuan Popper-a behavior docs en rawh.
html boolean a ni false Tooltip ah HTML phalsak rawh. A dik a nih chuan tooltip's a HTML tags te chu tooltip titleah a render ang. False a nih chuan innerTextproperty hmangin DOM ah content dah a ni ang. XSS attack i ngaihtuah chuan text hmang rawh.
offset array, string, hnathawh dan te [0, 0] Tooltip chu a target nena khaikhin chuan offset a ni. Data attribute-ah string pakhat chu comma separated value hmangin i pass thei a, chu chu: data-bs-offset="10,20". Offset hriat nan function hman a nih chuan a argument hmasa ber atan popper placement, reference leh popper rects te awmna object hmangin koh a ni. Triggering element DOM node chu argument pahnihna atan pass a ni. Function hian number pahnih nei array a rawn pe chhuak tur a ni: skidding , distance . Hriat belh duh chuan Popper-a offset docs en rawh.
placement string, hnathawh dan 'top' Tooltip dah dan: auto, chunglam, hnuai lam, veilam, dinglam. A autotarlan hunah chuan tooltip chu dynamically in a reorient ang. Function pakhat chu placement hriat nan hman a nih chuan tooltip DOM node chu a argument hmasa ber atan leh triggering element DOM node chu a pahnihna atan hmangin koh a ni. Context chu thistooltip instance ah dah a ni.
popperConfig null, thil, hnathawh null Bootstrap-a Popper config default thlak tur chuan Popper-a configuration en rawh . Popper configuration siamna atana function hman a nih chuan Bootstrap-a default Popper configuration awmna object hmangin koh a ni. Default chu i configuration nen hman leh merge turin a pui che a ni. Function hian Popper tan configuration object a rawn pe chhuak tur a ni.
sanitize boolean a ni true Sanitization hi enable emaw disable emaw theih a ni. Activated a nih chuan 'template', 'content'leh 'title'options te chu sanitized a ni ang.
sanitizeFn null, hnathawh null Hetah hian mahni sanitize function i supply thei ang. Sanitization tih nan library bik hman i duh chuan hei hi a tangkai thei hle.
selector string, dik lo false Selector pek a nih chuan tooltip objects chu target tarlan te hnenah delegate a ni ang. jQuery.onPractice-ah chuan hei hi dynamically added DOM elements ( support)-a tooltips hmanna atan pawh hman a ni. He issue leh entîrna thu hriat theihna en rawh .
template hrui '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>' Tooltip siam huna hman tur HTML base rawh. Tooltip's titlechu a inject ang a, .tooltip-inner. .tooltip-arrowtooltip-a arrow a lo ni ta a ni. Wrapper element pawn lam ber chuan .tooltipclass leh role="tooltip".
title string, element, hnathawh dan te '' titleAttribute a awm loh chuan title value default a ni. Function pek a nih chuan a thisreference set chu popover attached element-ah dahin a ko ang.
trigger hrui 'hover focus' Tooltip tihchhuah dan: click, hover, focus, manual. Trigger tam tak i pass thei a; space hmangin then hran rawh. 'manual'tooltip chu programmatic-in .tooltip('show'), .tooltip('hide')leh .tooltip('toggle')methods hmangin a trigger dawn tih a tarlang a; he value hi trigger dang nen a inzawm thei lo. 'hover'a mah chauhin keyboard hmanga trigger theih loh tooltips a siam ang a, keyboard hmangtute tana information inang thehdarh dan dang a awm chauhvin hman tur a ni.

Tooltip hrang hrang atana data attribute te

Tooltip hrang hrang atana option hrang hrangte chu a dangin data attribute hmanga tarlan theih a ni a, a chunga kan sawi tawh ang khan.

Function hman dan nenpopperConfig

const tooltip = new bootstrap.Tooltip(element, {
  popperConfig(defaultBsPopperConfig) {
    // const newPopperConfig = {...}
    // use defaultBsPopperConfig if needed...
    // return newPopperConfig
  }
})

Thiltih dan tur

Asynchronous method leh inthlak danglamna te

API method zawng zawng hi asynchronous a ni a , transition a tan vek a ni . Transition an tan veleh mahse a tawp hmain call tu hnenah an kir leh thin . Chu bakah, transitioning component-a method call chu ngaihthah a ni ang .

Hriat belh duh chuan kan JavaScript documentation en rawh .

Tihdan Hrilhfiahna
disable Element pakhat tooltip a lan theihna tur a paih chhuak. Tooltip hi re-enable a nih chauhvin a lang thei ang.
dispose Element pakhat tooltip a thup a, a tichhia (DOM element-a data dahkhawmte a paih chhuak). Delegation hmanga siam Tooltips ( option hmanga siamselector ) te chu descendant trigger elements ah pakhat zel tihchhiat theih a ni lo.
enable Element pakhat tooltip chu a lantir theihna a pe. Tooltips hi default-in a enable a ni.
getInstance Static method hmangin DOM element nena inzawm tooltip instance chu i hmu thei a, a nih loh leh initialized a nih loh chuan a thar siam theih a ni bawk.
getOrCreateInstance Static method hmangin DOM element nena inzawm tooltip instance chu i hmu thei a, a nih loh leh initialized a nih loh chuan a thar siam theih a ni bawk.
hide Element pakhat tooltip a thup thin. Tooltip a thup tak tak hmain (chu chu hidden.bs.tooltipevent a thlen hmain) caller hnenah a kir leh thin. Hei hi tooltip “manual” triggering anga ngaih a ni.
setContent Tooltip a initialization hnua a content thlak dan tur a pe.
show Element pakhat tooltip a pholang. Tooltip a lan tak tak hmain (chu chu shown.bs.tooltipevent a thlen hmain) caller hnenah a kir leh thin. Hei hi tooltip “manual” triggering anga ngaih a ni. Zero-length title nei tootip te hi a lang ngai lo.
toggle Element pakhat tooltip a toggle thin. Tooltip a lan tak tak emaw a thup hma emaw (chu chu shown.bs.tooltipor hidden.bs.tooltipevent a thlen hma) caller hnenah a kir leh thin. Hei hi tooltip “manual” triggering anga ngaih a ni.
toggleEnabled Element pakhat tooltip tarlan emaw thup emaw theihna tur a toggle thin.
update Element pakhat tooltip awmna hmun a update thin.
const tooltip = bootstrap.Tooltip.getInstance('#example') // Returns a Bootstrap tooltip instance

// setContent example
tooltip.setContent({ '.tooltip-inner': 'another title' })
setContentMethod chuan argument a pawm a object, chutah chuan property-key tin chu popover template chhunga selector dik tak a ni a string, a kaihhnawih property-value tinte chu string| element| function| null

Thil thlengte

Hunbik Hrilhfiahna
hide.bs.tooltip hideHe event hi instance method koh a nih chuan a fire nghal a ni.
hidden.bs.tooltip He event hi popover chu user hnen atanga thup a nih zawh chuan fired a ni (CSS transitions zawh hun a nghak ang).
inserted.bs.tooltip show.bs.tooltipHe event hi DOM-a tooltip template dah a nih hunah event zawhah fire a ni.
show.bs.tooltip showHe event hi instance method kan koh chuan a fire nghal vek a ni.
shown.bs.tooltip He event hi popover chu user hmuh theiha siam a nih hunah fire a ni (CSS transitions zawh hun a nghak ang).
const myTooltipEl = document.getElementById('myTooltip')
const tooltip = bootstrap.Tooltip.getOrCreateInstance(myTooltipEl)

myTooltipEl.addEventListener('hidden.bs.tooltip', () => {
  // do something...
})

tooltip.hide()