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>
Related
I am new to HTML and am about to complete my first website, however, I am stuck on the formatting of my navbar at different page widths.
I successfully managed to have a navbar with full options at max width, a drop down menu button below a certain width (1045px) and a sticky navbar when above 1045px with all options.
However, when the navbar is smaller than 1045px, the menu doesn't keep the same formatting and won't open to show drop down options. It also is permanently locked in the top left of the screen no matter the width.
Can someone please help fix my issue or provide guidance. The links provided are the resources I used to create this:
https://www.w3schools.com/howto/howto_css_dropdown.asp
https://www.w3schools.com/howto/howto_js_navbar_sticky.asp
These are also some minor issues I wanted to fix as well:
The options below 'Menu' option are left aligned to the button, Ii
would prefer it to be centred
When clicking the options in the full sized navbar, the back-ground colour changes even though I haven't programmed for this and would like the background colour not to change
Thank you for any help you can provide
EDIT:
I managed to fix the navbar formatting so it now says just menu when below 1045px, but when you hover or click on menu, the list for it doesn't show beneath; I instead noticed the list appeared on the right of all the other options when expanding the width beyond 1045px, with incorrect font-colour.
HTML:
<div id="navbar" class="sitcky">
<a title="Go to 'Before Rutherford' page" href="#">BEFORE RUTHERFORD</a>
<a title="Go to 'Experiment + results' page" href="exp.html">EXPERIMENT + RESULTS</a>
<a title="Go to 'What it changed' page" href="chang.html">WHAT IT CHANGED</a>
<a title="Go to 'Scattering equation' page" href="equa.html">SCATTERING EQUATION</a>
<div class="dropdown">
<button class="dropbtn">MENU</button>
<div class="dropdown-content">
<a title="Go to 'Before Rutherford' page" href="#">BEFORE RUTHERFORD</a>
<a title="Go to 'Experiment + results' page" href="exp.html">EXPERIMENT + RESULTS</a>
<a title="Go to 'What it changed' page" href="chang.html">WHAT IT CHANGED</a>
<a title="Go to 'Scattering equation' page" href="equa.html">SCATTERING EQUATION</a>
</div>
</div>
<!-- Script to keep navbar sticky when scrolled -->
<script>
window.onscroll = function() {myFunction()};
var navbar = document.getElementById("navbar");
var sticky = navbar.offsetTop;
function myFunction() {
if (window.pageYOffset >= sticky) {
navbar.classList.add("sticky")
} else {
navbar.classList.remove("sticky");
}
}
</script>
CSS:
#navbar {
background-color: rgb(0, 25, 50);
display: block;
width: auto;
text-align: center;
padding-top: 14px;
padding-bottom: 14px;
z-index: 10;
}
#navbar a {
color: whitesmoke;
text-decoration: none;
font-size: 16px;
padding-left: 30px;
padding-right: 30px;
}
#navbar a:hover{
color: rgb(255, 192, 0);
}
#s_navbar {
background-color: rgb(0, 25, 50);
display: block;
width: auto;
text-align: center;
padding-top: 14px;
padding-bottom: 14px;
z-index: 10;
}
#s_navbar a {
color: whitesmoke;
text-decoration: none;
font-size: 16px;
padding-left: 30px;
padding-right: 30px;
}
#s_navbar a:hover{
color: rgb(255, 192, 0);
}
#media (max-width: 1045px) {
#navbar a{display: none;}
}
#media (min-width: 1045px) {
.dropbtn {display:none;}
}
.dropdown {
position: relative;
display: inline-block;
}
.dropbtn {
background-color: rgb(0, 25, 50);
color: whitesmoke;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {
background-color: #f1f1f1
}
.dropdown:hover .dropdown-content {
display: block;
color: rgb(255, 192, 0);
}
.sticky {
position: fixed;
top: 0;
left:0;
right:0;
width:max-content;
}
.sticky + .main {
padding-top: 60px;
}
I have a dropDown menu and when the drop list is open is overlapping the div below, I wish to push the div below down when the dropdown is open, I've try with flex, grid, flexgrow, grid rows, positions relative/absolute, and I can't find any solution.
here is the HTML code:
<div class="container">
<div class="dropContainer">
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">Dropdown</button>
<div id="myDropdown" class="dropdown-content">
Home
About
Contact
</div>
</div>
</div>
<div class="inputContainer">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname" />
</div>
</div>
and the CSS:
.container{
display: flex;
flex-direction: column;
height: 100vh;
}
.dropContainer{
display: block;
height: 100%;
margin-bottom: 2rem;
}
.inputContainer{
display: block;
height: 100%;
top: 5rem;
}
/* dropDown Menu */
.dropbtn {
background-color: #3498DB;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 160px;
padding-bottom: 140px;
overflow: auto;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.show {display: block; }
and here is the code example working: https://codepen.io/raulcosalux/pen/VwzGyYO
kind regards,
Using absolute positioning will not regard for content underneath. With that being said, you have to use position: relative; on your dropdown menu in order to allow the input or any other content below to adjust when the menu opens.
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
.container{
display: flex;
flex-direction: column;
height: 100vh;
}
.dropContainer{
display: block;
height: 100%;
margin-bottom: 2rem;
}
.inputContainer{
display: block;
height: 100%;
position: sticky;
}
/* dropDown Menu */
.dropbtn {
background-color: #3498DB;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: relative;
background-color: #f1f1f1;
min-width: 160px;
padding-bottom: 140px;
overflow: auto;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.show {display: block; }
<div class="container">
<div class="dropContainer">
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">Dropdown</button>
<div id="myDropdown" class="dropdown-content">
Home
About
Contact
</div>
</div>
</div>
<div class="inputContainer">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname" />
</div>
</div>
Change the position of the dropdown container that holds the menu to relative, then remove the padding you have on it. Remove this => padding-bottom: 140px; and change this => .dropdown-content { position: absolute; } to .dropdown-content { position: relative; }, this will push the content down below the menu element and the padding will no longer cover its content.
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
.container{
display: flex;
flex-direction: column;
height: 100vh;
}
.dropContainer{
display: block;
margin-bottom: 2rem;
}
.inputContainer{
display: block;
height: 100%;
top: 5rem;
}
/* dropDown Menu */
.dropbtn {
background-color: #3498DB;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.show {
display: block;
}
<div class="container">
<div class="dropContainer">
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">Dropdown</button>
<div id="myDropdown" class="dropdown-content">
Home
About
Contact
</div>
</div>
</div>
<div class="inputContainer">
<label for="fname">First name: </label>
<input type="text" id="fname" name="fname" />
</div>
</div>
I also removed the height on the dropContainer as well.
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>
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>```
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.