How to use HTML in a CSS-only tooltip - html

I have a CSS-only tooltip that uses a special element attribute to provide the content:
<li class="privTooltip" data-tooltip="My tooltip text">
Which is then handled in CSS:
<style>
[data-tooltip]:after {
content: attr(data-tooltip);
...styling...
}
</style>
But this only supports raw text. If I try to provide any HTML tags, like data-tooltip="<b>Granted through role paths</b>...more stuff", they aren't interpreted:
Text decoration, maybe a simple HTML table, etc.. would make these a lot nicer. I know I can write a DOM-based tooltip that does just about anything, but I'd like to know if it's possible with this lighter-weight pseudo-element CSS-only method.

This solution doesn't use your exact method, but it is CSS-only, which it sounds like is the important part for your use-case. You could try something like this, which allows you to style the tooltip's content with CSS.
EDIT: here's a live version of this in CodePen
HTML
<div class="tooltip">
<!-- put the content you want to hover over here -->
<img style="width: 40px; padding: 16px;" src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e4/Infobox_info_icon.svg/1200px-Infobox_info_icon.svg.png">
<span class="tooltiptext">
<!-- put the tooltip here -->
<strong>Title 1:</strong> Lorem ipsum.<br><br>
<strong>Title 2:</strong> Lorem ipsum.<br><br>
<strong>Title 3:</strong> Lorem ipsum.<br><br>
<strong>Title 4:</strong> Lorem ipsum.
</span>
</div>
CSS
.tooltip {
position: relative;
display: inline-block;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 200px;
background-color: #fff;
color: #000;
text-align: left;
border-radius: 4px;
border: 1px solid #d0d0d0;
padding: 8px;
/* Position the tooltip */
position: absolute;
z-index: 1;
}
.tooltip:hover .tooltiptext {
visibility: visible;
}

Related

linkable image with a mouseover text

I wanted to make this linkable image to have a text in a pop up box (not the type of pop up that is on w3schools, I want a classic yellowish box) when I mouseover. I tried to do it like this
<div class="folder1">
<a href="yourlinkhere" target="_self" >
<img src="https://78.media.tumblr.com/c00202bad8ae39931e34a7efa861d18b/tumblr_p70bjja6xI1x5vw3ao1_500.png" height="46" width="57"
title="This is some text I want to display." </a>
</div>
Opening the page in the link works great but there is no pop up box when I hover on it. Any help?
Currently, you are setting the title attribute to get a tooltip type hint when the element is hovered over. If this is what you are looking to do but perhaps just style the textbox to be, say, yellow, I would suggest using the following:
a {
color: #900;
text-decoration: none;
}
a:hover {
color: red;
position: relative;
}
a[data]:hover:after {
content: attr(data);
padding: 4px 8px;
color: rgba(0,0,0,0.5);
position: absolute;
left: 0;
top: 100%;
white-space: nowrap;
z-index: 2;
border-radius: 5px ;
background: rgba(0,0,0,0.5); /*Change this to yellow, or whatever background color you desire*/
}
<a data="This is the CSS tooltip showing up when you mouse over the link"href="#" class="tip">Link</a>
The above code was provided by Peeyush Kushwaha in this post. Simply change the anchor tag to your image tag, and apply styles as you see fit.
If by 'popup' you are looking for an alert to the user that requires interaction to close, you can use window.alert('text') in javascript in conjunction with the onmouseover event handler.
<img src="some_image.png" height="46px" width="57px" onmouseover="window.alert('Some Message')"/>
Otherwise, if you are looking for another element to be displayed upon mouseover of the image, you can use a bit of javascript to display a div or paragraph (really anything) upon mouseover of the img.
function showDiv() {
document.getElementById('popupBox').style.display = 'block';
}
#popupBox {
display: none;
}
<img src="some_image.png" width="41px" height="57px" onmouseover="showDiv()"/>
<div id="popupBox">Some Popup Text</div>
You can do this simply with CSS, or you can use one of many simple 'tooltip' JavaScript options. Bootstrap for example has this tooltip functionality built-in, ready to use. If you want something basic, here's a simple CSS-only approach that you can customise to your needs:
<!-- padding added here so you can see the pop-up above the folder, not necessary in-page -->
<div class="folder1" style="padding: 200px;">
<a href="yourlinkhere" target="_self" class="popper">
<img src="https://78.media.tumblr.com/c00202bad8ae39931e34a7efa861d18b/tumblr_p70bjja6xI1x5vw3ao1_500.png" height="46" width="57" />
<span class="pop-up">This is some text I want to display.</span>
</a>
</div>
<style>
a.popper {
display: inline-block;
position: relative;
}
.pop-up {
display: none;
position: absolute;
left: 0;
bottom: 100%;
padding: 1rem 1.5rem;
background: yellow;
color: black;
}
a.popper:hover .pop-up,
a.popper:focus .pop-up {
display: block;
}
</style>
Basically, you position the a tag relatively so that it can have absolutely positioned children, then relying on a:hover you show / hide the child using the child element's display property.
You can equally try this using css pseudo-element
a{
position: relative;
}
a:hover:after{
display:block;
content: "This is some text I want to display";
width: 200px;
background: yellow;
position: absolute;
top:0;
padding: 20px;
}
<div class="folder1" style="margin: 70px">
<a href="yourlinkhere" target="_self" class="">
<img src="https://78.media.tumblr.com/c00202bad8ae39931e34a7efa861d18b/tumblr_p70bjja6xI1x5vw3ao1_500.png" height="46" width="57"
</a>
</div>

