Hover affect of tooltip also underlines text of content in span - html

Edited:
I have a tooltip icon that when you hover over it brings up a box with information which is fine. However, I also want this to underline text inside the contents of a span tag but I can't seem to apply the css to do both I can only seem to get it to do one or the other.
Below is the code for the tooltip icon:
SCSS
.tooltip-region {
text-align: center;
background-color: blue;
border-radius: 50%;
width: 24px;
height: 24px;
font-size: 14px;
line-height: 26px;
cursor: default;
z-index: 8;
margin-left: 10px;
margin-top: 5px;
}
.tooltip-region::before {
content: '?';
font-weight: bold;
color: #fff;
}
.tooltip-region:hover p{
display: block;
transform-origin: 100% 100%;
-webkit-animation: fadeIn 0.3s ease-in-out;
animation: fadeIn 0.3s ease-in-out;
}
.tooltip-region p{
display: none;
text-align: left;
background-color: blue;
padding: 20px;
width: 200px;
position: relative;
border-radius: 3px;
box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2);
left: -4px;
color: #fff;
font-size: 13px;
line-height: 1.4;
font-size: 16px;
font-family: sans-serif;
}
.tooltip-region p::before {
position: absolute;
content: '';
width:0;
height: 0;
border:6px solid transparent;
border-bottom-color: blue;
left:10px;
top:-12px;
}
.tooltip-region p::after {
width:100%;
height:40px;
content:'';
position: relative;
top:-40px;
left:0;
}
html
<div class="grid-container">
<form action="#">
<div class="flexrow">
<div class="tooltip-region">
<p>Text</p>
</div>
</div>
</form>
</div>
The code for the span I want to highlight is this:
html
<div class="grid-item-2">
<pre id="terraCode">
region = "<span id="regionList" class="regionListUnderline"></span>"
</pre>
</div>
I have JavaScript code that autofills the content of the span which is why the code above has no text in it.
But the css I want to apply to the contents of the span when I hover over the tooltip is this:
SCSS
.regionListUnderline:hover {
border-bottom: 1px dotted black;
}
If anyone can see how I can apply the dotted line to the contents of the span when I hover over the tooltip icon would be very much appreciated!
Thanks

You can update the style via JavaScript. Therefore you would have to add this to your script (make sure that the dom content has loaded):
const handleMouseOver = () => {
const el = document.getElementById("regionList");
el.style.borderBottom = "1px dotted black";
};
const handleMouseLeave = () => {
const el = document.getElementById("regionList");
el.style.borderBottom = "none";
};
const [tooltip] = document.getElementsByClassName("tooltip-region");
tooltip.addEventListener("mouseover", handleMouseOver);
tooltip.addEventListener("mouseleave", handleMouseLeave);
This will only work if you have one element with the class tooltip-reqion because the code targets the first of occurance. If you have several this would need more logic.

Related

My html button cannot be clicked, even though I modified only its style

The code I have for my button in HTML is this simple
What causes the button to not be able to be clicked, even though it is of type button?
.menubutton {
background-color: orange;
color: black;
text-align: center;
font-size: 20px;
padding: 20px 50px;
}
<button class="menubutton" style="position:absolute;left:10%" type="button"><b>Home</b></button>
The button is able to be clicked, as demonstrated by the following event listener:
document.querySelector(".menubutton").addEventListener("click", (e) => {
console.log("button was clicked!");
})
.menubutton {
background-color: orange;
color: black;
text-align: center;
font-size: 20px;
padding: 20px 50px;
}
<button class="menubutton" style="position:absolute;left:10%" type="button"><b>Home</b></button>
You probably mean that the user can't tell it's a button. To improve this, add a hover effect and pointer cursor to the CSS:
document.querySelector(".menubutton").addEventListener("click", (e) => {
console.log("button was clicked!");
})
.menubutton {
background-color: orange;
color: black;
text-align: center;
font-size: 20px;
padding: 20px 50px;
/* 👇 pointer on hover */
cursor: pointer;
/* 👇 transition */
transition: 0.2s ease;
}
/* 👇 hover event */
.menubutton:hover {
background-color: lightgrey;
}
<button class="menubutton" style="position:absolute;left:10%" type="button"><b>Home</b></button>
Read more about hover effects here and transitions here.
I don't think you need to add type=button on a button element.
You should add all the styles in the element in the <style> tag.
Using these changes, you should have:
HTML
<button class="menubutton">
<b>Home</b>
</button>
CSS
<style>
.menubutton {
position: absolute;
left: 10%;
background-color: orange;
color: black;
text-align: center;
font-size: 20px;
padding: 20px 50px;
}
</style>

button:hover and cursor pointer not working?

