What is the best method for passing HTML code (complete with tags) through 'data-title' to CSS content using attr(data-title)? Alternatively, is there another approach that can be used for

I successfully implemented hover tooltips in my HTML code using the following method:

HTML (Django templates):

          <div class="hint-quest-mark">
             &nbsp;?<span class="hint-title" data-title="{{ class_.explanation }}"></span>
          </div>

The class_.explanation variable contains a string with line breaks represented by '\n'. However, when rendered in the browser, it displays as follows:

      <div class="hint-quest-mark">
         &nbsp;?<span class="hint-title" data-title="string 1 string2 string3"></span>
      </div>

without the actual line breaks.

To address this issue, I tried using the Django filter linebreaksbr to replace '\n' with the <br> tag. However, the CSS content property attr(data-title) cannot interpret HTML tags and simply displays "string 1<br>string2<br>string3".

CSS:

.hint-title {
        display: inline;
        position: relative;
}
.hint-quest-mark:hover > .hint-title::after {
        display: block;
        content: attr(data-title);
        position: absolute;
        top: -24px;
        left: 27px;
        z-index: 1;

}
.hint-quest-mark:hover > .hint-title::before {
        display: block;
        position: absolute;
        background: url("pict/hint_left_oblique.png") no-repeat;
        content: "";
        left: 12px;
        top: -12px;
        z-index: 2;
}

My question is: How can I include HTML tags in the CSS content, or explore other solutions to create custom hover tooltips with HTML-tagged content?

Answer №1

Choosing to not use one-sigarette decision

data-title -> content: attr(data-title)
method.

It is preferable to incorporate tiptool <div> directly into the HTML code without using ::before/::after, and toggling it on/off with Jquery when hovered over.

    <div class="hint-quest-mark" 
             onmouseover="$(this).children('.hint-title-hover').css('display', 'block');
                          $(this).children('.hint-title-pin').css('display', 'block');"
                                                    
             onmouseleave="$(this).children('.hint-title-hover').css('display', 'none');
                           $(this).children('.hint-title-pin').css('display', 'none');">
    
                         &nbsp;?
                          <div class="hint-title-pin"></div>
                          <div class="hint-title-hover">
                           <span>{{ class_.explanation|linebreaksbr }}</span>
                          </div>
   </div>

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

Error encountered: iPad3 running on iOS7 has exceeded the localStorage quota, leading to a

Experiencing a puzzling issue that even Google can't seem to solve. I keep getting the QuotaExceededError: DOM Exception 22 on my iPad3 running iOS7.0.4 with Safari 9537.53 (version 7, WebKit 537.51.1). Despite turning off private browsing and trying ...

Converting an NPM package into a gulp workflow

I'm currently generating html files from Nunjucks using my gulp file. Now, I need to convert these html files into text files. I came across a useful NPM package called html-to-text that can help with this task. However, I'm facing some challenge ...

Adding rows dynamically to multiple tables on a single page using a single function

I am facing a situation where I have multiple tables and a function that adds rows to these tables: <table id="table1" style=" border-collapse: collapse;"> <tr id="table1row1">... <tr id="table1row2">... <table id="table2" style=" bor ...

Error: jQuery is unable to access the property 'xxx' because it is undefined

While attempting to make a post request from the site to the server with user input data, I encountered an error message saying TypeError: Cannot read property 'vehicle' of undefined as the response. Here is the HTML and script data: <!DOCTY ...

The width of the Bootstrap row decreases with each subsequent row

I'm having trouble understanding this issue, as it seems like every time I try to align my rows in bootstrap, they keep getting smaller. Can anyone point out what mistake I might be making? ...

What steps can I take to maintain the horizontal scroll position of a div even after adding new elements to it?

I'm struggling to achieve an infinite x-scroll using HTMX. The issue I'm facing is that the request keeps getting triggered endlessly because the element that triggers it gets inserted on the left side of the div, causing a new request to load it ...

Position the center button evenly between two images, aligned vertically using percentages

I'm attempting to achieve a specific layout that includes images scaling across Bootstrap breakpoints and a static button position. The challenge is maintaining the layout as depicted in the mockup, regardless of image size. The images are set to im ...

What could be the reason for bootstrap failing to recognize and apply my variables?

Whenever I set the text color to green using this code: @textColor: green; It works perfectly and changes the text color, but when I try to modify grid column width and gutter width with this code: @gridColumnWidth: 10px; @gridGutterWidth: 0px; @flu ...

Incantation within ng-include | src involving a series of characters

Is there a way to create a URL in ng-include|src by combining an expression and a constant string? I've attempted the code below, but it doesn't seem to be working. <aside ng-include src="{{staticPath}} + 'assets/tpl/products-feed-histor ...

Angular <select><option> tags are missing from the browser display, although they are present in the source HTML code

After incorporating a dropdown list into the FormGroup, it seems to be missing from the browser display. Upon inspecting the page's HTML source on Chrome, I noticed that the <select><option></option></select> element is present ...

Problem with pairing table rows and cells, slight misalignment of 1 pixel

In my attempt to align an icon and text side by side, with the icon on the left and the text on the right, I encountered an issue where the element's box seems to be consistently 1 pixel off. This misalignment is causing the text to not line up proper ...

Increasing the height of a child div by 100% relative to its parent div using

In my latest project, I am incorporating Bootstrap cards and need to ensure compatibility with Chromium 57.xx for company-related reasons. However, I have encountered a problem that needs addressing. I applied height: 100% to the cards, which resulted in ...

Display the specified div element automatically

Despite my best efforts, I can't seem to figure this out. I've searched everywhere for a solution but no luck so far. Is there a way to automatically display the content from http://tympanus.net/Tutorials/CSS3ContentNavigator/index.html#slide-mai ...

What is the process for spinning a span in the center of an image?

My canvas displays an image: https://i.sstatic.net/p3MV4.png There is a white square with a refresh icon on the right side of the image, slightly hidden by a black circle. I implemented it like this: var rotatorSpan = document.createElement("span"); rot ...

Enhance your website with Bootstrap 4 by separating text and images in your carousel

I've been struggling to create a slider similar to the one shown in the image. I attempted using the Bootstrap carousel, but ran into issues with inconsistent image sizes and the text on the left side jumping around before settling in its correct posi ...

What is the best way to get a table header with collapsed borders and tbody cells with spacing between them?

Example I am currently in the process of creating a table design for a web project, inspired by the example above. Here is my attempt: .table_RMA table{ width: 100%; border-collapse: separate; border-spacing: .5rem; } .table_RMA table thead{ color:white ...

When clicking on a different tab, the Bootstrap tab will shift to the left, outlining the new selection

While working with Bootstrap, I created a small footer with a tab. However, whenever I click on the second value, the entire div shifts to the left. How can I keep it in place? Below is my code along with two images depicting how the first tab aligns corr ...

Guide on concealing and showcasing an icon within a bootstrap collapsible panel using solely CSS

Hey there, I've been working with Bootstrap's collapsible panel feature and I'm trying to get Font Awesome icons (+ / -) to display based on whether the panel is expanded or collapsed. I'm not too familiar with using CSS for this kind ...

Attach an event listener to a particular textarea element

Currently, I am developing a project in Next.js13 and my focus is on creating a custom textarea component. The goal is to have this component add an event listener to itself for auto-adjusting its height as the user types. Below is the relevant section of ...

How to effectively manage memory leaks in Phaser.js and properly release objects in a Phaser Canvas application?

We are currently running a game on Phaser .JS platform. We have noticed that the memory usage keeps increasing while using different browsers. What is the correct approach to clean up objects and manage memory efficiently in this scenario? ...