Tips for customizing the CSS of the Bootstrap 4.5 tooltip

Using bootstrap 4.5.3, I have created a tooltip and now I want to customize its appearance by adding my own styles:

.tooltip {
    display: flex;
    justify-content: flex-start;
    position: absolute;
    z-index: 9999;
    background: #ddff9d;
    color: #333333;
    width: 320px;
    
    -webkit-box-shadow: 5px 5px 5px 5px white;
    box-shadow: 2px 2px 2px 2px white;
    -moz-border-radius: 8px;
    border-radius: 8px;
    -webkit-border-radius: 8px;
    opacity: 1 !important;

    padding: 10px;
    text-align: left;
}

.tooltip-inner {
    background-color: #00acd6 !important;
    /*!important is not necessary if you place custom.css at the end of your css calls. For the purpose of this demo, it seems to be required in SO snippet*/
    color: #fff;
}

.tooltip.top .tooltip-arrow {
    border-top-color: #00acd6;
}

.tooltip.right .tooltip-arrow {
    border-right-color: #00acd6;
}

.tooltip.bottom .tooltip-arrow {
    border-bottom-color: #00acd6;
}

.tooltip.left .tooltip-arrow {
    border-left-color: #00acd6;
}

Currently, the tooltip looks like this:

But I want to achieve the following modifications:

  1. Change the width of the internal (blue) block to fill the width + paddings
  2. Set equal paddings for the internal block as well as the external block
  3. Align the text inside the internal block to the left

