Collapsible Icon/Content Color Change on Hover - html

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>

Related

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.

ANKI CSS/HTML: How to make Tags in browser "Position: fixed" in the bottom right corner, without the tags overlapping?

See video for more detail on question:
https://streamable.com/td4k8j
I have all my tags visible on review, but I want them in the fixed position (i.e. doesn't move with scroll) in the bottom right. When I try this, they all overlap in the bottom right, how can I separate them?
I don't know a lot about HTML/CSS, and this is as far as I could get with common sense, please could answers be as specific as possible including the code? It's fine if not, thank you for your time.
Front Code (HTML):
<b id="tags-container">{{Tags}}</b>
<script>
var tagContainer = document.getElementById("tags-container")
if (tagContainer.childElementCount == 0) {
var tagList= tagContainer.innerHTML.split(" ");
var kbdList = [];
var newTagContent = document.createElement("div");
for (var i = 0; i < tagList.length; i++) {
var newTag = document.createElement("kbd");
newTag.innerHTML = tagList[i];
newTagContent.append(newTag)
}
tagContainer.innerHTML = newTagContent.innerHTML;
tagContainer.style.cursor = "default";
}
</script>
{{/Tags}}
Styling Code (CSS):
/* TAGS */
/* Clickable Tags (need to download the add-on) */
kbd {
display: inline-block;
letter-spacing: .2px;
font-weight: bold;
font-size: 16px !important;
text-shadow: none !important;
padding: 0.05rem 0.1rem !important;
margin: 1px !important;
border-radius: 4px;
border-width: 1.5px !important;
border-style: solid;
background-color: transparent !important;
box-shadow: none !important;
opacity: 0.5;
vertical-align: right;
word-break: break-all;
}
/* Tag Becomes More Visible On Hover */
kbd:hover { opacity: 1; transition: opacity 0.2s ease; }
/* Tag Colors */
kbd:nth-of-type(1n+0) { border-color: #fc00ff; color: #fc00ff; }
kbd:nth-of-type(2n+0) { border-color: #03A9F4; color: #03A9F4; }
kbd:nth-of-type(3n+0) { border-color: #FF0000; color: #FF0000; }
kbd:nth-of-type(4n+0) { border-color: #faed27; color: #faed27; }
kbd:nth-of-type(5n+0) { border-color: #FF9933; color: #FF9933}
kbd:nth-of-type(6n+0) { border-color: #ff6ec7; color: #ff6ec7; }
kbd:nth-of-type(7n+0) { border-color: #8ffcff; color: #8ffcff; }
kbd:nth-of-type(8n+0) { border-color: #ff009a; color: #ff009a; }
kbd:nth-of-type(9n+0) { border-color: #39ff14; color: #39ff14; }
kbd:nth-of-type(10n+0) { border-color: #1b03a3; color: #1b03a3; }
/* Tag Mobile Adjustments */
.mobile kbd { opacity: .9; margin: 1px !important; display: inline-block; font-size: 14px !important; }
.mobile #tags-container {line-height:0.6rem; margin-left: 0px; }
apply the position: fixed to their container, not to the elements themselves. If there is no dedicated container for them, create one...

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>

how to make color change to white when hovering over button

The text color only changes when I hover over the text. I want the text color to change to white when I hover over the button.
Can anyone see where I am going wrong, please?
#callbtn {
border: 1px solid #507487;
background-color: white;
padding: 10px;
font-size: 20px;
color: #507487;
border-radius: 10px;
font-weight: bold;
text-align: center;
}
#callbtn:hover {
background-color: orange;
color: white;
border: 1px solid orange;
cursor: pointer;
}
#callbtn a {
color: #507487;
}
#callbtn a:hover {
color: white;
}
#media screen and (max-width: 768px) {
#callbtn {
font-size: 14px;
}
}
#callbtn i {
padding-right: 10px;
}
<p class="m-2 text-center" id="callbtn"><i class="fas fa-phone-volume"></i>Call</p>
Your CSS need to apply the color on hover of the button, not the hover of the link
#callbtn:hover a {
color: #FFF
}
callbtn:hover triggering when the button is hovered over, and a:hover is triggering when the link is hovered over. Which is why this is happening, you are hovering over the button but not setting the colour of the link. The CSS below will set a style to the child link when button is hovered over.
#callbtn:hover a {
color: white;
}
It would be more efficient to set your button up like this:
.callbtn {
display: block;
border: 1px solid #507487;
background-color: white;
color: #507487;
padding: 10px;
text-decoration: none;
border-radius: 10px;
text-align: center;
font-weight: bold;
font-size: 20px;
}
.callbtn:hover {
border: 1px solid orange;
background-color: orange;
color: white;
}
.callbtn i {
padding-right: 10px;
}
#media screen and (max-width: 768px) {
.callbtn {
font-size: 14px;
}
}
<link href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" rel="stylesheet"/>
<a class="callbtn" href="tel:+441225xxxxxx">
<i class="fas fa-phone-volume"></i>Call
</a>
It's a bit weird but some JavaScript solves the problem:
var callButton = document.body.querySelector("#callbtn");
var callButtonLnk = document.body.querySelector("#callbtn a");
callButton.addEventListener("mouseover", function(){
callButtonLnk.style.color = "white";
})
callButton.addEventListener("mouseout", function(){
callButtonLnk.style.color = "#507487";
})

Responsive Hover Code

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.