I am trying to add a popup when hover on my text (span).
I'm trying to do it like they explain in W3schools:
https://www.w3schools.com/css/css_tooltip.asp
But I am already using style in my span to color the text that I want to hover, so if I add the class with the properties from w3schools to my span the text is gonna be hidden since they have visibility: hidden; in the span class.
I am very new to this, so I would be glad if someone could help me.
If you want to add color to the span text (My text) then add a color property to .tooltip class in the w3schools example
However if your goal is adding color to tooltip text then adjust the color property in .tooltip .tooltiptext{}
This is the same example from w3schools
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black;
/* color of the span text */
color: rgb(119, 162, 241);
}
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
/* color of the tooltip text */
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
}
.tooltip:hover .tooltiptext {
visibility: visible;
}
<div class="tooltip">Hover over me
<span class="tooltiptext">My text</span>
</div>
I'm also very new to HTML and CSS, but I'll try to answer, anyway.
You can try to nest spans...
Taking W3Schools' code as an example, it will look something like this:
.p {
text-align: left;
}
.firstSpan {
color: rgb(119, 162, 241)
}
.firstSpan .secondSpan {
visibility: hidden;
width: 120px;
background-color: gray;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
}
.firstSpan:hover .secondSpan {
visibility: visible;
}
<p>Let's try some 'nested' spans.</p>
<p>This is some text in a paragraph. You can hover <span class="firstSpan">over me<span class="secondSpan">Some text.</span></span> and you'll see some text.
</p>
<p>Another text in another paragraph. Hover <span class="firstSpan">over me<span class="secondSpan">A hint.</span></span> and you'll see some text — Maybe a hint.
</p>
Depending on what you want, nested spans may not be the best practice, but if what you're looking for is a simple inline container... go for it.
I hope I was helpful. 😉
Related
I wrote
"
Home<i class="fa fa-home" fa-3%>
"
But it does not work...
Plz answer my Quz--and if u can, show me the syntax example
Use title attribute
like title="Cat chattering ekekekek"
Tooltips are little boxes containing helpful text that appear when you hover over certain elements in a web page. They’re a useful UI component for providing additional information to users without having to clutter the interface. In this tutorial we’ll be creating a simple tooltip using HTML & CSS with no JavaScript required.
Following code is the example of how to add tooltip text.
<style>
/* Tooltip container */
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black; /* If you want dots under the hoverable text */
}
/* Tooltip text */
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
padding: 5px 0;
border-radius: 6px;
/* Position the tooltip text - see examples below! */
position: absolute;
z-index: 1;
}
/* Show the tooltip text when you mouse over the tooltip container */
.tooltip:hover .tooltiptext {
visibility: visible;
}
</style>
<div class="tooltip">Hover over me
<span class="tooltiptext">Tooltip text</span>
</div>
I hope you'll like this.
So I thought it'd be a great idea to add tooltips to my Neocities site, but I seem to have run into an issue I can't find the answer to...
Okay for some ungodly reason my tooltip class isn't working. I assigned my div the class, and the span inside it the tooltiptext class, but it would still just use what I had assigned the body. I only noticed this when the text was still white, when it should've been black, among other things.
Here's the html section:
<h1>please god ignore the background, I haven't found a good one yet</h1>
<img id="A wooden door framed with clip-art of flowers." style="position: relative;" src="images/flowerydoor.png" />
<div class="tooltip">
<p>this is literally copy+pasted from w3schools what the actual fuck-
<span class="tooltiptext">wait a minute this should have black text why isn't the class working</span></p>
</div>
I'm including the header and image parts because I'm desperate and worry the answer lies within one of the miniscule details
here's the stylesheet:
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: white;
color: black;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
}
.tooltip:hover .tooltiptext {
visibility: visible;
}
body {
background-color: #fbb291;
color: white;
font-family: Verdana;
}
Once again all copy+pasted from w3schools just to make sure it wasn't me
Like I said, the text of the tooltip-assigned div still has white text, and nothing from the tooltip class...
Either the body is overriding my class, or there's something going on with the class itself that's stopping it from working.
I don't know if this helps, but I have assigned a class to my body, which works perfectly fine. I'm wondering if there's something going on with it? I mean, it shouldn't, because I have another page using said class, along with divs using other classes that work perfectly fine!
.door {
margin: 0 auto;
background-image: url("https://64.media.tumblr.com/1adbeafb3ca992a7681ede48ddedcbbd/d5886a952040c00b-9b/s250x400/a917bb1772111a1460eac4922c0502e0ba860bd1.jpg");
/*position: relative;*/
width: 600px;
height: 900px;
text-align: center;
}
I apologize if I'm not making much sense, I'm not super familiar with certain html and css terms.
In this snippet based on your code, the tooltip text is black:
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: white;
color: black;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
}
.tooltip:hover .tooltiptext {
visibility: visible;
}
body {
background-color: #fbb291;
color: white;
font-family: Verdana;
}
<h1>please god ignore the background, I haven't found a good one yet</h1>
<img id="A wooden door framed with clip-art of flowers." style="position: relative;" src="images/flowerydoor.png" />
<div class="tooltip">
<p>this is literally copy+pasted from w3schools what the actual fuck-
<span class="tooltiptext">wait a minute this should have black text why isn't the class working</span></p>
</div>
If you're using other libraries with their own CSS or are deploying this on a third-party website, there could be a namespace collision. You can check what styles are applying to an HTML element using the Chrome DevTools or similar tools in other browsers. Here is a guide for doing this in Chrome: https://developer.chrome.com/docs/devtools/css/overrides/
The simplest way to disable <a> links is by custom CSS-class "disabled" which sets the pointer-events to none.
How ever title-Attributes where we would like to display the reason why the link is disabled as hover text wont work anymore...
See example below:
a.disabled,
a.disabled:visited {
pointer-events: none;
color: grey;
}
active Link with hover text
<br>
disabled link with hidden hover text
I see two possibility which are both not really elegant:
Wrapping the <a> and add title to parent. But this is an unnecessary wrapping element and may affect styling.
a.disabled,
a.disabled:visited {
pointer-events: none;
color: grey;
}
active Link
<br>
<span title="link is disabled because of...">
disabled link
</span>
Since we're using deactivated anchor tags mostly styled as a button, we could use <button> instead. But unfortunately onclick navigation on buttons can not be opened optionally in a separate windows like <a> do (via context menu or click on the middle mouse button). This could be added with additional Javascript but this would be a even worse solution...
a.disabled,
a.disabled:visited {
pointer-events: none;
color: grey;
}
<button href="#" title="link is clickable" onclick="location.href='http://www.google.com'">
active button
</button>
<br>
<button title="link is disabled because of..." onclick="location.href='http://www.google.com'" disabled>
disabled button
</button>
I even don't understand why there is no disabled-attribute for <a> in the html standard like buttons have...
Any ideas for a really proper solution to disabled anchor tags but still displaying title hover texts? It would be nice to find an CSS only solution or a similar approach.
You can use the title attribute with disabled links,
you have to modify your code this way:
a.disabled {
pointer-events: auto;
color: grey;
}
a.disabled:active {
pointer-events: none;
}
This is an exemple using the attribute title and a custom attribute named data-tooltip to show the tooltip text:
a.disabled {
pointer-events: auto;
color: grey;
}
a.disabled:active {
pointer-events: none;
}
/* Tooltip **/
[data-tooltip] {
position: relative;
z-index: 10;
}
[data-tooltip]::after {
pointer-events: auto;
background: #444;
border-radius: 0.25rem;
box-shadow: 0 1rem 2rem -0.5rem rgba(0, 0, 0, 0.25);
color: #fff;
content: attr(data-tooltip);
display: inline-block;
font-size: 0.75rem;
letter-spacing: 1px;
line-height: 1;
max-width: 11rem;
opacity: 0.8;
padding: 0.375rem 0.25rem;
position: absolute;
left: 50%;
bottom: calc(100% + 0.25rem);
text-align: center;
transform: translate(-10%, 0.25rem);
user-select: none;
-webkit-user-select: none;
vertical-align: middle;
visibility: hidden;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
z-index: 999;
}
[data-tooltip]:hover::after {
visibility: visible;
opacity: 0.8;
transform: translate(-50%, 0.125rem);
z-index: 9999 !important;
transition: opacity 200ms ease-in-out, transform 500ms ease-in-out;
}
<br>
<br>
active Link with hover text
<br>
disabled link with hidden hover text
If you're fine with using a little bit of Javascript, you could simply go like this:
document.addEventListener('click', function(event) {
if (event.target.matches('a.disabled'))
event.preventDefault();
})
a.disabled,
a.disabled:visited {
color: grey;
}
active Link with hover text
<br>
disabled link with hidden hover text
I would like to have a colored underline that looks like this when it breaks:
text-decoration-color seems to be not supported widely enough.
I tried this:
.underline {
position: relative;
}
.underline:after {
position: absolute;
content: '';
height: 1px;
background-color: #ffc04d;
bottom: .1rem;
right: 0;
left: 0;
z-index: -1;
}
<h1><span class="underline">Sprouted Bread</span></h1>
What about a linear-gradient where it will be easy to control color, size and distance within a single element:
.underline {
position: relative;
font-size:28px;
background:
linear-gradient(yellow,yellow) /* Color */
left 0 bottom 2px/ /* Position */
100% 2px /* Size (width height)*/
no-repeat;
}
<div style="width:150px;text-align:center"><span class="underline">Sprouted Bread</span></div>
As a side note, border-bottom works fine used with inline element but of course you cannot easily control the distance to make it behave as a text-decoration:
.underline {
position: relative;
font-size:28px;
border-bottom:2px solid yellow;
}
<div style="width:150px;text-align:center"><span class="underline">Sprouted Bread</span></div>
Try this JSFiddle
By wrapping the elements like you have in a span. You can put the text decoration on the parent element and the text color on the span.
HTML:
<h1><span class="underline">Some Text</span></h1>
CSS:
h1 {
text-decoration: underline;
color: red;
}
.underline {
color: blue;
}
Just add a border!
Using display: inline, add a bottom border and space it with padding.
You could also use line-height and then place negative margins to increase the space in between the lines.
And...you could also animate it!
.underline {
position: relative;
padding-bottom: 1px;
border-bottom: 1px solid #ffc04d;
}
<h1 style="width: 5em">
<span class="underline">Sprouted Bread</span>
</h1>
As mentioned by #chriskirknielsen, you could use box-decoration-break, although not supported by IE or Edge. Credits: #Temani Afif
Isn't opaque supposed to mean opaque??
In particular, I've been experimenting with tooltip boxes in HTML application coding. So far I have appropriated the following CSS code:
/* Begin Tooltip Tomfoolery */
.tooltip {
position: relative;
display: inline;
border-bottom: 2px solid magenta;
}
.tooltiptext {
color: magenta; background-color: yellow;
text-align: justify;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
border-radius: 6px;
padding: 5px 0 0 .25in;
/* Position the tooltip */
position: absolute;
top: 100%;
left: 200px;
margin-left: -60px;
}
.tooltip:hover .tooltip {
visibility: visible;
z-index: 0;
}
.tooltip:hover .tooltiptext {
visibility: visible; filter: alpha(opacity=100);
z-index: 1;
}
/* -End- Tooltip Tomfoolery */
My tooltip boxes come out okay, but when I hover my mouse over one tooltip label, the text from neighbouring tooltip labels keeps bleeding through the chosen label's tooltip text, sometimes making the requested tooltip all but illegible. Text outside of tooltip labeling appears to be covered adequately. I've formatted my tooltip label-text combinations as below:
<span class="tooltip"><em>Tooltip LABEL</em
><span class="tooltiptext">Tooltip TEXT</span></span>
exempli gratia:
<!-- earlier text --><span
class="tooltip"><em>Krigah! Tarzan Bundolo!</em><span
class="tooltiptext" style="left: 75px"
>Beware! The Albino Kills!
(and he ain't swingin' from no
consarned rubber BAND neither!)</span></span><!-- later text -->
(Aside: I don't know if your system allows tags to be split before the closing angle, but mine seems not to complain—plus it does allow me to control my line lengths for better source-code legibility.) I tried playing with opacity and other field properties, but I think I've pretty much run out of options. Any help you can provide will be deeply appreciated.