Responsive Hover Code - html

I'm creating a map/floorplan with hover but the hover image + text does not seem to be responsive to the image. I'm using fixed value and I understand I should use % but even when I do, I'm not experienced enough to get it to work.
How it looks when image is not made responsive
How it looks when image is made responsive
CSS:
.hoverinfosupermarket {
position: absolute;
top:79%;
left: 37%;
font-size: 80%;
font-family: Arial;
font-weight: bold;
color: #6e706f;
cursor: default;
}
.hoverinfosupermarket p {
display: none;
color: #000000;
font-size:10px;
}
.hoverinfosupermarket:hover p {
background-color: rgba(255, 255, 255, 0.7);
display: block;
}
HTML:
<div class="hoverinfosupermarket">
<span>#B1-01</span>
<p>
<img alt="Supermarket" src="/cs/w/img/supermarket.jpg" /><br />
Supermarket
</p>
</div>
The map/floorplan is actually inside a tab and the hover image + text is within this tab as well.
<div class="tab">
<button class="tablinks" onclick="openMap(event, 'B1')">B1</button>
<button class="tablinks" onclick="openMap(event, 'L1')">L1</button>
</div>
<script>
function openMap(evt, mapName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(mapName).style.display = "block";
evt.currentTarget.className += " active";
}
</script>
CSS :
.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 14px 16px;
transition: 0.3s;
font-size: 17px;
}
.tab button:hover {
background-color: #ddd;
}
.tab button.active {
background-color: #ccc;
}
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
}

You container <div class="hoverinfosupermarket"> should have position: relative and then add position: absolute to p tag. After specifying these, use pixels to specify the top and left. It would work like charm.

Related

Collapsible Icon/Content Color Change on Hover

I'm working on 'collapsible' content (a FAQ dropdown). On the pre-clicked 'button' I have a 'plus' icon (the icon turns to a 'negative' icon after the button is pressed). What I would like is for the pre-clicked button 'plus' icon to change colors (namely, turn white) when the button is hovered over. I'm not sure how to modify the CSS to make the icon change on hover.
I have tried:
.collapsible:after, .hover{
color: $light;
}
But this only reverses the issue... Thank you in advance! Code below.
var coll = document.getElementsByClassName("collapsible");
var i;
for (i = 0; i < coll.length; i++) {
coll[i].addEventListener("click", function() {
this.classList.toggle("active");
var content = this.nextElementSibling;
if (content.style.display === "block") {
content.style.display = "none";
} else {
content.style.display = "block";
}
});
}
/* TARGET ICON */
.collapsible:after {
content: '\02795'; /* Unicode character for "plus" sign (+) */
color: black;
font-weight: bold;
float: right;
margin-left: 5px;
}
.active:after {
content: "\2796"; /* Unicode character for "minus" sign (-) */
color: white;
}
/* Style the button that is used to open and close the collapsible content */
.collapsible {
background-color: white;
color: black;
cursor: pointer;
padding: 10px 18px;
width: 100%;
border: solid;
border-width: thin;
border-radius: 5px;
margin-bottom: 5px;
text-align: left;
outline: none;
font-size: 24px;
}
/* Add a background color to the button if it is clicked on (add the .active class with JS), and when you move the mouse over it (hover) */
.active, .collapsible:hover {
background-color: black;
color: white;
}
/* Style the collapsible content. Note: hidden by default */
.content-faq {
padding: 0px 22px;
border-radius: 5px;
margin-bottom: 15px;
margin-top: -6px;
max-height: 0;
transition: max-height 0.2s ease-out;
background-color: #f1f1f1;
}
<button class="collapsible">Some Question</button>
<div class="content-faq">
<p>Some Answer</p>
</div>
Use .collapsible:hover::after to select the content on hover created with the use of ::after
As the greyish color is of the symbol you used which is inherited so changed that to simple + - for demo to show effect only .
You can use any symbol but without inherit color
var coll = document.getElementsByClassName("collapsible");
var i;
for (i = 0; i < coll.length; i++) {
coll[i].addEventListener("click", function() {
this.classList.toggle("active");
var content = this.nextElementSibling;
if (content.style.display === "block") {
content.style.display = "none";
} else {
content.style.display = "block";
}
});
}
/* TARGET ICON */
.collapsible::after {
content: '+';
/* Unicode character for "plus" sign (+) */
color: black;
font-weight: bold;
float: right;
margin-left: 5px;
}
.active:after {
content: "\2212";
/* Unicode character for "minus" sign (-) */
color: white;
}
/* Style the button that is used to open and close the collapsible content */
.collapsible {
background-color: white;
color: black;
cursor: pointer;
padding: 10px 18px;
width: 100%;
border: solid;
border-width: thin;
border-radius: 5px;
margin-bottom: 5px;
text-align: left;
outline: none;
font-size: 24px;
}
/* Add a background color to the button if it is clicked on (add the .active class with JS), and when you move the mouse over it (hover) */
.active,
.collapsible:hover {
background-color: black;
color: white;
}
/* Style the collapsible content. Note: hidden by default */
.content-faq {
padding: 0px 22px;
border-radius: 5px;
margin-bottom: 15px;
margin-top: -6px;
max-height: 0;
transition: max-height 0.2s ease-out;
background-color: #f1f1f1;
}
.collapsible:hover::after {
color: white;
}
<button class="collapsible">Some Question</button>
<div class="content-faq">
<p>Some Answer</p>
</div>