Is there an HTML entity for an info icon?

I am looking for a basic information icon like this:
After some more searching, I myself have found the entity. The code for it is ⓘ, and it looks like this: ⓘ
There's 🛈 (U+1F6C8, CIRCLED INFORMATION SOURCE). As an HTML entity: 🛈.
There are plenty of tools, many online, that let you search for, and get more information about, Unicode characters. My personal favourite is this one.
this may help you ,
using html and css we can achieve this results
<!DOCTYPE html>
<html>
<style>
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
/* Position the tooltip */
position: absolute;
z-index: 1;
}
.tooltip:hover .tooltiptext {
visibility: visible;
}
</style>
<body style="text-align:center;">
<div class="tooltip">🛈
<span class="tooltiptext">Tooltip text</span>
</div>
</body>
</html>
UNICODE U+02139
HEX CODE ℹ
HTML CODE ℹ
CSS CODE \2139
// css example
span {
content: "\2139";
}
HTML Example
<span>ℹ</span>
Source
These days I use emoji for "info" ℹī¸ or "documentation" 📄 or "source" 📚
Previously, I would put the ⓘ inside superscript ⓘ because it reflects that it is a footnote to the text.
<sup>ⓘ</sup>
Also, consider the ☰ symbol over the 🛈 as it respects the baseline.
Use the unicode: ⓘ into the HTML.
HTML Code: ℹ
CSS Code: \2139
Use tailwind CSS (https://tailwindcss.com/) then the code below will create a nice info button.
<div class="flex items-center justify-center italic
text-stone-500 cursor-default w-5 h-5
rounded-full border border-gray-500 bg-green-100">
i
</div>

Add margin between ::before and element self, only if element self is displayed

I've been trying to solve this for a while. As an example, this code;
<span class="icon">save</span> lorem ipsum
<span class="icon"><span class="screenreader">edit</span></span> lorem ipsum
With a ::before I add an icon to the span. No problems there. Now I would like to add a margin between the icon and the 'label'. But only if there is a label displayed. For example, the 'edit' label is hidden and purely in the code for screenreaders.
An example says more than a thousand words;
http://codepen.io/anon/pen/jbWwbb
Notice how there's unwanted margin before lorem ipsum on the second line. How can I solve this without adding extra markup to the html?
Thanx!
You can simply add one space after pseudo-element content and remove margin-right. This will work because browser collapses multiple spaces and renders only one.
.icon:before {
content: '❤ '; /* space after heart will make a trick */
}
So it will render as expected in both cases.
.screenreader {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
.icon {
color: red;
}
.icon:before {
content: '❤ ';
}
<span class="icon">save</span> lorem ipsum
<br>
<span class="icon"><span class="screenreader">edit</span></span> lorem ipsum

Not-standard shaped input field

I need a text area field with an embedded button, like on this image:
__________________________________
|Lorep ipsum lorep ipsum lorep ipsu|
|m lorep ipsum lorep ipsum lorep ip|
|sum lorep ipsum lorep ip _________|
|sum lorep ipsum lorep ip| OK |
|________________________|_________|
The text should flow around the button, without being hidden under it.
The only option I could imagine is custom SVG component with text and user action handlers, but that seems to be a bit overkill.
Any suggestion on simple (may be not perfect) approach for this task?
I totally suck at this client-side stuff, but it seems to be possible with contenteditable.
.input {
width: 300px;
}
.submit {
border: 1px solid black;
float: right;
text-align: center;
padding: 10px;
cursor: pointer;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div class='input' contenteditable=true>
<div type='button' class='submit' contenteditable=false>Save</div>
The text should flow around the button, without being hidden under it.
The only option I could imagine is custom SVG component with text and user action handlers, but that seems to be a bit overkill.
Any suggestion on simple (may be not perfect) approach for this task?
</div>
</body>
</html>
It's not quite what you asked for, but maybe a different approach to take. I'm positioning the button at the bottom of a contenteditable div and only showing you it when you hover the lover section.
As i said, it's not a 'solution', more of a different approach of an issue.
.wrap {
position: relative;
}
.text {
height: 200px;
width: 400px;
background: rgba(0, 0, 0, 0.4);
overflow:auto;
}
.bot {
position: absolute;
bottom: 0;
height: 20px;
width: 400px;
padding-bottom: 5%;
}
button {
position: absolute;
height: 100%;
width: 100px;
right: 0;
transition: all 0.8s;
opacity: 0;
}
.bot:hover button {
opacity: 1;
}
<div class="wrap">
<div class="text" contenteditable="true">
You can type in me! hover my lower section and you'll see the button!
</div>
<div class="bot">
<button>OK</button>
</div>
</div>
Note
This 'solution' could be tidied up, as most css styling is for 'extra bits', like overflow and transitions.
This is not possible with a textarea. But you can do it contenteditable div.
<div contenteditable="true"></div>
jsFiddle
HTML
<div>
<textarea name="" id="txt" cols="30" rows="10"></textarea>
<button>OK</button>
</div>
CSS
div{
display:inline-block;
position:relative;
}
button{
position:absolute;
bottom:10px;
right:10px;
}
div{
display:inline-block;
position:relative;
}
button{
position:absolute;
bottom:10px;
right:10px;
}
<div>
<textarea name="" id="txt" cols="30" rows="10"></textarea>
<button>OK</button>
</div>

Tooltip on image

I am using the tooltip. But I want that on image tag, like when I mouseover the image then the tooltip should work. I have tried but not working for me on image tag.
You can use the standard HTML title attribute of image for this:
<img src="source of image" alt="alternative text" title="this will be displayed as a tooltip"/>
I am set Tooltips On My Working Project That Is 100% Working
<!DOCTYPE html>
<html>
<style>
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
/* Position the tooltip */
position: absolute;
z-index: 1;
}
.tooltip:hover .tooltiptext {
visibility: visible;
}
.size_of_img{
width:90px}
</style>
<body style="text-align:center;">
<p>Move the mouse over the text below:</p>
<div class="tooltip"><img class="size_of_img" src="https://babeltechreviews.com/wp-content/uploads/2018/07/rendition1.img_.jpg" alt="Image 1" /><span class="tooltiptext">grewon.pdf</span></div>
<p>Note that the position of the tooltip text isn't very good. Check More Position GO</p>
</body>
</html>
Using javascript, you can set tooltips for all the images on the page.
<!DOCTYPE html>
<html>
<body>
<img src="http://sushmareddy.byethost7.com/dist/img/buffet.png" alt="Food">
<img src="http://sushmareddy.byethost7.com/dist/img/uthappizza.png" alt="Pizza">
<script>
//image objects
var imageEls = document.getElementsByTagName("img");
//Iterating
for(var i=0;i<imageEls.length;i++){
imageEls[i].title=imageEls[i].alt;
//OR
//imageEls[i].title="Title of your choice";
}
</script>
</body>
</html>
You can use the following format to generate a tooltip for an image.
<div class="tooltip"><img src="joe.jpg" />
<span class="tooltiptext">Tooltip text</span>
</div>