So I was wondering how to make the menu item that has been clicked, shown as 'active'/'highligted', so the user can see which page they are on?
I've made this menu bar.
/* Add a black background color to the top navigation */
.topnav_menu {
background-color: #333;
overflow: hidden;
display: flex;
align-items: center;
}
/* Style the links inside the navigation bar */
.topnav_menu a {
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
cursor: pointer;
}
/* Change the color of links on hover */
.topnav_menu a:hover,
.engine_dropdown:hover .engine_dropbtn {
background-color: #ebebeb;
color: black;
}
<div class="topnav_menu">
<!-- # will be removed for enable redirect -->
Profile
Test Runs
Dashboard
TRT Tools
</div>
After the item has been clicked it should appear highlighted.
EDIT
So I created a solution, but is that the best way?
Created this function to check which page in on, and then if im on that page, I would set the class to active
function active($currect_page){
$url = basename(getcwd())."/".str_replace(".php", "", basename($_SERVER['PHP_SELF'])); // If filename is just "name" or "name.php"
// Also checks which directory the file is in, to avoid highlighting multiple menu items with same name
// $currect_page == $url :: parentFolder/fileName == parentFolder/fileName (without .php here)
if($currect_page == $url || $currect_page == basename(getcwd())."/".basename($_SERVER['PHP_SELF'])){
echo 'active'; // class name in css
}
}
<div class="topnav_menu">
<div id="imgDiv"></div>
Test Runs
Dashboard
TRT Tools
</div>
active class would look like this
/* Active menu item */
.topnav_menu a.active,
.topnav_menu a:focus {
/* When a-tags inside this class has been clicked */
background-color: #ffffff;
color: black;
}
Based on how you have written the HTML, bellow js will solve the problem.
//JS
let a = document.querySelectorAll('a')
for(let i =0; i< a.length; i++){
a[i].onclick = function(){
a.forEach(function(item){
item.classList.remove("active");
});
this.classList.add("active");
}
}
Related
I have set up an accordion to present terms and conditions on a website which works until I attempt to pull a page from elsewhere on the server.
My coding so far is as follows:
CSS:
/* Accordion controls & Styles */
/* Style the buttons that are used to open and close the accordion panel */
.accordion {
background-color: #eee;
color: #444;
cursor: pointer;
padding: 18px;
width: 100%;
border: none;
text-align: left;
outline: none;
font-size: 15px;
transition: 0.4s;
}
.active, .accordion:hover {
background-color: #ccc;
}
.accordion:after {
content: '\002B';
color: #777;
font-weight: bold;
float: right;
margin-left: 5px;
}
.active:after {
content: "\2212";
}
.panel {
padding: 0 18px;
background-color: white;
max-height: 0;
overflow: hidden;
transition: max-height 0.2s ease-out;
}
Accordion:
<button class="accordion">Standard Terms</button>
<div class="panel">
<p>
<?php include(SHARED_PATH . '/legal/inserts/standard_terms.php'); ?>
</p>
</div>
and JavaScript:
var acc = document.getElementsByClassName("accordion");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function() {
this.classList.toggle("active");
var panel = this.nextElementSibling;
if (panel.style.maxHeight) {
panel.style.maxHeight = null;
} else {
panel.style.maxHeight = panel.scrollHeight + "px";
}
});
}
Standard terms page to render:
<?php include(SHARED_PATH . '/public_header.php'); ?>
<ol>
<h3><li>What we provide</li></h3>
</ol>
<?php include(SHARED_PATH . '/public_footer.php');?>
Everything works as it should until I put the <?php include(SHARED_PATH . '/legal/inserts/standard_terms.php'); ?> in if I remove it and place outside of accordion it renders fine and displays the content.
Only inside accordion does it stop everything in its tracks.
It doesn't render the rest of the page, and no errors are thrown.
Any Ideas?
Sorry found the answer, realised my mistake after posting the standard terms page. header and footer have already been called by previous page.
I am trying to build a custom template from scratch for my Joomla 3.9 website. I am new to web design. I have been following several tutorials on how to set up menu style via CSS, but I cannot seem to find information on how to define the drop-down menu style. The menu items are defined in Joomla configuration, and the menu should be injected into the right place.
relevant lines from index.php:
<body>
<div class="nav">
<nav>
<jdoc:include type="modules" name="navigation" style="none"/>
</nav>
</div>
</body>
And from template.css:
.nav {
background-color:#FFA500;
position: sticky;
top: 0;
}
ul.nav { //this element needs centering
margin:auto;
width:80%;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #FFA500;
}
ul.nav li {
float:left;
display:block;;
text-align: center;
padding: 14px 16px;
text-decoration: none;
border-right: 3px solid #bbb;
}
ul.nav li:last-child {
border-right: none;
}
ul.nav li a{
color: white;
font-size: 20px
}
ul.nav li:hover {
background-color: #e09100;
}
This code works fine for displaying the menu the way I want (except for not centering it in the screen, but that's not relevant) for simple menu items. However, if I add sub-menu items in Joomla Menu configuration, it gets all messed up. I want these sub-menus to be displayed in a drop-down fashion when the user hovers over the parent item with the mouse, but instead, right now these sub-menus are displayed below the parent item statically. Obviously, that's because I haven't written the code for that part yet.
Problem is, I do not know how to define the style for these sub-menu items, because they are not defined in the CSS, but instead, provided by Joomla. I cannot find any relevant documentation that would tell me the keywords to hook up to these items. Can someone tell me how to turn these sub-menu items into a nice drop-down menu when the user hovers the mouse over the parent menu item?
I'm trying to set up a nav button system where you either hover or click on the SVG ( which is but it as a separate php) then there will be button drop dop, but more like transparent button.
text with a clear background (no box or border). how do I do this?
The Many Ways to Change an SVG Fill on Hover (and When to Use Them)
#CSS Filters
CSS filters allow us to apply a whole bunch of cool, Photoshop-esque effects right in the browser. Filters are applied to the element after the browser renders layout and initial paint, which means they fall back gracefully. They apply to the whole element, including children. Think of a filter as a lens laid over the top of the element it's applied to.
You can change the opacity with the opacity filter opacity(<number-percentage>); .
and you can put this in a hover css tag
.navbar:hover {
filter: opacity(<number-percentage>);
}
And here is how you make a dropdown navbar:
<div class="navbar">
Home
News
<div class="dropdown">
<button class="dropbtn">Dropdown
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
</div>
here is the css to the navbar:
/* Navbar container */
.navbar {
overflow: hidden;
background-color: #333;
font-family: Arial;
}
/* Links inside the navbar */
.navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
/* The dropdown container */
.dropdown {
float: left;
overflow: hidden;
}
/* Dropdown button */
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit; /* Important for vertical align on mobile phones */
margin: 0; /* Important for vertical align on mobile phones */
}
/* Add a red background color to navbar links on hover */
.navbar a:hover, .dropdown:hover .dropbtn {
background-color: red;
}
/* Dropdown content (hidden by default) */
.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;
}
/* Links inside the dropdown */
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
/* Add a grey background color to dropdown links on hover */
.dropdown-content a:hover {
background-color: #ddd;
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
I have a problem when making a wordpress theme integrated with woocommerce like cannot show "add to cart" button when hovering a cursor in product box and only show when hovering a cursor to bottom in product box like GIF below:
woocommerce.css
.woocommerce ul.products li.product .button {
margin: 1em 0 3px 0.3em;
}
.woocommerce a.button {
/* font-size: 100%; */
/* margin: 0; */
/* line-height: 1; */
/* cursor: pointer; */
position: relative;
font-family: inherit;
text-decoration: none;
overflow: visible;
padding: 0.618em 1.75em;
font-weight: 700;
/* border-radius: 3px; */
/* left: auto; */
color: transparent;
background-color: transparent;
/* border: 0; */
/* white-space: nowrap; */
/* display: inline-block; */
/* background-image: none; */
/* box-shadow: none; */
/* -webkit-box-shadow: none; */
/* text-shadow: none; */
}
.woocommerce a.button:hover {
background-color: #f37020;
text-decoration: none;
color: #fff;
background-image: none;
}
.woocommerce ul.products li:hover {
border: 3px solid;
border-color: #f37020;
}
How I can fix it?
UPDATED (Dec 11,2015):
Its my URL link: http://dev.galerigadget.com/shop/
Obviously your "add to cart" button is only displaying when you hover the lower part of the box. That indicates only the bottom area is linked. Your "a" element might need to be "display:block" so it covers the entire block inside the brown rule. Hard to tell without seeing the actual site. Can you post URL?
AFTER EXAMINING YOUR CODE, HERE IS WHAT IS HAPPENING
The add-to-cart link is there, even when not hovered.
You do not see it b/c the CSS includes:
color: transparent;
background-color: transparent;
I would remove those parameters so the button is visible in gray and white. Looks nice and tells the user where to click to purchase the item.
You still have the hover effect that changes the button color to brown, but now the user clearly sees where to put their cursor.
If you want the button 'hidden' until the box is hovered, and then turn brown when hovering the box, add this to your CSS:
li:hover a.add_to_cart_button {
background-color: #f37020;
text-decoration: none;
color: #fff;
background-image: none;
}
Here is an example
$(document).ready(function () {
$(document).on('mouseenter', '.divbutton', function () {
$(this).find(":button").show();
}).on('mouseleave', '.divbutton', function () {
$(this).find(":button").hide();
});
});
.divbutton {
height: 140px;
background: #0000ff;
width:180px;
}
button{
padding: 4px;
text-align: center;
margin-top: 109px;
margin-left: 7px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="divbutton" ">
<button type="button" style="display: none;">ADD TO CART</button>
</div>
Or If you want to use only CSS
button {
display: none; /* Hide button */
}
.divbutton:hover button {
display: block; /* On :hover of div show button */
}
I've got a page (documents.php) that contains four tabs, the 1st tab is set as the default and opens when one browses to documents.php
I need to be able to target tabs 2, 3 and 4 directly from hyperlinks on my index.php and a JavaScript menu that appears on all pages on the site.
Example:
Tab 3 on documents.php contains "archived documents".
On Index.php I want to place a link called "Click here to go to Archived documents" and when someone clicks on it it must take them to documents.php but automatically go to Tab 3 which is "archived documents" and not go to the default 1st Tab.
Here is the coding I am using to create the Tabs and would like to only modify this at most (and not re-invent the wheel by using jQuery or other technology and re-write the tabs on this and other pages):
HTML:
<ul>
<li class="current">General Documents</li>
<li>Circulars</li>
<li>Newsletters</li>
<li>Archived Documents</li>
</ul>
Javascript:
<script>
$(document).ready(function(){
$(".tabs li").click(function() {
$(this).parent().parent().find(".tab-content").hide();
var selected_tab = $(this).find("a").attr("href");
$(selected_tab).fadeIn();
$(this).parent().find("li").removeClass('current');
$(this).addClass("current");
return false;
});
});</script>
Then there's some CSS in an external style sheet that formats the Tabs, their borders, background etc.
CSS Formatting:
.tabs ul{
list-style:none;
display:block;
margin:0px;
padding:0px;
z-index:99;
position:relative;
}
.tabs li {
float:left;
display:block;
border-top:#E5E5E5 1px solid;
border-left:#E5E5E5 1px solid;
border-right:#E5E5E5 1px solid;
border-top-left-radius:4px;
border-top-right-radius:4px;
position:relative;
z-index:999;
color: #444444;
padding: 4px 8px 4px 8px;
margin: 0px 6px 0px 0px;
background: #e7e7e7 url(/assets/images/common/bg.png) repeat-x;
}
.tabs li:hover {
/*If you want hover effects on tabs put your css here*/
}
.tabs li a {
display:block;
color:#323234;
outline:none;
}
.tabs li.current {
border-bottom:#DD6E27 2px solid;
outline:none;
}
.tab-content {
display:none;
clear:both;
min-height: 120px;
border-top-left-radius:0px;
border-top-right-radius:4px;
border-bottom-left-radius:4px;
border-bottom-right-radius:4px;
color:#444444;
background:#fefefe url(/assets/images/common/bg.png) repeat-x;
border: 1px solid #E5E5E5;
overflow:hidden;
padding:15px;
}
.tab-content:first-child {
display: block;
}
Pass the # value url like http://example.com#tabs3 .Then use like this in your document ready.
$(document).ready(function(){
var hash = window.location.hash;
$('#'+ hash).addClass("current");
$(".tabs li").click(function() {
$(this).parent().parent().find(".tab-content").hide();
var selected_tab = $(this).find("a").attr("href");
$(selected_tab).fadeIn();
$(this).parent().find("li").removeClass('current');
$(this).addClass("current");
return false;
});
});