How to change the style of the title attribute inside an anchor tag?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
Example:
<a href="example.com" title="My site"> Link </a>
How do I change the "title" attribute. By default, it just has yellow background and small font. I would like to make it bigger and change the background color.
Is there a CSS way to style the title attribute?
html css
add a comment |
Example:
<a href="example.com" title="My site"> Link </a>
How do I change the "title" attribute. By default, it just has yellow background and small font. I would like to make it bigger and change the background color.
Is there a CSS way to style the title attribute?
html css
stackoverflow.com/questions/36275678/how-to-create-a-tooltip
– Pooja Kedar
Mar 16 '17 at 5:28
add a comment |
Example:
<a href="example.com" title="My site"> Link </a>
How do I change the "title" attribute. By default, it just has yellow background and small font. I would like to make it bigger and change the background color.
Is there a CSS way to style the title attribute?
html css
Example:
<a href="example.com" title="My site"> Link </a>
How do I change the "title" attribute. By default, it just has yellow background and small font. I would like to make it bigger and change the background color.
Is there a CSS way to style the title attribute?
html css
html css
edited Jul 11 '18 at 2:10
TylerH
16.1k105569
16.1k105569
asked Jan 6 '10 at 5:33
KunphaKunpha
1,0512105
1,0512105
stackoverflow.com/questions/36275678/how-to-create-a-tooltip
– Pooja Kedar
Mar 16 '17 at 5:28
add a comment |
stackoverflow.com/questions/36275678/how-to-create-a-tooltip
– Pooja Kedar
Mar 16 '17 at 5:28
stackoverflow.com/questions/36275678/how-to-create-a-tooltip
– Pooja Kedar
Mar 16 '17 at 5:28
stackoverflow.com/questions/36275678/how-to-create-a-tooltip
– Pooja Kedar
Mar 16 '17 at 5:28
add a comment |
10 Answers
10
active
oldest
votes
Here is an example of how to do it:
a.tip {
border-bottom: 1px dashed;
text-decoration: none
}
a.tip:hover {
cursor: help;
position: relative
}
a.tip span {
display: none
}
a.tip:hover span {
border: #c0c0c0 1px dotted;
padding: 5px 20px 5px 5px;
display: block;
z-index: 100;
background: url(../images/status-info.png) #f0f0f0 no-repeat 100% 5%;
left: 0px;
margin: 10px;
width: 250px;
position: absolute;
top: 10px;
text-decoration: none
}
<a href="#" class="tip">Link<span>This is the CSS tooltip showing up when you mouse over the link</span></a>
doesn't work properly in FF if instead of the tag a use the tag, for instance, td
– dnim
Sep 27 '12 at 10:26
5
See sixrevisions.com/css/css-only-tooltips for an example of the above technique, with a detailed explanation.
– George
Oct 4 '12 at 23:22
When I do this, I see a double tool tip. The styled one, and then shortly after, the unstyled one pops over this one. This is on your fiddle. I am using chrome. Is this an abnormality?
– Aaron Loften
Jun 28 '14 at 22:04
add a comment |
It seems that there is in fact a pure CSS solution, requiring only the css attr
expression, generated content and attribute selectors (which suggests that it works as far back as IE8):
a[title]:hover:after {
content: attr(title);
position: absolute;
}
Source: https://jsfiddle.net/z42r2vv0/2/
update w/ input from @ViROscar: please note that it's not necessary to use any specific attribute, although I've used the "title" attribute in the example above; actually my recommendation would be to use the "alt" attribute, as there is some chance that the content will be accessible to users unable to benefit from CSS.
update again I'm not changing the code because the "title" attribute has basically come to mean the "tooltip" attribute, and it's probably not a good idea to hide important text inside a field only accessible on hover, but if you're interested in making this text accessible the "aria-label" attribute seems like the best place for it: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-label_attribute
10
And if you do not wish for the native tooltip to eventually display as well, you can always use the "alt" tag..
– Jon z
Jul 10 '13 at 21:32
1
@Jonz i've tried with a custom property "data-alt='alt'" and everything goes ok. is not necessary to use the alt or title property.
– ViROscar
Jan 23 '15 at 15:27
6
Pure CSS Tooltips has serious wrawback -- they are bounded to the element, thus bounded to itsstacking context
. All elements withposition
other thanstatic
creates new stacking context and pure CSS tooltips are not visible outside nor can go beyond such stacking context, so if you have tight element with positionrelative
, your CSS tooltip will not be visible. The only solution is attaching tooltip to top stacking context (e.g.<body>
) which needs JavaScript.
– Vaclav Novotny
Sep 23 '16 at 21:34
unfortunately it doesn't disappear on click.
– user2705463
Oct 11 '16 at 23:18
add a comment |
CSS can't change the tooltip appearance. It is browser/OS-dependent. If you want something different you'll have to use Javascript to generate markup when you hover over the element instead of the default tooltip.
19
One doesn't have to use JS to do it.
– ANeves
May 23 '12 at 16:47
2
The risk with 'you can't' answers is that they can become out-of-date. (The other risk is that you could just not know how.)
– Michael Scheper
Feb 6 at 5:49
add a comment |
You can't style an actual title
attribute
How the text in the title
attribute is displayed is defined by the browser and varies from browser to browser. It's not possible for a webpage to apply any style to the tooltip that the browser displays based on the title
attribute.
However, you can create something very similar using other attributes.
You can make a pseudo-tooltip with CSS and a custom attribute (e.g. data-title
)
For this, I'd use a data-title
attribute. data-*
attributes are a method to store custom data in DOM elements/HTML. There are multiple ways of accessing them. Importantly, they can be selected by CSS.
Given that you can use CSS to select elements with data-title
attributes, you can then use CSS to create :after
(or :before
) content
that contains the value of the attribute using attr()
.
Styled tooltip Examples
Bigger and with a different background color (per question's request):
[data-title]:hover:after {
opacity: 1;
transition: all 0.1s ease 0.5s;
visibility: visible;
}
[data-title]:after {
content: attr(data-title);
background-color: #00FF00;
color: #111;
font-size: 150%;
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;
}
[data-title] {
position: relative;
}
<a href="example.com" data-title="My site"> Link </a> with styled tooltip (bigger and with a different background color, as requested in the question)<br/>
<a href="example.com" title="My site"> Link </a> with normal tooltip
More elaborate styling (adapted from this blog post):
[data-title]:hover:after {
opacity: 1;
transition: all 0.1s ease 0.5s;
visibility: visible;
}
[data-title]:after {
content: attr(data-title);
position: absolute;
bottom: -1.6em;
left: 100%;
padding: 4px 4px 4px 8px;
color: #222;
white-space: nowrap;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 0px 0px 4px #222;
-webkit-box-shadow: 0px 0px 4px #222;
box-shadow: 0px 0px 4px #222;
background-image: -moz-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #f8f8f8),color-stop(1, #cccccc));
background-image: -webkit-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -moz-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -ms-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -o-linear-gradient(top, #f8f8f8, #cccccc);
opacity: 0;
z-index: 99999;
visibility: hidden;
}
[data-title] {
position: relative;
}
<a href="example.com" data-title="My site"> Link </a> with styled tooltip<br/>
<a href="example.com" title="My site"> Link </a> with normal tooltip
Known issues
Unlike a real title
tooltip, the tooltip produced by the above CSS is not, necessarily, guaranteed to be visible on the page (i.e. it might be outside the visible area). On the other hand, it is guaranteed to be within the current window, which is not the case for an actual tooltip.
From the code on the blog post linked above (which I first saw in an answer here that plagiarized it), it appeared obvious to me to use a data-*
attribute instead of the title
attribute. Doing so was also suggested in a comment by snostorm on that (now deleted) answer.
This may not the answer to the question, but this is the best solution so far. Thanks.
– JJ Labajo
Nov 16 '18 at 15:44
@JJLabajo Thanks for the complement about this being the best solution so far. However, I'm not sure how this doesn't answer the question. The question is asking for something that's just not possible. This answer says it's not possible, but offers an alternative that accomplishes something similar to what the OP desires.
– Makyen
Dec 26 '18 at 14:38
add a comment |
I thought i'd post my 20 lines JavaScript solution here. It is not perfect, but may be useful for some depending on what you need from your tooltips.
When to use it
- Automatically styles the tooltip for all HTML elements with a
TITLE
attribute defined (this includes elements dynamically added to the document in the future) - No Javascript/HTML changes or hacks required for every tooltip (just the
TITLE
attribute, semantically clear) - Very light (adds about 300 bytes gzipped and minified)
- You want only a very basic styleable tooltip
When NOT to use
- Requires jQuery, so do not use if you don't use jQuery
- Bad support for nested elements that both have tooltips
- You need more than one tooltip on the screen at the same time
- You need the tooltip to disappear after some time
The code
// Use a closure to keep vars out of global scope
(function () {
var ID = "tooltip", CLS_ON = "tooltip_ON", FOLLOW = true,
DATA = "_tooltip", OFFSET_X = 20, OFFSET_Y = 10,
showAt = function (e) {
var ntop = e.pageY + OFFSET_Y, nleft = e.pageX + OFFSET_X;
$("#" + ID).html($(e.target).data(DATA)).css({
position: "absolute", top: ntop, left: nleft
}).show();
};
$(document).on("mouseenter", "*[title]", function (e) {
$(this).data(DATA, $(this).attr("title"));
$(this).removeAttr("title").addClass(CLS_ON);
$("<div id='" + ID + "' />").appendTo("body");
showAt(e);
});
$(document).on("mouseleave", "." + CLS_ON, function (e) {
$(this).attr("title", $(this).data(DATA)).removeClass(CLS_ON);
$("#" + ID).remove();
});
if (FOLLOW) { $(document).on("mousemove", "." + CLS_ON, showAt); }
}());
Paste it anywhere, it should work even when you run this code before the DOM is ready (it just won't show your tooltips until DOM is ready).
Customize
You can change the var
declarations on the second line to customize it a bit.
var ID = "tooltip"; // The ID of the styleable tooltip
var CLS_ON = "tooltip_ON"; // Does not matter, make it somewhat unique
var FOLLOW = true; // TRUE to enable mouse following, FALSE to have static tooltips
var DATA = "_tooltip"; // Does not matter, make it somewhat unique
var OFFSET_X = 20, OFFSET_Y = 10; // Tooltip's distance to the cursor
Style
You can now style your tooltips using the following CSS:
#tooltip {
background: #fff;
border: 1px solid red;
padding: 3px 10px;
}
2
Works great! Fix for a minor bug (if title is empty) can be found here: stackoverflow.com/questions/26702472/…
– Malasorte
Nov 2 '14 at 18:10
If you move rapidly over an element I am getting an empty tooltip, even with the bug fix mentioned above. This is erratic and stops if I take off the $(this).removeAttr("title"). But of course I then get the standard help showing after a while.
– Allen Conquest
Oct 25 '17 at 9:47
add a comment |
A jsfiddle for custom tooltip pattern is Here
It is based on CSS Positioning and pseduo class selectors
Check MDN docs for cross-browser support of pseudo classes
<!-- HTML -->
<p>
<a href="http://www.google.com/" class="tooltip">
I am a
<span> (This website rocks) </span></a> a developer.
</p>
/*CSS*/
a.tooltip {
position: relative;
}
a.tooltip span {
display: none;
}
a.tooltip:hover span, a.tooltip:focus span {
display:block;
position:absolute;
top:1em;
left:1.5em;
padding: 0.2em 0.6em;
border:1px solid #996633;
background-color:#FFFF66;
color:#000;
}
add a comment |
I have found the answer here: http://www.webdesignerdepot.com/2012/11/how-to-create-a-simple-css3-tooltip/
my own code goes like this, I have changed the attribute name, if you maintain the title name for the attribute you end up having two popups for the same text, another change is that my text on hovering displays underneath the exposed text.
.tags {
display: inline;
position: relative;
}
.tags:hover:after {
background: #333;
background: rgba(0, 0, 0, .8);
border-radius: 5px;
bottom: -34px;
color: #fff;
content: attr(glose);
left: 20%;
padding: 5px 15px;
position: absolute;
z-index: 98;
width: 350px;
}
.tags:hover:before {
border: solid;
border-color: #333 transparent;
border-width: 0 6px 6px 6px;
bottom: -4px;
content: "";
left: 50%;
position: absolute;
z-index: 99;
}
<a class="tags" glose="Text shown on hovering">Exposed text</a>
add a comment |
Native tooltip cannot be styled.
That being said, you can use some library that would show styles floating layers when element is being hovered (instead of the native tooltips, and suppress them) requiring little or no code modifications...
I don’t think you can suppress the native tooltips if an element has atitle
attribute. So if you set up your own tooltip implementation, it is better to use some other attribute (say,data-tip
) instead oftitle
.
– Jukka K. Korpela
Mar 29 '12 at 16:08
1
you can, if after you attach to the event you clear title attribute
– poncha
Mar 30 '12 at 8:49
1
I see your point, but it’s not about styling native tooltips; it’s about avoiding them (by modifying the DOM).
– Jukka K. Korpela
Mar 30 '12 at 10:26
@JukkaK.Korpela yep, and i said in my first sentence that it was impossible ;)
– poncha
Mar 30 '12 at 11:19
The benefit of using the title attribute and clearing it later is that the tooltip is still available if the user has JavaScript disabled.
– JJJ
May 9 '13 at 11:54
|
show 1 more comment
You cannot style the default browser tooltip. But you can use javascript to create your own custom HTML tooltips.
add a comment |
a[title="My site"] {
color: red;
}
This also works with any attribute you want to add for instance:
HTML
<div class="my_class" anything="whatever">My Stuff</div>
CSS
.my_class[anything="whatever"] {
color: red;
}
See it work at: http://jsfiddle.net/vpYWE/1/
13
That styles an element with the specified title; not the tooltip title that the browser displays
– Rowland Shaw
Nov 29 '13 at 12:58
1
Also,anything
isn’t a valid HTML attribute. For custom attributes usedata-
attributes.
– Sebastian Simon
Jun 6 '16 at 10:39
add a comment |
protected by Community♦ Apr 21 '13 at 10:11
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
10 Answers
10
active
oldest
votes
10 Answers
10
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here is an example of how to do it:
a.tip {
border-bottom: 1px dashed;
text-decoration: none
}
a.tip:hover {
cursor: help;
position: relative
}
a.tip span {
display: none
}
a.tip:hover span {
border: #c0c0c0 1px dotted;
padding: 5px 20px 5px 5px;
display: block;
z-index: 100;
background: url(../images/status-info.png) #f0f0f0 no-repeat 100% 5%;
left: 0px;
margin: 10px;
width: 250px;
position: absolute;
top: 10px;
text-decoration: none
}
<a href="#" class="tip">Link<span>This is the CSS tooltip showing up when you mouse over the link</span></a>
doesn't work properly in FF if instead of the tag a use the tag, for instance, td
– dnim
Sep 27 '12 at 10:26
5
See sixrevisions.com/css/css-only-tooltips for an example of the above technique, with a detailed explanation.
– George
Oct 4 '12 at 23:22
When I do this, I see a double tool tip. The styled one, and then shortly after, the unstyled one pops over this one. This is on your fiddle. I am using chrome. Is this an abnormality?
– Aaron Loften
Jun 28 '14 at 22:04
add a comment |
Here is an example of how to do it:
a.tip {
border-bottom: 1px dashed;
text-decoration: none
}
a.tip:hover {
cursor: help;
position: relative
}
a.tip span {
display: none
}
a.tip:hover span {
border: #c0c0c0 1px dotted;
padding: 5px 20px 5px 5px;
display: block;
z-index: 100;
background: url(../images/status-info.png) #f0f0f0 no-repeat 100% 5%;
left: 0px;
margin: 10px;
width: 250px;
position: absolute;
top: 10px;
text-decoration: none
}
<a href="#" class="tip">Link<span>This is the CSS tooltip showing up when you mouse over the link</span></a>
doesn't work properly in FF if instead of the tag a use the tag, for instance, td
– dnim
Sep 27 '12 at 10:26
5
See sixrevisions.com/css/css-only-tooltips for an example of the above technique, with a detailed explanation.
– George
Oct 4 '12 at 23:22
When I do this, I see a double tool tip. The styled one, and then shortly after, the unstyled one pops over this one. This is on your fiddle. I am using chrome. Is this an abnormality?
– Aaron Loften
Jun 28 '14 at 22:04
add a comment |
Here is an example of how to do it:
a.tip {
border-bottom: 1px dashed;
text-decoration: none
}
a.tip:hover {
cursor: help;
position: relative
}
a.tip span {
display: none
}
a.tip:hover span {
border: #c0c0c0 1px dotted;
padding: 5px 20px 5px 5px;
display: block;
z-index: 100;
background: url(../images/status-info.png) #f0f0f0 no-repeat 100% 5%;
left: 0px;
margin: 10px;
width: 250px;
position: absolute;
top: 10px;
text-decoration: none
}
<a href="#" class="tip">Link<span>This is the CSS tooltip showing up when you mouse over the link</span></a>
Here is an example of how to do it:
a.tip {
border-bottom: 1px dashed;
text-decoration: none
}
a.tip:hover {
cursor: help;
position: relative
}
a.tip span {
display: none
}
a.tip:hover span {
border: #c0c0c0 1px dotted;
padding: 5px 20px 5px 5px;
display: block;
z-index: 100;
background: url(../images/status-info.png) #f0f0f0 no-repeat 100% 5%;
left: 0px;
margin: 10px;
width: 250px;
position: absolute;
top: 10px;
text-decoration: none
}
<a href="#" class="tip">Link<span>This is the CSS tooltip showing up when you mouse over the link</span></a>
a.tip {
border-bottom: 1px dashed;
text-decoration: none
}
a.tip:hover {
cursor: help;
position: relative
}
a.tip span {
display: none
}
a.tip:hover span {
border: #c0c0c0 1px dotted;
padding: 5px 20px 5px 5px;
display: block;
z-index: 100;
background: url(../images/status-info.png) #f0f0f0 no-repeat 100% 5%;
left: 0px;
margin: 10px;
width: 250px;
position: absolute;
top: 10px;
text-decoration: none
}
<a href="#" class="tip">Link<span>This is the CSS tooltip showing up when you mouse over the link</span></a>
a.tip {
border-bottom: 1px dashed;
text-decoration: none
}
a.tip:hover {
cursor: help;
position: relative
}
a.tip span {
display: none
}
a.tip:hover span {
border: #c0c0c0 1px dotted;
padding: 5px 20px 5px 5px;
display: block;
z-index: 100;
background: url(../images/status-info.png) #f0f0f0 no-repeat 100% 5%;
left: 0px;
margin: 10px;
width: 250px;
position: absolute;
top: 10px;
text-decoration: none
}
<a href="#" class="tip">Link<span>This is the CSS tooltip showing up when you mouse over the link</span></a>
edited Nov 13 '16 at 11:02
Stephen Ostermiller
14.4k76482
14.4k76482
answered Jan 6 '10 at 5:56
vallivalli
4,4532158
4,4532158
doesn't work properly in FF if instead of the tag a use the tag, for instance, td
– dnim
Sep 27 '12 at 10:26
5
See sixrevisions.com/css/css-only-tooltips for an example of the above technique, with a detailed explanation.
– George
Oct 4 '12 at 23:22
When I do this, I see a double tool tip. The styled one, and then shortly after, the unstyled one pops over this one. This is on your fiddle. I am using chrome. Is this an abnormality?
– Aaron Loften
Jun 28 '14 at 22:04
add a comment |
doesn't work properly in FF if instead of the tag a use the tag, for instance, td
– dnim
Sep 27 '12 at 10:26
5
See sixrevisions.com/css/css-only-tooltips for an example of the above technique, with a detailed explanation.
– George
Oct 4 '12 at 23:22
When I do this, I see a double tool tip. The styled one, and then shortly after, the unstyled one pops over this one. This is on your fiddle. I am using chrome. Is this an abnormality?
– Aaron Loften
Jun 28 '14 at 22:04
doesn't work properly in FF if instead of the tag a use the tag, for instance, td
– dnim
Sep 27 '12 at 10:26
doesn't work properly in FF if instead of the tag a use the tag, for instance, td
– dnim
Sep 27 '12 at 10:26
5
5
See sixrevisions.com/css/css-only-tooltips for an example of the above technique, with a detailed explanation.
– George
Oct 4 '12 at 23:22
See sixrevisions.com/css/css-only-tooltips for an example of the above technique, with a detailed explanation.
– George
Oct 4 '12 at 23:22
When I do this, I see a double tool tip. The styled one, and then shortly after, the unstyled one pops over this one. This is on your fiddle. I am using chrome. Is this an abnormality?
– Aaron Loften
Jun 28 '14 at 22:04
When I do this, I see a double tool tip. The styled one, and then shortly after, the unstyled one pops over this one. This is on your fiddle. I am using chrome. Is this an abnormality?
– Aaron Loften
Jun 28 '14 at 22:04
add a comment |
It seems that there is in fact a pure CSS solution, requiring only the css attr
expression, generated content and attribute selectors (which suggests that it works as far back as IE8):
a[title]:hover:after {
content: attr(title);
position: absolute;
}
Source: https://jsfiddle.net/z42r2vv0/2/
update w/ input from @ViROscar: please note that it's not necessary to use any specific attribute, although I've used the "title" attribute in the example above; actually my recommendation would be to use the "alt" attribute, as there is some chance that the content will be accessible to users unable to benefit from CSS.
update again I'm not changing the code because the "title" attribute has basically come to mean the "tooltip" attribute, and it's probably not a good idea to hide important text inside a field only accessible on hover, but if you're interested in making this text accessible the "aria-label" attribute seems like the best place for it: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-label_attribute
10
And if you do not wish for the native tooltip to eventually display as well, you can always use the "alt" tag..
– Jon z
Jul 10 '13 at 21:32
1
@Jonz i've tried with a custom property "data-alt='alt'" and everything goes ok. is not necessary to use the alt or title property.
– ViROscar
Jan 23 '15 at 15:27
6
Pure CSS Tooltips has serious wrawback -- they are bounded to the element, thus bounded to itsstacking context
. All elements withposition
other thanstatic
creates new stacking context and pure CSS tooltips are not visible outside nor can go beyond such stacking context, so if you have tight element with positionrelative
, your CSS tooltip will not be visible. The only solution is attaching tooltip to top stacking context (e.g.<body>
) which needs JavaScript.
– Vaclav Novotny
Sep 23 '16 at 21:34
unfortunately it doesn't disappear on click.
– user2705463
Oct 11 '16 at 23:18
add a comment |
It seems that there is in fact a pure CSS solution, requiring only the css attr
expression, generated content and attribute selectors (which suggests that it works as far back as IE8):
a[title]:hover:after {
content: attr(title);
position: absolute;
}
Source: https://jsfiddle.net/z42r2vv0/2/
update w/ input from @ViROscar: please note that it's not necessary to use any specific attribute, although I've used the "title" attribute in the example above; actually my recommendation would be to use the "alt" attribute, as there is some chance that the content will be accessible to users unable to benefit from CSS.
update again I'm not changing the code because the "title" attribute has basically come to mean the "tooltip" attribute, and it's probably not a good idea to hide important text inside a field only accessible on hover, but if you're interested in making this text accessible the "aria-label" attribute seems like the best place for it: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-label_attribute
10
And if you do not wish for the native tooltip to eventually display as well, you can always use the "alt" tag..
– Jon z
Jul 10 '13 at 21:32
1
@Jonz i've tried with a custom property "data-alt='alt'" and everything goes ok. is not necessary to use the alt or title property.
– ViROscar
Jan 23 '15 at 15:27
6
Pure CSS Tooltips has serious wrawback -- they are bounded to the element, thus bounded to itsstacking context
. All elements withposition
other thanstatic
creates new stacking context and pure CSS tooltips are not visible outside nor can go beyond such stacking context, so if you have tight element with positionrelative
, your CSS tooltip will not be visible. The only solution is attaching tooltip to top stacking context (e.g.<body>
) which needs JavaScript.
– Vaclav Novotny
Sep 23 '16 at 21:34
unfortunately it doesn't disappear on click.
– user2705463
Oct 11 '16 at 23:18
add a comment |
It seems that there is in fact a pure CSS solution, requiring only the css attr
expression, generated content and attribute selectors (which suggests that it works as far back as IE8):
a[title]:hover:after {
content: attr(title);
position: absolute;
}
Source: https://jsfiddle.net/z42r2vv0/2/
update w/ input from @ViROscar: please note that it's not necessary to use any specific attribute, although I've used the "title" attribute in the example above; actually my recommendation would be to use the "alt" attribute, as there is some chance that the content will be accessible to users unable to benefit from CSS.
update again I'm not changing the code because the "title" attribute has basically come to mean the "tooltip" attribute, and it's probably not a good idea to hide important text inside a field only accessible on hover, but if you're interested in making this text accessible the "aria-label" attribute seems like the best place for it: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-label_attribute
It seems that there is in fact a pure CSS solution, requiring only the css attr
expression, generated content and attribute selectors (which suggests that it works as far back as IE8):
a[title]:hover:after {
content: attr(title);
position: absolute;
}
Source: https://jsfiddle.net/z42r2vv0/2/
update w/ input from @ViROscar: please note that it's not necessary to use any specific attribute, although I've used the "title" attribute in the example above; actually my recommendation would be to use the "alt" attribute, as there is some chance that the content will be accessible to users unable to benefit from CSS.
update again I'm not changing the code because the "title" attribute has basically come to mean the "tooltip" attribute, and it's probably not a good idea to hide important text inside a field only accessible on hover, but if you're interested in making this text accessible the "aria-label" attribute seems like the best place for it: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-label_attribute
edited Mar 15 '18 at 7:50
A Friend
634617
634617
answered Jul 10 '13 at 19:44
Jon zJon z
2,3952118
2,3952118
10
And if you do not wish for the native tooltip to eventually display as well, you can always use the "alt" tag..
– Jon z
Jul 10 '13 at 21:32
1
@Jonz i've tried with a custom property "data-alt='alt'" and everything goes ok. is not necessary to use the alt or title property.
– ViROscar
Jan 23 '15 at 15:27
6
Pure CSS Tooltips has serious wrawback -- they are bounded to the element, thus bounded to itsstacking context
. All elements withposition
other thanstatic
creates new stacking context and pure CSS tooltips are not visible outside nor can go beyond such stacking context, so if you have tight element with positionrelative
, your CSS tooltip will not be visible. The only solution is attaching tooltip to top stacking context (e.g.<body>
) which needs JavaScript.
– Vaclav Novotny
Sep 23 '16 at 21:34
unfortunately it doesn't disappear on click.
– user2705463
Oct 11 '16 at 23:18
add a comment |
10
And if you do not wish for the native tooltip to eventually display as well, you can always use the "alt" tag..
– Jon z
Jul 10 '13 at 21:32
1
@Jonz i've tried with a custom property "data-alt='alt'" and everything goes ok. is not necessary to use the alt or title property.
– ViROscar
Jan 23 '15 at 15:27
6
Pure CSS Tooltips has serious wrawback -- they are bounded to the element, thus bounded to itsstacking context
. All elements withposition
other thanstatic
creates new stacking context and pure CSS tooltips are not visible outside nor can go beyond such stacking context, so if you have tight element with positionrelative
, your CSS tooltip will not be visible. The only solution is attaching tooltip to top stacking context (e.g.<body>
) which needs JavaScript.
– Vaclav Novotny
Sep 23 '16 at 21:34
unfortunately it doesn't disappear on click.
– user2705463
Oct 11 '16 at 23:18
10
10
And if you do not wish for the native tooltip to eventually display as well, you can always use the "alt" tag..
– Jon z
Jul 10 '13 at 21:32
And if you do not wish for the native tooltip to eventually display as well, you can always use the "alt" tag..
– Jon z
Jul 10 '13 at 21:32
1
1
@Jonz i've tried with a custom property "data-alt='alt'" and everything goes ok. is not necessary to use the alt or title property.
– ViROscar
Jan 23 '15 at 15:27
@Jonz i've tried with a custom property "data-alt='alt'" and everything goes ok. is not necessary to use the alt or title property.
– ViROscar
Jan 23 '15 at 15:27
6
6
Pure CSS Tooltips has serious wrawback -- they are bounded to the element, thus bounded to its
stacking context
. All elements with position
other than static
creates new stacking context and pure CSS tooltips are not visible outside nor can go beyond such stacking context, so if you have tight element with position relative
, your CSS tooltip will not be visible. The only solution is attaching tooltip to top stacking context (e.g. <body>
) which needs JavaScript.– Vaclav Novotny
Sep 23 '16 at 21:34
Pure CSS Tooltips has serious wrawback -- they are bounded to the element, thus bounded to its
stacking context
. All elements with position
other than static
creates new stacking context and pure CSS tooltips are not visible outside nor can go beyond such stacking context, so if you have tight element with position relative
, your CSS tooltip will not be visible. The only solution is attaching tooltip to top stacking context (e.g. <body>
) which needs JavaScript.– Vaclav Novotny
Sep 23 '16 at 21:34
unfortunately it doesn't disappear on click.
– user2705463
Oct 11 '16 at 23:18
unfortunately it doesn't disappear on click.
– user2705463
Oct 11 '16 at 23:18
add a comment |
CSS can't change the tooltip appearance. It is browser/OS-dependent. If you want something different you'll have to use Javascript to generate markup when you hover over the element instead of the default tooltip.
19
One doesn't have to use JS to do it.
– ANeves
May 23 '12 at 16:47
2
The risk with 'you can't' answers is that they can become out-of-date. (The other risk is that you could just not know how.)
– Michael Scheper
Feb 6 at 5:49
add a comment |
CSS can't change the tooltip appearance. It is browser/OS-dependent. If you want something different you'll have to use Javascript to generate markup when you hover over the element instead of the default tooltip.
19
One doesn't have to use JS to do it.
– ANeves
May 23 '12 at 16:47
2
The risk with 'you can't' answers is that they can become out-of-date. (The other risk is that you could just not know how.)
– Michael Scheper
Feb 6 at 5:49
add a comment |
CSS can't change the tooltip appearance. It is browser/OS-dependent. If you want something different you'll have to use Javascript to generate markup when you hover over the element instead of the default tooltip.
CSS can't change the tooltip appearance. It is browser/OS-dependent. If you want something different you'll have to use Javascript to generate markup when you hover over the element instead of the default tooltip.
answered Jan 6 '10 at 5:39
cletuscletus
513k141844915
513k141844915
19
One doesn't have to use JS to do it.
– ANeves
May 23 '12 at 16:47
2
The risk with 'you can't' answers is that they can become out-of-date. (The other risk is that you could just not know how.)
– Michael Scheper
Feb 6 at 5:49
add a comment |
19
One doesn't have to use JS to do it.
– ANeves
May 23 '12 at 16:47
2
The risk with 'you can't' answers is that they can become out-of-date. (The other risk is that you could just not know how.)
– Michael Scheper
Feb 6 at 5:49
19
19
One doesn't have to use JS to do it.
– ANeves
May 23 '12 at 16:47
One doesn't have to use JS to do it.
– ANeves
May 23 '12 at 16:47
2
2
The risk with 'you can't' answers is that they can become out-of-date. (The other risk is that you could just not know how.)
– Michael Scheper
Feb 6 at 5:49
The risk with 'you can't' answers is that they can become out-of-date. (The other risk is that you could just not know how.)
– Michael Scheper
Feb 6 at 5:49
add a comment |
You can't style an actual title
attribute
How the text in the title
attribute is displayed is defined by the browser and varies from browser to browser. It's not possible for a webpage to apply any style to the tooltip that the browser displays based on the title
attribute.
However, you can create something very similar using other attributes.
You can make a pseudo-tooltip with CSS and a custom attribute (e.g. data-title
)
For this, I'd use a data-title
attribute. data-*
attributes are a method to store custom data in DOM elements/HTML. There are multiple ways of accessing them. Importantly, they can be selected by CSS.
Given that you can use CSS to select elements with data-title
attributes, you can then use CSS to create :after
(or :before
) content
that contains the value of the attribute using attr()
.
Styled tooltip Examples
Bigger and with a different background color (per question's request):
[data-title]:hover:after {
opacity: 1;
transition: all 0.1s ease 0.5s;
visibility: visible;
}
[data-title]:after {
content: attr(data-title);
background-color: #00FF00;
color: #111;
font-size: 150%;
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;
}
[data-title] {
position: relative;
}
<a href="example.com" data-title="My site"> Link </a> with styled tooltip (bigger and with a different background color, as requested in the question)<br/>
<a href="example.com" title="My site"> Link </a> with normal tooltip
More elaborate styling (adapted from this blog post):
[data-title]:hover:after {
opacity: 1;
transition: all 0.1s ease 0.5s;
visibility: visible;
}
[data-title]:after {
content: attr(data-title);
position: absolute;
bottom: -1.6em;
left: 100%;
padding: 4px 4px 4px 8px;
color: #222;
white-space: nowrap;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 0px 0px 4px #222;
-webkit-box-shadow: 0px 0px 4px #222;
box-shadow: 0px 0px 4px #222;
background-image: -moz-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #f8f8f8),color-stop(1, #cccccc));
background-image: -webkit-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -moz-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -ms-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -o-linear-gradient(top, #f8f8f8, #cccccc);
opacity: 0;
z-index: 99999;
visibility: hidden;
}
[data-title] {
position: relative;
}
<a href="example.com" data-title="My site"> Link </a> with styled tooltip<br/>
<a href="example.com" title="My site"> Link </a> with normal tooltip
Known issues
Unlike a real title
tooltip, the tooltip produced by the above CSS is not, necessarily, guaranteed to be visible on the page (i.e. it might be outside the visible area). On the other hand, it is guaranteed to be within the current window, which is not the case for an actual tooltip.
From the code on the blog post linked above (which I first saw in an answer here that plagiarized it), it appeared obvious to me to use a data-*
attribute instead of the title
attribute. Doing so was also suggested in a comment by snostorm on that (now deleted) answer.
This may not the answer to the question, but this is the best solution so far. Thanks.
– JJ Labajo
Nov 16 '18 at 15:44
@JJLabajo Thanks for the complement about this being the best solution so far. However, I'm not sure how this doesn't answer the question. The question is asking for something that's just not possible. This answer says it's not possible, but offers an alternative that accomplishes something similar to what the OP desires.
– Makyen
Dec 26 '18 at 14:38
add a comment |
You can't style an actual title
attribute
How the text in the title
attribute is displayed is defined by the browser and varies from browser to browser. It's not possible for a webpage to apply any style to the tooltip that the browser displays based on the title
attribute.
However, you can create something very similar using other attributes.
You can make a pseudo-tooltip with CSS and a custom attribute (e.g. data-title
)
For this, I'd use a data-title
attribute. data-*
attributes are a method to store custom data in DOM elements/HTML. There are multiple ways of accessing them. Importantly, they can be selected by CSS.
Given that you can use CSS to select elements with data-title
attributes, you can then use CSS to create :after
(or :before
) content
that contains the value of the attribute using attr()
.
Styled tooltip Examples
Bigger and with a different background color (per question's request):
[data-title]:hover:after {
opacity: 1;
transition: all 0.1s ease 0.5s;
visibility: visible;
}
[data-title]:after {
content: attr(data-title);
background-color: #00FF00;
color: #111;
font-size: 150%;
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;
}
[data-title] {
position: relative;
}
<a href="example.com" data-title="My site"> Link </a> with styled tooltip (bigger and with a different background color, as requested in the question)<br/>
<a href="example.com" title="My site"> Link </a> with normal tooltip
More elaborate styling (adapted from this blog post):
[data-title]:hover:after {
opacity: 1;
transition: all 0.1s ease 0.5s;
visibility: visible;
}
[data-title]:after {
content: attr(data-title);
position: absolute;
bottom: -1.6em;
left: 100%;
padding: 4px 4px 4px 8px;
color: #222;
white-space: nowrap;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 0px 0px 4px #222;
-webkit-box-shadow: 0px 0px 4px #222;
box-shadow: 0px 0px 4px #222;
background-image: -moz-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #f8f8f8),color-stop(1, #cccccc));
background-image: -webkit-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -moz-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -ms-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -o-linear-gradient(top, #f8f8f8, #cccccc);
opacity: 0;
z-index: 99999;
visibility: hidden;
}
[data-title] {
position: relative;
}
<a href="example.com" data-title="My site"> Link </a> with styled tooltip<br/>
<a href="example.com" title="My site"> Link </a> with normal tooltip
Known issues
Unlike a real title
tooltip, the tooltip produced by the above CSS is not, necessarily, guaranteed to be visible on the page (i.e. it might be outside the visible area). On the other hand, it is guaranteed to be within the current window, which is not the case for an actual tooltip.
From the code on the blog post linked above (which I first saw in an answer here that plagiarized it), it appeared obvious to me to use a data-*
attribute instead of the title
attribute. Doing so was also suggested in a comment by snostorm on that (now deleted) answer.
This may not the answer to the question, but this is the best solution so far. Thanks.
– JJ Labajo
Nov 16 '18 at 15:44
@JJLabajo Thanks for the complement about this being the best solution so far. However, I'm not sure how this doesn't answer the question. The question is asking for something that's just not possible. This answer says it's not possible, but offers an alternative that accomplishes something similar to what the OP desires.
– Makyen
Dec 26 '18 at 14:38
add a comment |
You can't style an actual title
attribute
How the text in the title
attribute is displayed is defined by the browser and varies from browser to browser. It's not possible for a webpage to apply any style to the tooltip that the browser displays based on the title
attribute.
However, you can create something very similar using other attributes.
You can make a pseudo-tooltip with CSS and a custom attribute (e.g. data-title
)
For this, I'd use a data-title
attribute. data-*
attributes are a method to store custom data in DOM elements/HTML. There are multiple ways of accessing them. Importantly, they can be selected by CSS.
Given that you can use CSS to select elements with data-title
attributes, you can then use CSS to create :after
(or :before
) content
that contains the value of the attribute using attr()
.
Styled tooltip Examples
Bigger and with a different background color (per question's request):
[data-title]:hover:after {
opacity: 1;
transition: all 0.1s ease 0.5s;
visibility: visible;
}
[data-title]:after {
content: attr(data-title);
background-color: #00FF00;
color: #111;
font-size: 150%;
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;
}
[data-title] {
position: relative;
}
<a href="example.com" data-title="My site"> Link </a> with styled tooltip (bigger and with a different background color, as requested in the question)<br/>
<a href="example.com" title="My site"> Link </a> with normal tooltip
More elaborate styling (adapted from this blog post):
[data-title]:hover:after {
opacity: 1;
transition: all 0.1s ease 0.5s;
visibility: visible;
}
[data-title]:after {
content: attr(data-title);
position: absolute;
bottom: -1.6em;
left: 100%;
padding: 4px 4px 4px 8px;
color: #222;
white-space: nowrap;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 0px 0px 4px #222;
-webkit-box-shadow: 0px 0px 4px #222;
box-shadow: 0px 0px 4px #222;
background-image: -moz-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #f8f8f8),color-stop(1, #cccccc));
background-image: -webkit-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -moz-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -ms-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -o-linear-gradient(top, #f8f8f8, #cccccc);
opacity: 0;
z-index: 99999;
visibility: hidden;
}
[data-title] {
position: relative;
}
<a href="example.com" data-title="My site"> Link </a> with styled tooltip<br/>
<a href="example.com" title="My site"> Link </a> with normal tooltip
Known issues
Unlike a real title
tooltip, the tooltip produced by the above CSS is not, necessarily, guaranteed to be visible on the page (i.e. it might be outside the visible area). On the other hand, it is guaranteed to be within the current window, which is not the case for an actual tooltip.
From the code on the blog post linked above (which I first saw in an answer here that plagiarized it), it appeared obvious to me to use a data-*
attribute instead of the title
attribute. Doing so was also suggested in a comment by snostorm on that (now deleted) answer.
You can't style an actual title
attribute
How the text in the title
attribute is displayed is defined by the browser and varies from browser to browser. It's not possible for a webpage to apply any style to the tooltip that the browser displays based on the title
attribute.
However, you can create something very similar using other attributes.
You can make a pseudo-tooltip with CSS and a custom attribute (e.g. data-title
)
For this, I'd use a data-title
attribute. data-*
attributes are a method to store custom data in DOM elements/HTML. There are multiple ways of accessing them. Importantly, they can be selected by CSS.
Given that you can use CSS to select elements with data-title
attributes, you can then use CSS to create :after
(or :before
) content
that contains the value of the attribute using attr()
.
Styled tooltip Examples
Bigger and with a different background color (per question's request):
[data-title]:hover:after {
opacity: 1;
transition: all 0.1s ease 0.5s;
visibility: visible;
}
[data-title]:after {
content: attr(data-title);
background-color: #00FF00;
color: #111;
font-size: 150%;
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;
}
[data-title] {
position: relative;
}
<a href="example.com" data-title="My site"> Link </a> with styled tooltip (bigger and with a different background color, as requested in the question)<br/>
<a href="example.com" title="My site"> Link </a> with normal tooltip
More elaborate styling (adapted from this blog post):
[data-title]:hover:after {
opacity: 1;
transition: all 0.1s ease 0.5s;
visibility: visible;
}
[data-title]:after {
content: attr(data-title);
position: absolute;
bottom: -1.6em;
left: 100%;
padding: 4px 4px 4px 8px;
color: #222;
white-space: nowrap;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 0px 0px 4px #222;
-webkit-box-shadow: 0px 0px 4px #222;
box-shadow: 0px 0px 4px #222;
background-image: -moz-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #f8f8f8),color-stop(1, #cccccc));
background-image: -webkit-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -moz-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -ms-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -o-linear-gradient(top, #f8f8f8, #cccccc);
opacity: 0;
z-index: 99999;
visibility: hidden;
}
[data-title] {
position: relative;
}
<a href="example.com" data-title="My site"> Link </a> with styled tooltip<br/>
<a href="example.com" title="My site"> Link </a> with normal tooltip
Known issues
Unlike a real title
tooltip, the tooltip produced by the above CSS is not, necessarily, guaranteed to be visible on the page (i.e. it might be outside the visible area). On the other hand, it is guaranteed to be within the current window, which is not the case for an actual tooltip.
From the code on the blog post linked above (which I first saw in an answer here that plagiarized it), it appeared obvious to me to use a data-*
attribute instead of the title
attribute. Doing so was also suggested in a comment by snostorm on that (now deleted) answer.
[data-title]:hover:after {
opacity: 1;
transition: all 0.1s ease 0.5s;
visibility: visible;
}
[data-title]:after {
content: attr(data-title);
background-color: #00FF00;
color: #111;
font-size: 150%;
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;
}
[data-title] {
position: relative;
}
<a href="example.com" data-title="My site"> Link </a> with styled tooltip (bigger and with a different background color, as requested in the question)<br/>
<a href="example.com" title="My site"> Link </a> with normal tooltip
[data-title]:hover:after {
opacity: 1;
transition: all 0.1s ease 0.5s;
visibility: visible;
}
[data-title]:after {
content: attr(data-title);
background-color: #00FF00;
color: #111;
font-size: 150%;
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;
}
[data-title] {
position: relative;
}
<a href="example.com" data-title="My site"> Link </a> with styled tooltip (bigger and with a different background color, as requested in the question)<br/>
<a href="example.com" title="My site"> Link </a> with normal tooltip
[data-title]:hover:after {
opacity: 1;
transition: all 0.1s ease 0.5s;
visibility: visible;
}
[data-title]:after {
content: attr(data-title);
position: absolute;
bottom: -1.6em;
left: 100%;
padding: 4px 4px 4px 8px;
color: #222;
white-space: nowrap;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 0px 0px 4px #222;
-webkit-box-shadow: 0px 0px 4px #222;
box-shadow: 0px 0px 4px #222;
background-image: -moz-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #f8f8f8),color-stop(1, #cccccc));
background-image: -webkit-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -moz-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -ms-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -o-linear-gradient(top, #f8f8f8, #cccccc);
opacity: 0;
z-index: 99999;
visibility: hidden;
}
[data-title] {
position: relative;
}
<a href="example.com" data-title="My site"> Link </a> with styled tooltip<br/>
<a href="example.com" title="My site"> Link </a> with normal tooltip
[data-title]:hover:after {
opacity: 1;
transition: all 0.1s ease 0.5s;
visibility: visible;
}
[data-title]:after {
content: attr(data-title);
position: absolute;
bottom: -1.6em;
left: 100%;
padding: 4px 4px 4px 8px;
color: #222;
white-space: nowrap;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 0px 0px 4px #222;
-webkit-box-shadow: 0px 0px 4px #222;
box-shadow: 0px 0px 4px #222;
background-image: -moz-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #f8f8f8),color-stop(1, #cccccc));
background-image: -webkit-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -moz-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -ms-linear-gradient(top, #f8f8f8, #cccccc);
background-image: -o-linear-gradient(top, #f8f8f8, #cccccc);
opacity: 0;
z-index: 99999;
visibility: hidden;
}
[data-title] {
position: relative;
}
<a href="example.com" data-title="My site"> Link </a> with styled tooltip<br/>
<a href="example.com" title="My site"> Link </a> with normal tooltip
edited Nov 16 '18 at 22:45
answered Mar 20 '18 at 23:28
MakyenMakyen
21k84378
21k84378
This may not the answer to the question, but this is the best solution so far. Thanks.
– JJ Labajo
Nov 16 '18 at 15:44
@JJLabajo Thanks for the complement about this being the best solution so far. However, I'm not sure how this doesn't answer the question. The question is asking for something that's just not possible. This answer says it's not possible, but offers an alternative that accomplishes something similar to what the OP desires.
– Makyen
Dec 26 '18 at 14:38
add a comment |
This may not the answer to the question, but this is the best solution so far. Thanks.
– JJ Labajo
Nov 16 '18 at 15:44
@JJLabajo Thanks for the complement about this being the best solution so far. However, I'm not sure how this doesn't answer the question. The question is asking for something that's just not possible. This answer says it's not possible, but offers an alternative that accomplishes something similar to what the OP desires.
– Makyen
Dec 26 '18 at 14:38
This may not the answer to the question, but this is the best solution so far. Thanks.
– JJ Labajo
Nov 16 '18 at 15:44
This may not the answer to the question, but this is the best solution so far. Thanks.
– JJ Labajo
Nov 16 '18 at 15:44
@JJLabajo Thanks for the complement about this being the best solution so far. However, I'm not sure how this doesn't answer the question. The question is asking for something that's just not possible. This answer says it's not possible, but offers an alternative that accomplishes something similar to what the OP desires.
– Makyen
Dec 26 '18 at 14:38
@JJLabajo Thanks for the complement about this being the best solution so far. However, I'm not sure how this doesn't answer the question. The question is asking for something that's just not possible. This answer says it's not possible, but offers an alternative that accomplishes something similar to what the OP desires.
– Makyen
Dec 26 '18 at 14:38
add a comment |
I thought i'd post my 20 lines JavaScript solution here. It is not perfect, but may be useful for some depending on what you need from your tooltips.
When to use it
- Automatically styles the tooltip for all HTML elements with a
TITLE
attribute defined (this includes elements dynamically added to the document in the future) - No Javascript/HTML changes or hacks required for every tooltip (just the
TITLE
attribute, semantically clear) - Very light (adds about 300 bytes gzipped and minified)
- You want only a very basic styleable tooltip
When NOT to use
- Requires jQuery, so do not use if you don't use jQuery
- Bad support for nested elements that both have tooltips
- You need more than one tooltip on the screen at the same time
- You need the tooltip to disappear after some time
The code
// Use a closure to keep vars out of global scope
(function () {
var ID = "tooltip", CLS_ON = "tooltip_ON", FOLLOW = true,
DATA = "_tooltip", OFFSET_X = 20, OFFSET_Y = 10,
showAt = function (e) {
var ntop = e.pageY + OFFSET_Y, nleft = e.pageX + OFFSET_X;
$("#" + ID).html($(e.target).data(DATA)).css({
position: "absolute", top: ntop, left: nleft
}).show();
};
$(document).on("mouseenter", "*[title]", function (e) {
$(this).data(DATA, $(this).attr("title"));
$(this).removeAttr("title").addClass(CLS_ON);
$("<div id='" + ID + "' />").appendTo("body");
showAt(e);
});
$(document).on("mouseleave", "." + CLS_ON, function (e) {
$(this).attr("title", $(this).data(DATA)).removeClass(CLS_ON);
$("#" + ID).remove();
});
if (FOLLOW) { $(document).on("mousemove", "." + CLS_ON, showAt); }
}());
Paste it anywhere, it should work even when you run this code before the DOM is ready (it just won't show your tooltips until DOM is ready).
Customize
You can change the var
declarations on the second line to customize it a bit.
var ID = "tooltip"; // The ID of the styleable tooltip
var CLS_ON = "tooltip_ON"; // Does not matter, make it somewhat unique
var FOLLOW = true; // TRUE to enable mouse following, FALSE to have static tooltips
var DATA = "_tooltip"; // Does not matter, make it somewhat unique
var OFFSET_X = 20, OFFSET_Y = 10; // Tooltip's distance to the cursor
Style
You can now style your tooltips using the following CSS:
#tooltip {
background: #fff;
border: 1px solid red;
padding: 3px 10px;
}
2
Works great! Fix for a minor bug (if title is empty) can be found here: stackoverflow.com/questions/26702472/…
– Malasorte
Nov 2 '14 at 18:10
If you move rapidly over an element I am getting an empty tooltip, even with the bug fix mentioned above. This is erratic and stops if I take off the $(this).removeAttr("title"). But of course I then get the standard help showing after a while.
– Allen Conquest
Oct 25 '17 at 9:47
add a comment |
I thought i'd post my 20 lines JavaScript solution here. It is not perfect, but may be useful for some depending on what you need from your tooltips.
When to use it
- Automatically styles the tooltip for all HTML elements with a
TITLE
attribute defined (this includes elements dynamically added to the document in the future) - No Javascript/HTML changes or hacks required for every tooltip (just the
TITLE
attribute, semantically clear) - Very light (adds about 300 bytes gzipped and minified)
- You want only a very basic styleable tooltip
When NOT to use
- Requires jQuery, so do not use if you don't use jQuery
- Bad support for nested elements that both have tooltips
- You need more than one tooltip on the screen at the same time
- You need the tooltip to disappear after some time
The code
// Use a closure to keep vars out of global scope
(function () {
var ID = "tooltip", CLS_ON = "tooltip_ON", FOLLOW = true,
DATA = "_tooltip", OFFSET_X = 20, OFFSET_Y = 10,
showAt = function (e) {
var ntop = e.pageY + OFFSET_Y, nleft = e.pageX + OFFSET_X;
$("#" + ID).html($(e.target).data(DATA)).css({
position: "absolute", top: ntop, left: nleft
}).show();
};
$(document).on("mouseenter", "*[title]", function (e) {
$(this).data(DATA, $(this).attr("title"));
$(this).removeAttr("title").addClass(CLS_ON);
$("<div id='" + ID + "' />").appendTo("body");
showAt(e);
});
$(document).on("mouseleave", "." + CLS_ON, function (e) {
$(this).attr("title", $(this).data(DATA)).removeClass(CLS_ON);
$("#" + ID).remove();
});
if (FOLLOW) { $(document).on("mousemove", "." + CLS_ON, showAt); }
}());
Paste it anywhere, it should work even when you run this code before the DOM is ready (it just won't show your tooltips until DOM is ready).
Customize
You can change the var
declarations on the second line to customize it a bit.
var ID = "tooltip"; // The ID of the styleable tooltip
var CLS_ON = "tooltip_ON"; // Does not matter, make it somewhat unique
var FOLLOW = true; // TRUE to enable mouse following, FALSE to have static tooltips
var DATA = "_tooltip"; // Does not matter, make it somewhat unique
var OFFSET_X = 20, OFFSET_Y = 10; // Tooltip's distance to the cursor
Style
You can now style your tooltips using the following CSS:
#tooltip {
background: #fff;
border: 1px solid red;
padding: 3px 10px;
}
2
Works great! Fix for a minor bug (if title is empty) can be found here: stackoverflow.com/questions/26702472/…
– Malasorte
Nov 2 '14 at 18:10
If you move rapidly over an element I am getting an empty tooltip, even with the bug fix mentioned above. This is erratic and stops if I take off the $(this).removeAttr("title"). But of course I then get the standard help showing after a while.
– Allen Conquest
Oct 25 '17 at 9:47
add a comment |
I thought i'd post my 20 lines JavaScript solution here. It is not perfect, but may be useful for some depending on what you need from your tooltips.
When to use it
- Automatically styles the tooltip for all HTML elements with a
TITLE
attribute defined (this includes elements dynamically added to the document in the future) - No Javascript/HTML changes or hacks required for every tooltip (just the
TITLE
attribute, semantically clear) - Very light (adds about 300 bytes gzipped and minified)
- You want only a very basic styleable tooltip
When NOT to use
- Requires jQuery, so do not use if you don't use jQuery
- Bad support for nested elements that both have tooltips
- You need more than one tooltip on the screen at the same time
- You need the tooltip to disappear after some time
The code
// Use a closure to keep vars out of global scope
(function () {
var ID = "tooltip", CLS_ON = "tooltip_ON", FOLLOW = true,
DATA = "_tooltip", OFFSET_X = 20, OFFSET_Y = 10,
showAt = function (e) {
var ntop = e.pageY + OFFSET_Y, nleft = e.pageX + OFFSET_X;
$("#" + ID).html($(e.target).data(DATA)).css({
position: "absolute", top: ntop, left: nleft
}).show();
};
$(document).on("mouseenter", "*[title]", function (e) {
$(this).data(DATA, $(this).attr("title"));
$(this).removeAttr("title").addClass(CLS_ON);
$("<div id='" + ID + "' />").appendTo("body");
showAt(e);
});
$(document).on("mouseleave", "." + CLS_ON, function (e) {
$(this).attr("title", $(this).data(DATA)).removeClass(CLS_ON);
$("#" + ID).remove();
});
if (FOLLOW) { $(document).on("mousemove", "." + CLS_ON, showAt); }
}());
Paste it anywhere, it should work even when you run this code before the DOM is ready (it just won't show your tooltips until DOM is ready).
Customize
You can change the var
declarations on the second line to customize it a bit.
var ID = "tooltip"; // The ID of the styleable tooltip
var CLS_ON = "tooltip_ON"; // Does not matter, make it somewhat unique
var FOLLOW = true; // TRUE to enable mouse following, FALSE to have static tooltips
var DATA = "_tooltip"; // Does not matter, make it somewhat unique
var OFFSET_X = 20, OFFSET_Y = 10; // Tooltip's distance to the cursor
Style
You can now style your tooltips using the following CSS:
#tooltip {
background: #fff;
border: 1px solid red;
padding: 3px 10px;
}
I thought i'd post my 20 lines JavaScript solution here. It is not perfect, but may be useful for some depending on what you need from your tooltips.
When to use it
- Automatically styles the tooltip for all HTML elements with a
TITLE
attribute defined (this includes elements dynamically added to the document in the future) - No Javascript/HTML changes or hacks required for every tooltip (just the
TITLE
attribute, semantically clear) - Very light (adds about 300 bytes gzipped and minified)
- You want only a very basic styleable tooltip
When NOT to use
- Requires jQuery, so do not use if you don't use jQuery
- Bad support for nested elements that both have tooltips
- You need more than one tooltip on the screen at the same time
- You need the tooltip to disappear after some time
The code
// Use a closure to keep vars out of global scope
(function () {
var ID = "tooltip", CLS_ON = "tooltip_ON", FOLLOW = true,
DATA = "_tooltip", OFFSET_X = 20, OFFSET_Y = 10,
showAt = function (e) {
var ntop = e.pageY + OFFSET_Y, nleft = e.pageX + OFFSET_X;
$("#" + ID).html($(e.target).data(DATA)).css({
position: "absolute", top: ntop, left: nleft
}).show();
};
$(document).on("mouseenter", "*[title]", function (e) {
$(this).data(DATA, $(this).attr("title"));
$(this).removeAttr("title").addClass(CLS_ON);
$("<div id='" + ID + "' />").appendTo("body");
showAt(e);
});
$(document).on("mouseleave", "." + CLS_ON, function (e) {
$(this).attr("title", $(this).data(DATA)).removeClass(CLS_ON);
$("#" + ID).remove();
});
if (FOLLOW) { $(document).on("mousemove", "." + CLS_ON, showAt); }
}());
Paste it anywhere, it should work even when you run this code before the DOM is ready (it just won't show your tooltips until DOM is ready).
Customize
You can change the var
declarations on the second line to customize it a bit.
var ID = "tooltip"; // The ID of the styleable tooltip
var CLS_ON = "tooltip_ON"; // Does not matter, make it somewhat unique
var FOLLOW = true; // TRUE to enable mouse following, FALSE to have static tooltips
var DATA = "_tooltip"; // Does not matter, make it somewhat unique
var OFFSET_X = 20, OFFSET_Y = 10; // Tooltip's distance to the cursor
Style
You can now style your tooltips using the following CSS:
#tooltip {
background: #fff;
border: 1px solid red;
padding: 3px 10px;
}
answered May 9 '13 at 13:11
ChrisFChrisF
70979
70979
2
Works great! Fix for a minor bug (if title is empty) can be found here: stackoverflow.com/questions/26702472/…
– Malasorte
Nov 2 '14 at 18:10
If you move rapidly over an element I am getting an empty tooltip, even with the bug fix mentioned above. This is erratic and stops if I take off the $(this).removeAttr("title"). But of course I then get the standard help showing after a while.
– Allen Conquest
Oct 25 '17 at 9:47
add a comment |
2
Works great! Fix for a minor bug (if title is empty) can be found here: stackoverflow.com/questions/26702472/…
– Malasorte
Nov 2 '14 at 18:10
If you move rapidly over an element I am getting an empty tooltip, even with the bug fix mentioned above. This is erratic and stops if I take off the $(this).removeAttr("title"). But of course I then get the standard help showing after a while.
– Allen Conquest
Oct 25 '17 at 9:47
2
2
Works great! Fix for a minor bug (if title is empty) can be found here: stackoverflow.com/questions/26702472/…
– Malasorte
Nov 2 '14 at 18:10
Works great! Fix for a minor bug (if title is empty) can be found here: stackoverflow.com/questions/26702472/…
– Malasorte
Nov 2 '14 at 18:10
If you move rapidly over an element I am getting an empty tooltip, even with the bug fix mentioned above. This is erratic and stops if I take off the $(this).removeAttr("title"). But of course I then get the standard help showing after a while.
– Allen Conquest
Oct 25 '17 at 9:47
If you move rapidly over an element I am getting an empty tooltip, even with the bug fix mentioned above. This is erratic and stops if I take off the $(this).removeAttr("title"). But of course I then get the standard help showing after a while.
– Allen Conquest
Oct 25 '17 at 9:47
add a comment |
A jsfiddle for custom tooltip pattern is Here
It is based on CSS Positioning and pseduo class selectors
Check MDN docs for cross-browser support of pseudo classes
<!-- HTML -->
<p>
<a href="http://www.google.com/" class="tooltip">
I am a
<span> (This website rocks) </span></a> a developer.
</p>
/*CSS*/
a.tooltip {
position: relative;
}
a.tooltip span {
display: none;
}
a.tooltip:hover span, a.tooltip:focus span {
display:block;
position:absolute;
top:1em;
left:1.5em;
padding: 0.2em 0.6em;
border:1px solid #996633;
background-color:#FFFF66;
color:#000;
}
add a comment |
A jsfiddle for custom tooltip pattern is Here
It is based on CSS Positioning and pseduo class selectors
Check MDN docs for cross-browser support of pseudo classes
<!-- HTML -->
<p>
<a href="http://www.google.com/" class="tooltip">
I am a
<span> (This website rocks) </span></a> a developer.
</p>
/*CSS*/
a.tooltip {
position: relative;
}
a.tooltip span {
display: none;
}
a.tooltip:hover span, a.tooltip:focus span {
display:block;
position:absolute;
top:1em;
left:1.5em;
padding: 0.2em 0.6em;
border:1px solid #996633;
background-color:#FFFF66;
color:#000;
}
add a comment |
A jsfiddle for custom tooltip pattern is Here
It is based on CSS Positioning and pseduo class selectors
Check MDN docs for cross-browser support of pseudo classes
<!-- HTML -->
<p>
<a href="http://www.google.com/" class="tooltip">
I am a
<span> (This website rocks) </span></a> a developer.
</p>
/*CSS*/
a.tooltip {
position: relative;
}
a.tooltip span {
display: none;
}
a.tooltip:hover span, a.tooltip:focus span {
display:block;
position:absolute;
top:1em;
left:1.5em;
padding: 0.2em 0.6em;
border:1px solid #996633;
background-color:#FFFF66;
color:#000;
}
A jsfiddle for custom tooltip pattern is Here
It is based on CSS Positioning and pseduo class selectors
Check MDN docs for cross-browser support of pseudo classes
<!-- HTML -->
<p>
<a href="http://www.google.com/" class="tooltip">
I am a
<span> (This website rocks) </span></a> a developer.
</p>
/*CSS*/
a.tooltip {
position: relative;
}
a.tooltip span {
display: none;
}
a.tooltip:hover span, a.tooltip:focus span {
display:block;
position:absolute;
top:1em;
left:1.5em;
padding: 0.2em 0.6em;
border:1px solid #996633;
background-color:#FFFF66;
color:#000;
}
answered Jun 13 '13 at 5:22
prasunprasun
4,95672750
4,95672750
add a comment |
add a comment |
I have found the answer here: http://www.webdesignerdepot.com/2012/11/how-to-create-a-simple-css3-tooltip/
my own code goes like this, I have changed the attribute name, if you maintain the title name for the attribute you end up having two popups for the same text, another change is that my text on hovering displays underneath the exposed text.
.tags {
display: inline;
position: relative;
}
.tags:hover:after {
background: #333;
background: rgba(0, 0, 0, .8);
border-radius: 5px;
bottom: -34px;
color: #fff;
content: attr(glose);
left: 20%;
padding: 5px 15px;
position: absolute;
z-index: 98;
width: 350px;
}
.tags:hover:before {
border: solid;
border-color: #333 transparent;
border-width: 0 6px 6px 6px;
bottom: -4px;
content: "";
left: 50%;
position: absolute;
z-index: 99;
}
<a class="tags" glose="Text shown on hovering">Exposed text</a>
add a comment |
I have found the answer here: http://www.webdesignerdepot.com/2012/11/how-to-create-a-simple-css3-tooltip/
my own code goes like this, I have changed the attribute name, if you maintain the title name for the attribute you end up having two popups for the same text, another change is that my text on hovering displays underneath the exposed text.
.tags {
display: inline;
position: relative;
}
.tags:hover:after {
background: #333;
background: rgba(0, 0, 0, .8);
border-radius: 5px;
bottom: -34px;
color: #fff;
content: attr(glose);
left: 20%;
padding: 5px 15px;
position: absolute;
z-index: 98;
width: 350px;
}
.tags:hover:before {
border: solid;
border-color: #333 transparent;
border-width: 0 6px 6px 6px;
bottom: -4px;
content: "";
left: 50%;
position: absolute;
z-index: 99;
}
<a class="tags" glose="Text shown on hovering">Exposed text</a>
add a comment |
I have found the answer here: http://www.webdesignerdepot.com/2012/11/how-to-create-a-simple-css3-tooltip/
my own code goes like this, I have changed the attribute name, if you maintain the title name for the attribute you end up having two popups for the same text, another change is that my text on hovering displays underneath the exposed text.
.tags {
display: inline;
position: relative;
}
.tags:hover:after {
background: #333;
background: rgba(0, 0, 0, .8);
border-radius: 5px;
bottom: -34px;
color: #fff;
content: attr(glose);
left: 20%;
padding: 5px 15px;
position: absolute;
z-index: 98;
width: 350px;
}
.tags:hover:before {
border: solid;
border-color: #333 transparent;
border-width: 0 6px 6px 6px;
bottom: -4px;
content: "";
left: 50%;
position: absolute;
z-index: 99;
}
<a class="tags" glose="Text shown on hovering">Exposed text</a>
I have found the answer here: http://www.webdesignerdepot.com/2012/11/how-to-create-a-simple-css3-tooltip/
my own code goes like this, I have changed the attribute name, if you maintain the title name for the attribute you end up having two popups for the same text, another change is that my text on hovering displays underneath the exposed text.
.tags {
display: inline;
position: relative;
}
.tags:hover:after {
background: #333;
background: rgba(0, 0, 0, .8);
border-radius: 5px;
bottom: -34px;
color: #fff;
content: attr(glose);
left: 20%;
padding: 5px 15px;
position: absolute;
z-index: 98;
width: 350px;
}
.tags:hover:before {
border: solid;
border-color: #333 transparent;
border-width: 0 6px 6px 6px;
bottom: -4px;
content: "";
left: 50%;
position: absolute;
z-index: 99;
}
<a class="tags" glose="Text shown on hovering">Exposed text</a>
.tags {
display: inline;
position: relative;
}
.tags:hover:after {
background: #333;
background: rgba(0, 0, 0, .8);
border-radius: 5px;
bottom: -34px;
color: #fff;
content: attr(glose);
left: 20%;
padding: 5px 15px;
position: absolute;
z-index: 98;
width: 350px;
}
.tags:hover:before {
border: solid;
border-color: #333 transparent;
border-width: 0 6px 6px 6px;
bottom: -4px;
content: "";
left: 50%;
position: absolute;
z-index: 99;
}
<a class="tags" glose="Text shown on hovering">Exposed text</a>
.tags {
display: inline;
position: relative;
}
.tags:hover:after {
background: #333;
background: rgba(0, 0, 0, .8);
border-radius: 5px;
bottom: -34px;
color: #fff;
content: attr(glose);
left: 20%;
padding: 5px 15px;
position: absolute;
z-index: 98;
width: 350px;
}
.tags:hover:before {
border: solid;
border-color: #333 transparent;
border-width: 0 6px 6px 6px;
bottom: -4px;
content: "";
left: 50%;
position: absolute;
z-index: 99;
}
<a class="tags" glose="Text shown on hovering">Exposed text</a>
edited Oct 15 '18 at 5:56
Gerard
11.2k42040
11.2k42040
answered Jan 28 '16 at 19:02
Andrés ChandíaAndrés Chandía
384519
384519
add a comment |
add a comment |
Native tooltip cannot be styled.
That being said, you can use some library that would show styles floating layers when element is being hovered (instead of the native tooltips, and suppress them) requiring little or no code modifications...
I don’t think you can suppress the native tooltips if an element has atitle
attribute. So if you set up your own tooltip implementation, it is better to use some other attribute (say,data-tip
) instead oftitle
.
– Jukka K. Korpela
Mar 29 '12 at 16:08
1
you can, if after you attach to the event you clear title attribute
– poncha
Mar 30 '12 at 8:49
1
I see your point, but it’s not about styling native tooltips; it’s about avoiding them (by modifying the DOM).
– Jukka K. Korpela
Mar 30 '12 at 10:26
@JukkaK.Korpela yep, and i said in my first sentence that it was impossible ;)
– poncha
Mar 30 '12 at 11:19
The benefit of using the title attribute and clearing it later is that the tooltip is still available if the user has JavaScript disabled.
– JJJ
May 9 '13 at 11:54
|
show 1 more comment
Native tooltip cannot be styled.
That being said, you can use some library that would show styles floating layers when element is being hovered (instead of the native tooltips, and suppress them) requiring little or no code modifications...
I don’t think you can suppress the native tooltips if an element has atitle
attribute. So if you set up your own tooltip implementation, it is better to use some other attribute (say,data-tip
) instead oftitle
.
– Jukka K. Korpela
Mar 29 '12 at 16:08
1
you can, if after you attach to the event you clear title attribute
– poncha
Mar 30 '12 at 8:49
1
I see your point, but it’s not about styling native tooltips; it’s about avoiding them (by modifying the DOM).
– Jukka K. Korpela
Mar 30 '12 at 10:26
@JukkaK.Korpela yep, and i said in my first sentence that it was impossible ;)
– poncha
Mar 30 '12 at 11:19
The benefit of using the title attribute and clearing it later is that the tooltip is still available if the user has JavaScript disabled.
– JJJ
May 9 '13 at 11:54
|
show 1 more comment
Native tooltip cannot be styled.
That being said, you can use some library that would show styles floating layers when element is being hovered (instead of the native tooltips, and suppress them) requiring little or no code modifications...
Native tooltip cannot be styled.
That being said, you can use some library that would show styles floating layers when element is being hovered (instead of the native tooltips, and suppress them) requiring little or no code modifications...
answered Mar 29 '12 at 14:42
ponchaponcha
6,70212834
6,70212834
I don’t think you can suppress the native tooltips if an element has atitle
attribute. So if you set up your own tooltip implementation, it is better to use some other attribute (say,data-tip
) instead oftitle
.
– Jukka K. Korpela
Mar 29 '12 at 16:08
1
you can, if after you attach to the event you clear title attribute
– poncha
Mar 30 '12 at 8:49
1
I see your point, but it’s not about styling native tooltips; it’s about avoiding them (by modifying the DOM).
– Jukka K. Korpela
Mar 30 '12 at 10:26
@JukkaK.Korpela yep, and i said in my first sentence that it was impossible ;)
– poncha
Mar 30 '12 at 11:19
The benefit of using the title attribute and clearing it later is that the tooltip is still available if the user has JavaScript disabled.
– JJJ
May 9 '13 at 11:54
|
show 1 more comment
I don’t think you can suppress the native tooltips if an element has atitle
attribute. So if you set up your own tooltip implementation, it is better to use some other attribute (say,data-tip
) instead oftitle
.
– Jukka K. Korpela
Mar 29 '12 at 16:08
1
you can, if after you attach to the event you clear title attribute
– poncha
Mar 30 '12 at 8:49
1
I see your point, but it’s not about styling native tooltips; it’s about avoiding them (by modifying the DOM).
– Jukka K. Korpela
Mar 30 '12 at 10:26
@JukkaK.Korpela yep, and i said in my first sentence that it was impossible ;)
– poncha
Mar 30 '12 at 11:19
The benefit of using the title attribute and clearing it later is that the tooltip is still available if the user has JavaScript disabled.
– JJJ
May 9 '13 at 11:54
I don’t think you can suppress the native tooltips if an element has a
title
attribute. So if you set up your own tooltip implementation, it is better to use some other attribute (say, data-tip
) instead of title
.– Jukka K. Korpela
Mar 29 '12 at 16:08
I don’t think you can suppress the native tooltips if an element has a
title
attribute. So if you set up your own tooltip implementation, it is better to use some other attribute (say, data-tip
) instead of title
.– Jukka K. Korpela
Mar 29 '12 at 16:08
1
1
you can, if after you attach to the event you clear title attribute
– poncha
Mar 30 '12 at 8:49
you can, if after you attach to the event you clear title attribute
– poncha
Mar 30 '12 at 8:49
1
1
I see your point, but it’s not about styling native tooltips; it’s about avoiding them (by modifying the DOM).
– Jukka K. Korpela
Mar 30 '12 at 10:26
I see your point, but it’s not about styling native tooltips; it’s about avoiding them (by modifying the DOM).
– Jukka K. Korpela
Mar 30 '12 at 10:26
@JukkaK.Korpela yep, and i said in my first sentence that it was impossible ;)
– poncha
Mar 30 '12 at 11:19
@JukkaK.Korpela yep, and i said in my first sentence that it was impossible ;)
– poncha
Mar 30 '12 at 11:19
The benefit of using the title attribute and clearing it later is that the tooltip is still available if the user has JavaScript disabled.
– JJJ
May 9 '13 at 11:54
The benefit of using the title attribute and clearing it later is that the tooltip is still available if the user has JavaScript disabled.
– JJJ
May 9 '13 at 11:54
|
show 1 more comment
You cannot style the default browser tooltip. But you can use javascript to create your own custom HTML tooltips.
add a comment |
You cannot style the default browser tooltip. But you can use javascript to create your own custom HTML tooltips.
add a comment |
You cannot style the default browser tooltip. But you can use javascript to create your own custom HTML tooltips.
You cannot style the default browser tooltip. But you can use javascript to create your own custom HTML tooltips.
answered Mar 29 '12 at 14:42
bfavarettobfavaretto
64.1k1488133
64.1k1488133
add a comment |
add a comment |
a[title="My site"] {
color: red;
}
This also works with any attribute you want to add for instance:
HTML
<div class="my_class" anything="whatever">My Stuff</div>
CSS
.my_class[anything="whatever"] {
color: red;
}
See it work at: http://jsfiddle.net/vpYWE/1/
13
That styles an element with the specified title; not the tooltip title that the browser displays
– Rowland Shaw
Nov 29 '13 at 12:58
1
Also,anything
isn’t a valid HTML attribute. For custom attributes usedata-
attributes.
– Sebastian Simon
Jun 6 '16 at 10:39
add a comment |
a[title="My site"] {
color: red;
}
This also works with any attribute you want to add for instance:
HTML
<div class="my_class" anything="whatever">My Stuff</div>
CSS
.my_class[anything="whatever"] {
color: red;
}
See it work at: http://jsfiddle.net/vpYWE/1/
13
That styles an element with the specified title; not the tooltip title that the browser displays
– Rowland Shaw
Nov 29 '13 at 12:58
1
Also,anything
isn’t a valid HTML attribute. For custom attributes usedata-
attributes.
– Sebastian Simon
Jun 6 '16 at 10:39
add a comment |
a[title="My site"] {
color: red;
}
This also works with any attribute you want to add for instance:
HTML
<div class="my_class" anything="whatever">My Stuff</div>
CSS
.my_class[anything="whatever"] {
color: red;
}
See it work at: http://jsfiddle.net/vpYWE/1/
a[title="My site"] {
color: red;
}
This also works with any attribute you want to add for instance:
HTML
<div class="my_class" anything="whatever">My Stuff</div>
CSS
.my_class[anything="whatever"] {
color: red;
}
See it work at: http://jsfiddle.net/vpYWE/1/
answered Aug 13 '12 at 1:23
shana.shana.
9712
9712
13
That styles an element with the specified title; not the tooltip title that the browser displays
– Rowland Shaw
Nov 29 '13 at 12:58
1
Also,anything
isn’t a valid HTML attribute. For custom attributes usedata-
attributes.
– Sebastian Simon
Jun 6 '16 at 10:39
add a comment |
13
That styles an element with the specified title; not the tooltip title that the browser displays
– Rowland Shaw
Nov 29 '13 at 12:58
1
Also,anything
isn’t a valid HTML attribute. For custom attributes usedata-
attributes.
– Sebastian Simon
Jun 6 '16 at 10:39
13
13
That styles an element with the specified title; not the tooltip title that the browser displays
– Rowland Shaw
Nov 29 '13 at 12:58
That styles an element with the specified title; not the tooltip title that the browser displays
– Rowland Shaw
Nov 29 '13 at 12:58
1
1
Also,
anything
isn’t a valid HTML attribute. For custom attributes use data-
attributes.– Sebastian Simon
Jun 6 '16 at 10:39
Also,
anything
isn’t a valid HTML attribute. For custom attributes use data-
attributes.– Sebastian Simon
Jun 6 '16 at 10:39
add a comment |
protected by Community♦ Apr 21 '13 at 10:11
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
stackoverflow.com/questions/36275678/how-to-create-a-tooltip
– Pooja Kedar
Mar 16 '17 at 5:28