The cursor: pointer and background-color change on hover are both not working on my buttons. I have tried the solutions i have seen to similar questions (swapped from a button tag to a anchor or div tag, changed the z-index) but none of them have helped. The rest of the styling is working fine so i don't understand why this is happening, please help.
.btn {
cursor: pointer;
position: relative;
display: inline-block;
width: 80px;
height: 30px;
background-color: #15181c;
border: none;
margin: auto 10px;
border-radius: 5px;
font-weight: bold;
color: white;
letter-spacing: 1.5px;
transition-duration: 0.3s;
padding: 5px 10px;
}
.btn:hover {
background-color: lightslategray;
}
.disabled {
opacity: 0.5;
}
<div class ="buttons">
<div class="btn">DEAL</div>
<div class="btn disabled">HIT</div>
<div class="btn disabled">STAND</div>
</div>
In case anyone else has this issue. I had a box shadow overlay to add a shadow on the background which was stopping the buttons from registering the mouse hover. Changing the button z-index to 100 didn't help, but when i changed the overlay index to -1 it solved the issue.
It's a bug on webkit browsers that doesn't allow you to see the hover effect.
You can do it in 2 ways: (You can do both)
Set the div.btn inside another div called for example div.btn-container and apply the hover to the parent element. This will surely work for you. (You can apply the hover to both of them)
Change the display: inline-block to display: inline. Inline sometimes causes some issues. (Sometimes)
.buttons {
display: flex
}
.btn {
position: relative;
/* SET THE DISPLAY TO INLINE-BLOCK */
display: inline;
width: 80px;
height: 30px;
background-color: #15181c;
border: none;
border-radius: 5px;
font-weight: bold;
color: white;
letter-spacing: 1.5px;
transition-duration: 0.3s;
padding: 5px 10px;
}
.btn-container {
margin: auto 10px
}
/* YOU CAN WRITE BOTH IN YOUR CSS FILE HERE */
.btn:hover {
cursor: pointer;
background-color: lightslategray;
}
.btn-container:hover btn {
background-color: lightslategray;
cursor: pointer;
border: 1px solid red
}
/* UNTIL HERE */
.disabled {
opacity: 0.5;
}
<div class="buttons">
<div class='btn-container'>
<div class="btn">DEAL</div>
</div>
<div class='btn-container'>
<div class="btn disabled">HIT</div>
</div>
<div class='btn-container'>
<div class="btn disabled">STAND</div>
</div>
</div>
The cursor: pointer and background-color change on hover are both not working on my buttons.
Is the code in the snippet the one you are using?
Since in the code snippet .btn:hover is working just fine?
Have you tried force-refreshing your browser.
Control + F5
You can also try running the page with a different browser.
Edit:
Based on the answers you have given to the other comments, I think it might be a system or browser bug. Here's a Jquery alternative if the pure css does not work in your system (if you are fine with using it).
.buttons {
display: flex
}
.btn {
position: relative;
display: inline;
width: 80px;
height: 30px;
background-color: #15181c;
border: none;
border-radius: 5px;
font-weight: bold;
color: white;
letter-spacing: 1.5px;
transition-duration: 0.3s;
padding: 5px 10px;
}
.disabled {
opacity: 0.5;
}
.btn:hover, .btn.jqHover {
background-color: lightslategray;
cursor: pointer;
border: 1px solid red
}
.activeElement {
background:#bfbfbf;
}
<div class="buttons">
<div class='btn-container'>
<div class="btn">DEAL</div>
</div>
<div class='btn-container'>
<div class="btn disabled">HIT</div>
</div>
<div class='btn-container'>
<div class="btn disabled">STAND</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function () {
var hoveredElement;
var clickedElement;
$(document).mousemove(function (event) {
hoveredElement=event.target.nodeName;
// comment this section in between to see issue
$(hoveredElement).mouseenter(function () {
$(this).addClass('jqHover');
}).mouseleave(function () {
$(this).removeClass('jqHover');
});
return hoveredElement;
});
$(document).click(function (event) {
clickedElement = event.target.nodeName;
return clickedElement;
});
});
</script>
Original Jquery answer by Sai

label doesn't display when hover

