Is it possible to include a Bootstrap tooltip within a table header?

The default bootstrap tooltip in my table header is displaying unexpected behavior, such as increasing the width of the header.

Here is the link to view the code on Codepen:

https://codepen.io/tumulalmamun/pen/mpQzBV

$(document).ready(function(){
    $('[data-toggle="tooltip"]').tooltip();   
});
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h3>Tooltip Example</h3>
  <p>The data-placement attribute specifies the tooltip position.</p>
      <div class="row">
      <div class="col-lg-3">
            <table class="table table-bordered table-hover table-striped">
                <thead>
                    <tr><th colspan="2"> status (Overall)</th></tr>
                    <tr>
                        <th colspan="2" data-toggle="tooltip" data-placement="right" title="Hooray!">
                            Pending 

                        </th>

                    </tr>
                    <tr>
                        <th data-toggle="tooltip" data-placement="right" title="Hooray!">M</th>
                        <th data-toggle="tooltip" data-placement="right" title="Hooray!">O</th>
                    </tr>  
                </thead>
</table>
        
      </div>     
     
 <div class="col-lg-3"></div>
      <div class="col-lg-3"></div>

    </div>
</div>

</body>
</html>

Answer №1

To solve this issue, make sure to include the tool-tip within an element inside th/td rather than directly on it. (Wrap the text from the example in divs)

<table class="table table-bordered table-hover table-striped">
    <thead>
        <tr>
            <th colspan="5">Pre-Recruitment status (Overall)</th>
        </tr>
        <tr>
            <th rowspan="2" colspan="2">Status </th>
            <th rowspan="2">Candidate</th>
            <th colspan="2">
                <div data-toggle="tooltip" data-placement="right" title="Hooray!">Panding Doc.</div>
            </th>
        </tr>
        <tr>
            <th>
               <div data-toggle="tooltip" data-placement="right" title="Hooray!">M</div>
            </th>
            <th>
                <div data-toggle="tooltip" data-placement="right" title="Hooray!">O</div>
            </th>
        </tr>  
    </thead>
</table> 

When a tool-tip is triggered, it inserts a new div into the markup right after the element with the data-toggle="tooltip" attribute (Check using dev tools). Placing it outside a table element would disrupt the layout as the tool-tip appears after the table. Keeping it within the table element prevents layout issues.

I have made changes to your codepen which you can view here.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I am trying to incorporate the tailwind styling of "active:border-b-2 active:border-blue-500" into my next.js project, but unfortunately, it doesn't seem to be

This is the custom Tailwind CSS styling I would like to apply: import React from 'react' function HeaderIcon({Icon}) { return ( <div className="flex items-center cursor-pointer md:px-10 sm:h-14 m ...

Parsing HTML code using PHP's DOM parser for iteration

<div class="reviews-summary__stats"> <div class="reviews-summary"> <p class="reviews-title">A</p> <ul class="rating"> <li class="rating__item r ...

Targeting and sharing selected block quotes from social media posts

Within my Wordpress site's index.php file, there is a div that displays the post title, category, and featured image. Code snippet from index.php: <div> <h1><?php the_title(); ?></h1> <h3><?php the_category(& ...

How can the top height of a jquery dialog be reduced?

Just starting out with jquery, I've got a dialog box and I'm looking to decrease the height of this red image: https://i.sstatic.net/BuyQL.png Is there a way to do it? I've already made changes in the jquery-ui.css code, like so: .ui-dia ...

Encountering a problem while attempting to loop through div content upwards in jQuery, specifically when displaying the latest news

Hey there, I'm fairly new to JQuery and I am working on dynamically appending content to a div. I need to continuously scroll the content of that div to the top. After some research, I found a solution that meets my requirements. Here's a snippe ...

My jQuery code seems to be in order, so why isn't it working as expected?

I've been attempting to create basic jQuery play/pause buttons for an HTML5 video, but when I click on them, nothing seems to happen. If you have any code that could help with the play/pause functionality, I would greatly appreciate it. Here is the c ...

designing various containers and adjusting their divisions

I have a pop-up window that contains the code snippet below, defining a template within a "container": <form method="post" class="signin" action="#"> <div id='container'> <div> <div id="divFeeTitle"&g ...

Tips for automatically selecting the state from a dropdown list when utilizing address autofill

I created an HTML form and noticed that Chrome's autofill feature successfully fills in the street address, city, and zip code. However, when I use a select/option dropdown list for the state input, it does not get auto-filled. I have tried using sta ...

Sliced Text Transformation

Recently, I inquired about a pesky text effect that was bothering me. Thanks to the assistance of fellow users, I discovered that the culprit behind the effect was the background color's edge. Eliminating this problem should be simple, but even with ...

Creating a sleek hover effect with a bottom border on your Bootstrap navbar

Having trouble implementing a hover effect with a bottom border in the Bootstrap navbar, similar to this: https://i.sstatic.net/sbqt4.png However, my current result looks like this: https://i.sstatic.net/JXghl.png I want to adjust the bottom border to ...

Editing the header section of the stylesheet file

I need help with my Wordpress website. I want to remove the top black bar, but I'm worried it will affect other elements coded within it. Is there a safe way to remove the top bar without disrupting the rest of the components? The website in question ...

unable to display images from a folder using v-for in Vue.js

Just getting started with Vuejs and I have two pictures stored on my website. The v-for loop is correctly populating the information inside databaseListItem. The path is /opt/lampp/htdocs/products_db/stored_images/cms.png https://i.stack.imgur.com/969U7.p ...

The Angular (keyup) event is failing to detect the # symbol exclusively

When trying to incorporate a search bar using the Angular (keyup) event, I encountered file names like: base @, base $, base 1, base #, base 2, Searching for "base @" or "base $" or "base 1" in the search bar works fine. However, when searching for "bas ...

Tips for utilizing window.scrollTo in order to scroll inside an element:

I'm experiencing an issue where I have a vertical scrollbar for the entire page, and within that, there's an element (let's call it 'content') with a max-height and overflow-y scroll. The 'content' element contains child ...

How to apply a class on button click using react.js

After spending a few weeks diving into React, I've got the hang of the basic syntax like props and states. However, I'm hitting a roadblock when it comes to connecting certain concepts, especially adding classes when a state changes. My current p ...

Show off a font-awesome icon overlapping another image

My task involves fetching image source from a JSON file and then displaying it on an HTML page. https://i.sstatic.net/coOaU.png I also need to overlay a Font Awesome icon on top of the image as shown below: https://i.sstatic.net/nbrLk.png https://i.sst ...

Achieving a consistent appearance for file input controls with HTML and CSS

I'm currently working on customizing the appearance of the browse file control, aiming to replace it with a simple "add files" button. Here is the markup I have added so far. It seems to be functioning correctly, but I am facing an issue where the div ...

Is it necessary to include html, head, and body tags in pages loaded via AJAX requests?

I'm in the process of developing a web page that uses AJAX to load content within tabs. The content for each tab is stored in separate HTML files. My question is, do these individual HTML files loaded via AJAX need to contain the full <html>< ...

Ensure that two div elements expand to occupy the available vertical space

I am looking to create a layout similar to the following: |---| |------------| | | | b | | a | |____________| | | |------------| |___| |______c_____| Here is the code I have so far: <table> <tr> <td class="leftSid ...

Styling the CSS to give each grid element a unique height

I am working on a grid layout with three columns where the height adjusts to accommodate all text content. .main .contentWrapper { height:60%; margin-top:5%; display:grid; grid-template-columns:1fr 1fr 1fr; grid-gap:10px; /*grid-te ...