Expanding CSS tooltip size based on content

This is the CSS code for a tooltip:


    a.tooltips {
      position: relative;
      display: inline;
    }
    a.tooltips span {
      position: absolute;
      width:140px;
      color: #FFFFFF;
      background: #000000;
      height: 30px;
      line-height: 30px;
      text-align: center;
      visibility: hidden;
      border-radius: 6px;
    }
    a.tooltips span:after {
      content: '';
      position: absolute;
      top: 100%;
      left: 50%;
      margin-left: -8px;
      width: 0; height: 0;
      border-top: 8px solid #000000;
      border-right: 8px solid transparent;
      border-left: 8px solid transparent;
    }
    a:hover.tooltips span {
      visibility: visible;
      opacity: 0.8;
      bottom: 30px;
      left: 50%;
      margin-left: -76px;
      z-index: 999;
    }

I am looking for a way to make the tooltip automatically resize based on the length of the text. Can anyone help? Thank you.

Answer №1

Remove the width:140px; attribute from the a.tooltips span class.

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

What is the best way to limit a table overflow to stay within its row boundary?

Is it possible to truncate a table within a div in such a way that the overflow occurs on a row boundary? The table can have arbitrary rows and sometimes expands to accommodate more than one line of text. The div itself has a fixed height with overflow:hid ...

The way in which LI elements are dynamically displayed

Check out this Fiddle! I have a fiddle set up where li items are vertically aligned and floated to the right. The issue I'm facing is with the order of the items - currently, they appear as test3, test2, and then test1. However, I want them to displ ...

Troubleshooting issues with Bootstrap 4 navbar dropdown functionality

I recently added a test page, but when clicking on the links, they do not direct you to the album page as intended. Instead, the page blinks and jumps quickly. To see this issue in action, visit the live test page through this link. <!DOCTYPE html>&l ...

Is there a CSS4 resolution for transitioning from 0 to auto?

I searched extensively for information on CSS4, but unfortunately I came up empty-handed. Back in the era of CSS3, a common challenge arose when it came to height transitions from 0 to auto without relying on JavaScript. The introduction of transitions sa ...

Trouble linking CSS file with Plotly Dash interface

Transitioning from plotly to dash, I am looking to incorporate a css file to enhance the appearance of my dashboard. The structure consists of app.py and index.py in the main directory, with an additional style.css file located in the /assets folder. Desp ...

Can you explain the concept of image sprites and how they should be utilized?

When implementing image sprites in css, what approach do you typically take? Is it advisable to consolidate all the images on my website into a single image sprite? Are there significant benefits to doing so? How challenging is it to manage and update th ...

When using Webdriver to upload a file, the sendKeys() method does not trigger any action

I'm currently working on automating the file upload process using Selenium Webdriver. After researching numerous questions on stackoverflow and implementing the suggestions provided, I was able to successfully execute the code on a test page: Howeve ...

Leveraging HTML5's local storage functionality to save and manage a collection of list elements within `<ul>`

I need help with saving a to-do list in HTML so that it persists even after refreshing the browser. Can anyone assist me? html <!DOCTYPE html> <html> <head> <title>My To-Do List</title> <link rel="sty ...

Obtaining the identifier of the grandparent element that is of the "

I'm working on a project where I have a dynamic element called .courseBox. It's an <li> element that will be placed within a <ul> container. Each .courseBox has a red "x" button that, when clicked, removes it from the <ul>. Here ...

Determine total using PHP object

Can anyone assist me with adjusting this code? $aBlockVideos = (array) Advancedvideo_Service_Video::instance()->query("","v.total_comment DESC",1,5); I'm trying to figure out how to display the total number of comments for the current week. Any s ...

Limit the cell dimensions to a specific width and height

I initially set fixed widths and heights for the cells, but we decided to move away from that approach. Now I want the cells to be able to shrink and expand freely, but I also want them to stop resizing once they reach a certain width. <table align ...

After submitting in Moodle, the form fails to validate

I have been working on a form that adapts its structure based on the parameter in the URL. If no parameter is provided in the URL, an error message should be shown. Depending on the ID, a database query is executed, and the form is populated with data. Fo ...

Ways to display text when hovering over an image link

Despite trying various techniques recommended by fellow Stackoverflow users who faced similar issues, I still encountered a problem where the text appeared below the image even after applying the suggested methods to my code. I also experimented with a me ...

Leveraging ruby variables to generate dynamic HTML content

I am encountering an issue where the content in u.one_line, which is text from a database, sometimes contains formatted HTML with line breaks. For example: u.one_line is "This is < / b r > awesome" The desired behavior is for the webpage to process ...

Obtaining user Object data from an HTML form in Spring Boot Controller

Having trouble retrieving data from an HTML form in my controller method while trying to create a straightforward Web application for user registration. I've attempted various solutions without success. Main class: /* Main class code here */ Con ...

Unable to achieve CSS transition effect with height: 0, works fine with other values

I have been trying to implement a transition effect for when the header goes hidden, but it seems to disappear immediately. I've included the code below for reference: function getScrollTop() { return window.pageYOffset || document.documentElem ...

Is it possible to add a border to both the tbody and td

I currently have a table that is organized with tbody elements to group rows together. In order to create a grid-like structure, I applied borders to each individual td element within the tbody. However, I also desire to show that the tbodies themselves ar ...

What steps can I take to ensure that the div doesn't overlap with the scrollbar while still maintaining the functionality of my JQuery ScrollTo plug-in?

Currently troubleshooting an issue with a website I'm constructing. Utilizing the jQuery plug-in "scroll to" for a single-page layout with multiple sections, I am aiming to keep the navigation bar fixed at the top of the page while allowing users to s ...

Organize data in a Vue.js table

Currently facing an issue with sorting my table in vue.js. Looking to organize the table so that campaigns with the highest spend are displayed at the top in descending order. Here is the code I'm working with: <template> <div class=" ...

Getting the values of an HTML <select> element on the server side with expressJS: How to do it?

I came up with this custom drop-down filtering box using HTML: <select name="animals" id="animal-select"> <option value="">--Please select an animal--</option> <option value="lion">Lion</option> <option value=" ...