hi I want the label "hidden-btn-txt" display when hover
but It doesnt show at all when the mouse is on the label
i tried to do hover to the "hidden-btn" but it doesnt work
html in tsx:
return (<ul className='tickets'>*
{filteredTickets.map((ticket) => (<li key={ticket.id} className='ticket'>
<div className="hidden-btn" onClick={this.onHide.bind(this, ticket.id)} >
<label id="hidden-btn-txt">Hide</label>
</div>
<h5 className='title'>{ticket.title}</h5>
<p className='content'>{ticket.content}</p>
<footer>
<div className='meta-data'> <span> By {ticket.userEmail} | { new Date(ticket.creationTime).toLocaleString()}</span>
{ticket.labels ? this.renderLabels(ticket.labels): null}
</div>
</footer>
</li>))}
</ul>);
css:
.ticket {
width: 100%;
flex-shrink: 0;
border-radius: 8px;
background-color: #fff;
box-shadow: 0 2px 6px 1px #e1e5e8;
margin-bottom: 14px;
display: flex;
flex-direction: column;
border: 1px solid #fff;
padding: 10px 20px;
transition: box-shadow .2s ease-in-out;
position: relative;
&:hover {
box-shadow: 0 2px 6px 1px #d3d7da;
}
#hidden-btn-txt{
display: inline-block;
color: #20455e;
font-size: 12px;
font-style: normal;
text-align: right;
float: right;
}
#hidden-btn-txt.hover{
display: inline-block;
}
Using something like this should help your casue:
onHover = () => {
//Apply your classes here.
}
<label id="hidden-btn-txt" onMouseOver={this.onHover}>Hide</label>

Slide dropdown open