UPDATED BLOCK: This is actually a fullcalendar 3.9 component and the tooltip is rendered dynamically with JavaScript code:

 eventRender: function (eventInfo, element, view) {
  let adHtml = '<b>' + eventInfo.title + "</b><br> " +
        '<u>{!! showAppIcon('expire_date') !!} Expired at : ' + eventInfo.start_formatted + '</u><br>'+
        '{!! showAppIcon('location') !!}&nbsp;' + eventInfo.adLocationsCount + '&nbsp;location(s)<br>' +
        '<small>Status : ' + eventInfo.status_label + "</small><br>" +
        '<small>' + eventInfo.description + "</small>"

    let tooltipOptions = {
        title: adHtml,
        html: true
    }

   element.tooltip(tooltipOptions)

I am using the solar theme from bootswatch template. I am facing issues debugging elements in the browser's inspector as the tooltip gets hidden when the mouse hovers over it...

Thank you!

Answer №1

If you want to adjust the width, simply add max-width: 400px;. For left-aligning text, use text-align: left;

Here's a snippet of CSS that you can replace your current styles with:

.tooltip-inner {
  text-align: left;
  max-width: 400px;
  border-radius: 8px;
  padding: 20px;
}

You can view this code on Codepen here: https://codepen.io/manaskhandelwal1/pen/LYRXzro

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

Strategies for Text and Content Alignment in Angular Using CSS

Trying to format the text in my expand/collapse question bar using angular. Below is a snippet of HTML/Angular code amongst many others. <mat-expansion-panel hideToggle> <mat-expansion-panel-header> <mat-panel-title> User Data ...

Ways to eliminate a css class with jquery based on a specific screen dimension

There is a div element that includes a specific class. My goal is to remove this class when the window is resized to fit a mobile view-port. <div class="box"></div> ...

What is the reason behind a stationary lightbox sticking to the top of the webpage rather than the top of the viewport?

When you visit this page and scroll down a little before clicking on one of the art pieces, have you noticed that the "fixed" lightbox seems to be attaching itself to the top of the page instead of the viewport? I'm looking for ways to make it attach ...

The art of expertly placing the arrow in <details> with CSS

I'm looking to adjust the placement of the arrow within details. I've experimented with using float:left, but when the line is too long, like in the example provided, the arrow shifts to the beginning of the line below when I resize the window. I ...

I'm looking to add a next and previous button within my jumbotron- can anyone offer guidance?

As I near the completion of my Full Stack Nanodegree final project and await assistance from my instructor, I've taken on the task of developing my portfolio. However, I'm facing a challenge with implementing next and previous buttons within my j ...

The anchors seem to be malfunctioning, causing the page to remain stagnant

After spending countless hours on this issue, I am still unable to solve it. The problem seems simple enough - a few modifications were made to the site and now the anchors do not work properly unless the page is refreshed. Visit www.boldcreative.co.nz fo ...

Fuzzy division following a CSS transformation/animation

I have been working on a content slider, using the guidelines from this demonstration However, I have encountered an issue where my content, which consists of a few divs, appears slightly blurry after the CSS transition completes. This problem only seems ...

Can Font Awesome icons be resized beyond 'fa-5x'?

I recently implemented the following HTML code snippet: <div class="col-lg-4"> <div class="panel"> <div class="panel-heading"> <div class="row"> <div class="col-xs-3"> <i class="fa fa-cogs fa- ...

Apply the "active" class to the list item when its corresponding section is in view

I have a webpage with at least four sections. My goal is to dynamically apply the active class to the corresponding menu item when scrolling through each section. For instance, if the "About Us" section is visible on the screen, I want to mark the correspo ...

Centering items within grid columns for optimal alignment

I have successfully designed a contact form using a CSS grid layout that features 4 input fields and a submit button spanning across 2 columns. Two of the input fields take up 1fr of space each, while the remaining two are 1/3 wide. My challenge lies in c ...

css issue with styling on a and a:hover elements

I'm having trouble getting the CSS for 'a' and 'a:hover' to work properly. The background of the li elements isn't changing to blue when I hover over them. Can anyone provide some assistance? Your help would be greatly appreci ...

"The use of an angular variable to create dynamic HTML content

Looking to build a blog page using AngularJS and running into an issue with the message section. Currently, I have a div set up like this: <div class="post-content"> {{jsonPost.message}} </div> Within the jsonPost.message variable, I have ...

Class-dependent variable values

I'm trying to figure out how to change a SCSS variable based on a class. Specifically, I want the variable to be green when in the 'dark-mode' class. Css: $test: red; @mixin darkTheme { $test: green; } .theme-dark { @include darkThem ...

css side by side with immovable element

Seeking assistance with CSS. I am looking to create a layout as follows: I want a center-fixed menu with a width of 960px - this part is straightforward. Alongside the menu, I aim to have two divs: one spanning from the left edge of the screen to the cl ...

Sending a different name for the jQuery parameter

I'm looking to select CSS settings based on the presence of a data tag. What would be the correct approach for this? var datadirection = 'left'; //default direction if( $(this).attr('data-right') ){ datadirection = 'righ ...

Tabindex issue arises due to a conflict between Alertify and Bootstrap 4 modal

When trying to call an Alertify Confirmation dialog within a running Bootstrap 4 Modal, I encountered an issue with the tab focus. It seems to be stuck in the last element and not working as expected. I suspect that this might have something to do with th ...

Achieving Center Alignment for Material-UI's <Table> within a <div> using ReactJS

Currently, I am working with a Material-UI's <Table> embedded within a <div>. My goal is to center the <Table> while maintaining a fixed width. I want the table to remain centered in the browser, but if the browser window is minimize ...

In React JS, position the image at the top of the page, spanning the full width of the window

I've been trying to place a gif file at the top of the screen, but so far I haven't been successful. Currently, the gif file is taking up the entire page: <div style={{ backgroundImage: 'url(https://media.tenor.com/kKmvIr30vQYAAAAj/stars- ...

Label stops functioning properly when there is a line-height exceeding 1

The problem arises when the line-height of a paragraph is set to more than 1em and the label tag doesn't work properly between lines. <p style="line-height: 2em;"><input type="checkbox" id="xx" /> <label for="xx">Lorem ipsum dolor ...

Troubleshooting problems with CSS menus and submenus, along with addressing browser pixel issues specific to Web

Find my custom css menu here: Custom CSS Menu On hovering over "about us", the "our clergy" sub-menu appears automatically. I need it to show only when hovering over "our clergy". This screenshot is from Firefox, but webkit browsers like Chrome show a sl ...