The Maximum Width Property of CSS Tooltips is Not Being Applied

I'm working on a tooltip feature and facing an issue where the content does not expand as intended based on the CSS rules. Here's the snippet of my CSS code:

.parent {
  display: inline-flex;
  position: relative;
  font-weight: 900;
}

.parent:hover .child {
  display: block;
}

.child {
  display: none;
  position: absolute;
  bottom: 10px;
  font-weight: normal;
  background-color: black;
  color: white;
  height: 20px;
  max-width: 400px;
  width: auto;
  overflow: auto;
  padding: 10px;
}

Despite setting max-width to 400px, the tooltip's content is not expanding beyond the width of its parent element (bwre-tooltip).

I've tried adjusting the 'width' property and explored other options like 'max-content', but haven't found a satisfactory solution yet. I've also double-checked for any conflicting CSS rules that could be affecting the tooltip's width.

Is there a specific CSS technique or property I should be using to ensure the tooltip's content grows until its max-width is reached, regardless of the parent element's width?

If you have any insights, suggestions, or alternative methods to achieve this behavior, I would greatly appreciate your input. Thank you in advance for your help!

Additional Information:

Here's how the HTML structure looks:

<section>
      ipsum ...
      <div class="parent">
        <span class="child">
          sed diam nonumy eirmod tempor invidunt ut labore et dolore magna
          aliquyam
        </span>
        hello world
      </div>
      ...
    </section>

You can also access the sandbox link here.

Answer №1

After experimenting with different styles, I discovered that adding margin: 0 -100%; to the child element produced the desired effect.

However, upon further review, @wing's solution appears to be more optimal.

Answer №2

From my understanding, implementing box-sizing: border-box; in your tooltip is essential.

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

Hiding Certain Words on a Website

Is there a way to hide specific text strings on a website? For instance, suppose I want the string "hxxp://nullrefer.com/?" to be invisible whenever it appears on my page. If a URL like "hxxp://nullrefer.com/?hxxp://www.Amazon.com" is mentioned, I only w ...

Having trouble removing or adding a class to an HTML element?

I have a collection of three colored buttons. My goal is to allow users to select one button at a time, triggering it to be highlighted while the others are unselected. Each button corresponds to an object with a property called isSelected that can be set ...

Error in Angular 8: Property 'name' is undefined and cannot be read

Delving into the world of Angular, I encountered an interesting error: ERROR TypeError: Cannot read property 'name' of undefined. Here's the snippet of code: recipe-list.component.ts import { Component, OnInit } from '@angular/core&ap ...

Issues with external stylesheet functionality (effective internally)

When coding with internal CSS, everything appears as expected. However, after moving the CSS to an external file, certain properties seem to stop working. To view the code with the external CSS and identify the issues, check out the following link: https ...

Is there a way to prevent the text box from expanding beyond the small breakpoint?

Help! I'm trying to control the size of a Bootstrap 4 input text box. I need it to stop growing after the small breakpoint, so it doesn't expand to the full width of the screen. ...

Tips for integrating external JavaScript libraries and stylesheets into a widget

I am currently working on developing a custom Javascript widget that requires users to insert specific lines of code into their web pages. This code will then dynamically add an externally hosted javascript file, allowing me to inject HTML content onto the ...

The margin-left negative is not functioning when setting the left side at 50%

I'm having trouble getting this specific CSS to work on an element: .element { position: absolute; left: 50%; margin-left: -285px // the element has width: 500px; } This element is contained within another div that also has an absolute positio ...

Tips on how to prevent certain classes from being impacted by a hue-rotate filter applied to all elements on a webpage

I am currently in the process of adding a feature that allows users to choose between a dark or light theme, as well as select a specific theme color for the app. The implementation involves using CSS filters such as invert(1) for the dark theme and hue-ro ...

Image floating gracefully in the top corner of the screen

Check out this Picture I am trying to create a floating image similar to the one in the top left corner of the navigation bar. After searching for some code to achieve this, I came across the following: <html> <head></head> <bod ...

How can I display a popup window within an iframe on a separate full page?

I am facing an issue while creating an HTML table using AngularJS with a popup. The problem is that I want the popup window, which shows a graph, to open up on the entire page instead of in a specific div. My desired output should look like this: https://i ...

JavaScript strangeness

I am currently working on a dynamic page loaded with ajax. Here is the code that the ' $.get' jQuery function calls (located in an external HTML page): <script type="text/javascript"> $(function() { $('button').sb_animateBut ...

Issue encountered while attempting to compress tailwindcss

I attempted to reduce the size of my tailwindCSS by creating a script in my package.json: "tw:prod":"NODE_ENV=production npx tailwindcss-cli@latest build ./src/css/tailwind.css -o ./public/css/tailwind.css", However, I encountered the ...

Tips on how to dynamically allocate an id value to a jQuery function that retrieves the backgroundImage URL

I have a div with a background image and I am using a jQuery function to retrieve the URL of the background image. var name=image; var url=$("#"+name+"").css("background-image"); console.log(url); <script src="https://cdnjs.cloudflare.com/aj ...

Can anyone provide guidance on utilizing libraries within a Chrome extension?

I have been attempting to implement this for a total of 10 hours and I am struggling to make it work in script.js. // Creating a button element const button = document.createElement('button'); button.textContent = 'copy'; button.addEve ...

Navigational Arrows within a JQuery Image Carousel

I've successfully developed an image slider using a combination of HTML, CSS, and JS (Jquery). The slider consists of 5 images that users can navigate between using arrow buttons. Everything is functioning correctly so far, but I'm encountering a ...

Show the image on top of the div block as the AJAX content loads

Implementing this task may seem easy and common, but I am struggling to figure it out! What should take five minutes has turned into an hour of frustration. Please lend me your expertise in getting this done. I have a div container block: <div cla ...

How can we stop mobile email applications from automatically converting emails into a "mobile-friendly" layout without permission?

My email design is optimized to look great on mobile, web, and desktop mail clients. However, I'm facing a challenge with some mobile clients like Gmail on Android automatically reformatting the email to make it more mobile-friendly. This leads to a m ...

Managing Custom CSS Files in Sencha Touch 2 Production Build

Currently, I am in the process of working on a mobile website using Sencha Touch 2. To develop the production build, I utilized Sencha Cmd v3. Upon testing the production version, I noticed that although my custom CSS files are present in the folder struct ...

Load the div iframe when it is clicked

I'm looking for a way to optimize the loading of div elements on my website. Currently, when the page is loaded, all divs are also loaded but remain hidden until clicked. Is there a method to delay loading the content of a specific div until it's ...

When I forget to use var_dump, PHP fails to load scripts

When I am building CSS links using a function, the CSS doesn't work unless I add a var_dump at the end. What could I be missing or overlooking? Here is the code snippet: private function buildCssLinks(){ $files = $this->findFiles(dirname(d ...