EDIT: I couldn't find any solution without JS so I implemented it with JavaScript (solution as answer).
I am trying to create a slide-open-dropdown without any JavaScript. I've googled a bit but could not find any solutions using either a fixed height, using a fixed max-height or well.. JavaScript.
What I've done:
My Elements are the same height as my container so I could just use 3 times the height but now I have another constant.
Code:
.dropdown_menu {
display: inline-block;
font-family: Arial;
position: relative;
}
.dropdown_title {
background-color: #505050;
color: white;
margin: 0;
padding: 20px 50px;
}
.dropdown_content {
background-color: #646464;
position: absolute;
width: 100%;
z-index: 1;
height: 0;
overflow: hidden;
transition: height .3s;
}
.dropdown_content > * {
color: white;
display: block;
padding: 20px 0;
text-align: center;
text-decoration: none;
}
.dropdown_content > *:hover {
background-color: #7D7D7D;
}
.dropdown_menu:hover .dropdown_content {
height: 300%;
}
<div class="dropdown_menu">
<p class="dropdown_title">Dropdown</p>
<div class="dropdown_content">
Option 1
Option 2
Option 3
</div>
</div>
Is it possible to create this?
Use max-height instead of height, and set the max height on hover to a very big one. Also note that the transition time is relative to the full maximum height so you'll have to set a longer transition time.
.dropdown_menu {
display: inline-block;
font-family: Arial;
position: relative;
}
.dropdown_title {
background-color: #505050;
color: white;
margin: 0;
padding: 20px 50px;
}
.dropdown_content {
background-color: #646464;
position: absolute;
width: 100%;
z-index: 1;
max-height: 0;
overflow: hidden;
transition: max-height 1s;
}
.dropdown_content > * {
color: white;
display: block;
padding: 20px 0;
text-align: center;
text-decoration: none;
}
.dropdown_content > *:hover {
background-color: #7D7D7D;
}
.dropdown_menu:hover .dropdown_content {
max-height: 1000px;
}
<div class="dropdown_menu">
<p class="dropdown_title">Dropdown</p>
<div class="dropdown_content">
Option 1
Option 2
Option 3
</div>
</div>
<div class="dropdown_menu">
<p class="dropdown_title">Dropdown</p>
<div class="dropdown_content">
Option 1
Option 2
Option 3
Option 4
Option 5
</div>
</div>
So I worked out a solution with JavaScript and will provide it for future use :)
Here is my code:
"use strict";
document.querySelectorAll('.aDropdown').forEach(dropdown => {
let body = dropdown.children[1];
let titleHeight = dropdown.children[0].clientHeight;
dropdown.style.height = titleHeight + "px";
// Mouse enter listener
dropdown.addEventListener('mouseenter', () => {
// Variables
let bodyHeight = 0;
let selectionAmount = body.children.length;
// Get the height of all children
for(let i = 0; i < selectionAmount; i++)
bodyHeight += body.children[i].clientHeight;
// Set the container to a certain height
dropdown.style.height = (titleHeight + bodyHeight) + "px";
});
// Mouse leave listener
dropdown.addEventListener('mouseleave', () => {
dropdown.style.height = titleHeight + "px";
});
});
body {
background-color: white;
font-family: Arial;
}
/* ABOVE THIS IS JUST PAGE STYLING */
.aDropdown {
background-color: rgb(255, 255, 255);
border-radius: 5px;
border: 1px solid rgb(165, 165, 165);
display: inline-block;
overflow: hidden;
position: relative;
transition: height .3s;
}
.aDropdown > .title {
margin: 0;
padding: 10px 20px;
}
.aDropdown > .body > * {
display: block;
text-decoration: none;
color: black;
text-align: center;
padding: 10px;
background-color: white;
transition: background-color .5s;
}
.aDropdown > .body > *:hover {
background-color: rgb(225, 225, 225);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="./index.css">
</head>
<body>
<div class="aDropdown">
<p class="title">DropDown</p>
<div class="body">
Item
Item
Item
</div>
</div>
<script src="./index.js"></script>
</body>
</html>

CSS hover table cell

I got a table and I would like to have different text boxes when hovering on cells.
<div class="plan">
<h2 class="title">Premium</h2>
<div align="center">
<p class="plan-price">499<span>€</span></p>
</div>
<ul class="plan-features">
<li><strong>Hello1</strong></li>
<li><strong>Hello2</strong></li>
<li><strong>Hello3</strong>></li>
<li><strong>Hello4</strong></li>
<li><strong>Hello5</strong></li>
</ul>
Start Now
</div>
I would like to show a box with some text when for example a user move the pointer over Hello1.
This is the css code
.plan-features {
margin-bottom: 20px;
line-height: 2;
font-size: 12px;
color: #999;
text-align: center;
}
.plan-features > li > strong {
font-weight: bold;
color: #888;
}
.box:hover{
text-align: center;
color: white;
width: 200px;
margin: 10px -12px;
height: 100px;
background-color: rgba(0,0,0, 0.8);
}
I tried to add this to the first <li> tag
<ul class="plan-features">
<div class="box"><li><strong>Hello1</strong></li></div>
but obviously the box is shown with the text "Hello1", how can i hide "hello1" and add some other text?
You can do something like this! i tried to implement according to your requirements. But do explain what are you trying to achieve from this. Should there be different text for each li element? There are other ways too. Which would be simpler than this
HTML
<div>
<strong class="overlap hoverOn">Hello1</strong>
<strong class="overlap hide">someText</strong>
</div>
CSS
div
{
position:relative;
}
.overlap
{
position:absolute;
top:0; left:0;
}
.hide {
display: none;
background: red;
}
.hoverOn:hover + .hide {
display: block;
}
JSfiddle Sample
Cheers!
Try something like this:
HTML
<li><strong hover-text="Some text1">Hello1</strong></li>
CSS
strong:hover {
font-size: 0;
}
strong:hover:before {
font-size: 12px;
content: attr(hover-text);
}
Full code here: https://jsfiddle.net/5qkruhuc/
I found this solution using JavaScript, but the <div id="mynav" class="box"> is always shown except when I click on "x". Instead I want that the box is shown only when I click on "Hello1" and closed after have clicked on the "x"
Here's the code
JavaScript:
<script>
function openNav() {
document.getElementById("myNav").style.width = "100%";
}
function closeNav() {
document.getElementById("myNav").style.width = "0%";
}
</script>
CSS:
.plan-features {
margin-bottom: 20px;
line-height: 2;
font-size: 12px;
color: #999;
text-align: center;
}
.plan-features > li > strong {
font-weight: bold;
color: #888;
}
.box{
text-align: center;
color: white;
width: 200px;
margin: 10px -20px;
height: 100px;
background-color: rgba(0,0,0, 0.8);
overflow-x: hidden;
transition: 0.5s;
}
.closeButton {
color: yellow;
top: 20px;
right: 45px;
}
HTML:
<ul class="plan-features">
<div id="myNav" class="box">
x
<br />Some Text
</div>
<li onclick="openNav()"><strong>Hello1</strong></li>
<li><strong>Hello2</strong></li>
<li><strong>Hello3</strong></li>
<li><strong>Hello4</strong></li>
<li><strong>Hello5</strong></li>
</ul>
Simply do this
HTML Code:
<div class="plan">
<h2 class="title">Premium</h2>
<div align="center">
<p class="plan-price">499<span>€</span></p>
</div>
<ul class="plan-features">
<li><strong>Hello1</strong></li>
<li><strong>Hello2</strong></li>
<li><strong>Hello3</strong>></li>
<li><strong>Hello4</strong></li>
<li><strong>Hello5</strong></li>
</ul>
Start Now
</div>
CSS Code :
.plan-features {
margin-bottom: 20px;
line-height: 2;
font-size: 12px;
color: #999;
text-align: center;
}
.plan-features li strong:hover {
text-align: center;
color: white;
width: 200px;
margin: 10px -12px;
height: 100px;
background-color: rgba(0,0,0, 0.8);
}
Working example: https://jsfiddle.net/rajnikpatel/e7rrk9xy/