Hover affect of tooltip also underlines text of content in span

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.

Why can't I type or click into textarea?

I'm new to HTML and CSS, and I have some problems that I can't fix by myself.
My problem is that I can't type into my textarea, when I click on it nothing happens, also, I tried to put text ( "New Paste" ) above that, and I cant see it.
There is already questions on Stackoverflow about the textarea problem, but it didnt match to my problem.
How can I change my textarea position to be under the "New Paste" text ?
How can I fix my problem with textarea and write to it ?
function saveTextAsFile() {
var textToWrite = document.getElementById('textArea1').innerHTML;
var textFileAsBlob = new Blob([textToWrite], {
type: 'text/plain'
});
var fileNameToSaveAs = "MakePython.py";
var downloadLink = document.createElement("a");
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = "Download File";
if (window.webkitURL != null) {
// Chrome allows the link to be clicked without actually adding it to the DOM.
downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
} else {
// Firefox requires the link to be added to the DOM before it can be clicked.
downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
downloadLink.onclick = destroyClickedElement;
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
}
downloadLink.click();
}
var button = document.getElementById('SaveFile');
button.addEventListener('click', saveTextAsFile);
function destroyClickedElement(event) {
// remove the link from the DOM
document.body.removeChild(event.target);
}
body {
background-color: lightslategray
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
position: fixed;
top: 0px;
width: 100%;
}
li {
float: left;
}
.text {
display: block;
color: white;
text-align: center;
padding: 16px 18px;
background-color: teal;
text-decoration: none;
}
li a:hover {
background-color: black;
}
#textAreaOne {
display: block;
margin-left: auto;
margin-right: auto;
resize: none;
width: 950px;
height: 750px;
}
#SaveFile {
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin-left: auto;
margin-right: auto;
display: block;
}
#SaveFile:hover {
box-shadow: 0 12px 16px 0 rgba(0, 0, 0, 0.24), 0 17px 50px 0 rgba(0, 0, 0, 0.19);
}
<ul>
<li><a class="text" href="">Home</a></li>
<li><a class="text" href="">About</a></li>
<li><a class="text" href="">Contact</a></li>
</ul>
<p style="color: black;"><b>New Paste</b></p>
<textarea id="textAreaOne"></textarea>
<button id="SaveFile" type="button" value="Save File">Save</button>
Changing the position: fixed to sticky fixes your 'New Paste' problem.
function saveTextAsFile() {
var textToWrite = document.getElementById('textArea1').innerHTML;
var textFileAsBlob = new Blob([textToWrite], {
type: 'text/plain'
});
var fileNameToSaveAs = "MakePython.py";
var downloadLink = document.createElement("a");
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = "Download File";
if (window.webkitURL != null) {
// Chrome allows the link to be clicked without actually adding it to the DOM.
downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
} else {
// Firefox requires the link to be added to the DOM before it can be clicked.
downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
downloadLink.onclick = destroyClickedElement;
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
}
downloadLink.click();
}
var button = document.getElementById('SaveFile');
button.addEventListener('click', saveTextAsFile);
function destroyClickedElement(event) {
// remove the link from the DOM
document.body.removeChild(event.target);
}
body {
background-color: lightslategray;
margin: 0;
padding: 0;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
position: sticky;
top: 0px;
width: 100%;
}
li {
float: left;
}
.text {
display: block;
color: white;
text-align: center;
padding: 16px 18px;
background-color: teal;
text-decoration: none;
}
li a:hover {
background-color: black;
}
#textAreaOne {
display: block;
margin-left: auto;
margin-right: auto;
resize: none;
width: 950px;
height: 750px;
}
#SaveFile {
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin-left: auto;
margin-right: auto;
display: block;
}
#SaveFile:hover {
box-shadow: 0 12px 16px 0 rgba(0, 0, 0, 0.24), 0 17px 50px 0 rgba(0, 0, 0, 0.19);
}
<ul>
<li><a class="text" href="">Home</a></li>
<li><a class="text" href="">About</a></li>
<li><a class="text" href="">Contact</a></li>
</ul>
<p style="color: black;"><b>New Paste</b></p>
<textarea id="textAreaOne"></textarea>
<button id="SaveFile" type="button" value="Save File">Save</button>
Like I said, your textarea just works fine.
Your textArea id textAreaOne but you select the textArea1
var textToWrite = document.getElementById('textArea1').innerHTML;
<textarea id="textAreaOne"></textarea>
That's why when you click button nothing happens. To fix this handle true id
Also i would like say something about your HTML
Give an static height your header which is ul in this example
Use HTML5 tags like <header>, <section>
Then let margin on top the section because your header is position absolute or fixed, so this is not effect to relative height.
For example:
<head>
<style type="text/css">
header {
position: absolute;
height: 50px;
width: 100%;
top: 0;
}
section {
position: relative;
margin-top: 100px;
}
</style>
</head>
<body>
<header>
...blabla
</header>
<section>
...blabla
</section>
</body>```

Drop down submenu opening overlapping the main menu with back button

I kindly ask you for help, I would like the submenus to open in slide in the same screen overlapping in the drop vertical menu, because I have many rows and submenus to insert and use the back button to go back in the submenus when they are overlapped.
They do not have to open in cascade like it is now, or sideways, but when I click car the submenu must completely overlap the main menu, and then use the back buttons to go back in the menu go, is it possible?
the back button does not work for me..
I would like the submenus to open to pages, then overlapping each other and using the back button to go back through the menus
var dropdown = document.getElementsByClassName("dropdown-btn");
var i;
for (i = 0; i < dropdown.length; i++) {
dropdown[i].addEventListener("click", function() {
this.classList.toggle("active");
var dropdownContent = this.nextElementSibling;
if (dropdownContent.style.display === "block") {
dropdownContent.style.display = "none";
} else {
dropdownContent.style.display = "block";
}
});
}
.sidenav {
height: 250px;
width: 300px;
z-index: 1;
top: 200px;
left: 0;
background-color: #444;
overflow-x: hidden;
padding-top: 20px;
}
.sidenav a,
.dropdown-btn {
padding: 14px 8px 6px 16px;
text-decoration: none;
font-size: 17px;
color: #8c8c8c;
display: block;
border: none;
background: none;
width: 100%;
text-align: left;
cursor: pointer;
outline: none;
margin-left: 2px;
}
.sidenav a:hover,
.dropdown-btn:hover {
color: #f1f1f1;
background: #555;
border-left: 3px solid #f1d120;
margin-left: -1px;
}
.main {
margin-top: -460px;
margin-left: 310px;
font-size: 20px;
padding: 10px 50px;
}
.active {
background-color: grey;
color: white;
}
.dropdown-container {
display: none;
background-color: #4c4c4c;
padding-left: 8px;
}
<div class="sidenav">Brand <button class="dropdown-btn">Car <strong>
</strong> </button>
<div class="dropdown-container">° renault ° citoren</div>
<br /><br /><br />
<button>back</button>

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>