How do I display tooltip text for HTML <input> element using CSS style and data-title attribute?

JohnB

I am attempting to display tooltip like text using the data-title attribute for an HTML control.

I used the following technique for a element, and it works fine.

HTML Element:

<span class="spanNewID" data-title="Tooltip Text">816631-20319G14440 </span>

CSS Style:

span.spanNewID[data-title]:hover:after {
    opacity: 1;
    transition: all 0.1s ease 0.5s;
    visibility: visible;
}

span.spanNewID[data-title]:after {
    content: attr(data-title);
    background-color: lightblue;
    color: #111;
    font-size: 12pt;
    font-weight: bold;
    position: absolute;
    padding: 1px 5px 2px 5px;
    bottom: -1.6em;
    left: 100%;
    white-space: nowrap;
    box-shadow: 1px 1px 3px #222222;
    opacity: 0;
    border: 1px solid #111111;
    z-index: 99999;
    visibility: hidden;
}

span.spanNewID[data-title] {
    position: relative;
}

The above code snippet works to correctly display my css based tooltip.

I am trying to apply the same selector to an element. Consider the following:

HTML Element:

<input type="submit" value="Click Me" class="inuse" data-title="Input ELement Help"> </input>

CSS Style:

input.inuse[data-title]:hover:after {
    opacity: 1;
    transition: all 0.1s ease 0.5s;
    visibility: visible;
}

input.inuse[data-title]:after {
    content: attr(data-title);
    background-color: lightblue;
    color: #111;
    font-size: 12pt;
    font-weight: bold;
    position: absolute;
    padding: 1px 5px 2px 5px;
    bottom: -1.6em;
    left: 100%;
    white-space: nowrap;
    box-shadow: 1px 1px 3px #222222;
    opacity: 0;
    border: 1px solid #111111;
    z-index: 99999;
    visibility: hidden;
}

input.inuse[data-title] {
    position: relative;
}

The hover text/tooltip does not display in this case. I do not see any errors. There are no visible changes on the page. I attempted to use the css selector in the Chrome "CSS Selector Tester" and the selector works as expected.

What am I missing/doing wrong here?

Thanks,JohnB

Frish

I did a bit of Googling myself, and came up with some interesting information. First off, pseduo-selectors :before and :after should be used on container elements.

Potentially you could use <button></button> instead of <input> and achieve the effect you desire:

.inuse[data-title]:hover:after {
    opacity: 1;
    transition: all 0.1s ease 0.5s;
    visibility: visible;
}

.inuse[data-title]:after {
    content: attr(data-title);
    background-color: lightblue;
    color: #111;
    font-size: 12pt;
    font-weight: bold;
    position: absolute;
    padding: 1px 5px 2px 5px;
    bottom: -1.6em;
    left: 100%;
    white-space: nowrap;
    box-shadow: 1px 1px 3px #222222;
    opacity: 0;
    border: 1px solid #111111;
    z-index: 99999;
    visibility: hidden;
}

.inuse[data-title] {
    position: relative;
}
<button type="submit" value="Click Me" class="inuse" data-title="Input ELement Help">Click Me</button>

Or, and I'm sure you've considered this but it's worth mentioning anyway, just use the title attribute:

<input type="submit" value="Click Me" class="inuse" data-title="Input ELement Help" title="Input ELement Help">

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do you change the tooltip text of an HTML title element?

Changing content of a HTML element's 'title' attribute used for tooltip, using jquery or css

PHP: How to add a CSS text-align property to an already present inline style attribute of an element using simple_html_dom parser?

How do I change the style of an "<input>" element dynamically using Javascript?

How do I display a different chartjs tooltip title?

How do I style regular (untagged) HTML text with CSS?

Issue when using title attribute on style element

How do i get the text value of the text box as its title attribute using Jquery?

How do I style text input by a user?

how to find the css style attribute of a particular html element using Robot Framework?

How do I turn a form input type="text" into a HREF that sits behind a submit button, using HTML's 5 download attribute?

How do HTML5 and CSS3 specs decide the display attribute of a div element?

How to get placeholder text in HTML input in a scaffolded view by using Display(prompt) attribute over model class

How do I make this HTML display as a table using CSS floats?

How do I add text to a input element?

How do I display, in a ColorBox popup, a caption AND a title (caption from image 'alt' attribute and title from 'title' attribute

How do I style a "\n" using CSS?

How do I display any number of input text field on a modal depending on number of element in an array

How do i display a variable in a <p> element after requesting the data from a POST request using razor(C#) and html

How I can take attribute value from input element and add it to the action link using HTML?

How do I dock html input element?

How to change title attribute css in <input>?

How to get the text of /html/head/title element using Geb framework?

How do i display an element using javascript?

How do I get a cookie from user input, and display it on an html element

How to set title attribute for HTML element dynamically?

How to add title attribute on HTML element with TypeScript

How do I style the gold-email-input Polymer element?

how to create a custom tooltip using title attribute without jquery