Navigation stays highlighted after clicking on it - html

Hi i just wanted some help trying to animate my navigation bar. I want the nav link to still be highlight after I have clicked on the page. So for example if I pressed a "home" button while on the home page the home button would be highlighted to just to show that your definitely on this page. Would use :target or ::active?
<div id="header-content">
<div class="hire"><h3>For Hire</h3></div>
<h1>Black Cab Tours</h1>
<nav class="cl-effect-8">
<ul>
<li><a onclick="tours.html" href="#tab1">Tours</a></li>
<li>About</li>
<li>Contact</li>
<li>Review</li>
</ul>
</nav>
</div>

create a css class like
.active {
background: #c2c2c2;
}
when u click on a HOME page link add this class to that li tag through java script here is the code
$('li').click(function(){
$(this).removeClass('active');
$(this).addClass('active');
});
or you can use gt(), lt() selector to remove active class from else li tags

Your best bet is to use Javascript (e.g. jQuery) to assist you, in native CSS :active will only style the current interaction state as it occurs, :target may be unreliable if you rely on routing, and the final option :focus will fail when clicking elsewhere.
By using jQuery you can more tightly maintain control over the application/removal of a selected state, e.g:
$('#header-content li').on('click', function(){
$(this).addClass('selected').siblings().removeClass('selected');
});
This isolates the relevant elements, adds the class selected when you click one, and removes it from its siblings.

Related

How can I fadeOut() each individual li in a ul and keep track of how many li have been clicked on?

I have a number of tabs created with CSS that contains a ul within a div. I want to use jQuery to fadeOut() each li when clicked on and also keep track of how many lis have been clicked on. This is the code I have so far, it is currently fading out every single li when one is clicked on.
<div class="tab">
<h2>Lobby</h2>
<ul>
<li>Sponsor logos are displayed correctly and all link to their relevant sponsor booths</li>
<li>Top-left (branding) logo is displayed correctly and links to the event homepage</li>
<li>Lecture Theatre signpost is displayed correctly and links to the Live Redirect</li>
<li>Exhibition Hall signpost is displayed correctly and links to the event Exhibition Hall</li>
<li>If Delegate chat is in use, ensure the Minnit chat widget is displayed correctly and working</li>
<li>Ensure background image is appropriate for the event and displayed correctly, adjustments can be made in the branding tab CSS on the platform</li>
</ul>
</div>
<script>
$(document).ready(function(){
$("li").click(function(){
$("li").fadeOut()
});
});
</script>
To do what you require you need to reference the element which was clicked on. To do that you can use the this keyword within the anonymous function:
$("li").click(function(){
$(this).fadeOut()
});
Alternatively you can use an arrow function to make the code more succinct, however you will need to use the target property of the event argument in this case:
jQuery($ => {
$("li").click(e => $(e.target).fadeOut());
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="tab">
<h2>Lobby</h2>
<ul>
<li>Sponsor logos are displayed correctly and all link to their relevant sponsor booths</li>
<li>Top-left (branding) logo is displayed correctly and links to the event homepage</li>
<li>Lecture Theatre signpost is displayed correctly and links to the Live Redirect</li>
<li>Exhibition Hall signpost is displayed correctly and links to the event Exhibition Hall</li>
<li>If Delegate chat is in use, ensure the Minnit chat widget is displayed correctly and working</li>
<li>Ensure background image is appropriate for the event and displayed correctly, adjustments can be made in the branding tab CSS on the platform</li>
</ul>
</div>

Angular/Typescript - Change background color of a span when a link is clicked

I'm trying to change the color of a span when a link is clicked in order to indicate that it's checked. This must work in the form of a radio button, meaning that the color must disappear if another link is clicked (checked). I tried various methods using only html and css, but unfortunately I never managed to get it to work using :focus. At the moment, when I click on one of the filters there is no indication that one of the categories has been activated, heavily impacting the UX. I believe that this can be achieved using ngClass in angular, however, I'm really struggling to understand how this works. Any help would be really appreciated.
HTML:
<div class="checklist categories">
<ul>
<li><a data-action="filter-link" (click)="changeCategory(null)"><span></span>All</a></li>
<li><a data-action="filter-link" (click)="changeCategory('House Favourites')"><span></span>House Favourites</a></li>
</ul>
</div>
The styling of the span forms a small checkbox.
u can use ngClass Demo
in css create your class and write which css you want
.active-link span{background-color:green;}
in html create ngClass for each list item
<ul>
<li><a data-action="filter-link" [ngClass]="{'active-link' : menus.allMenu}" (click)="changeCategory(null,'allMenu')"><span></span>All</a></li>
<li><a data-action="filter-link" [ngClass]="{'active-link' : menus.houseMenu}" (click)="changeCategory('House Favourites','houseMenu')"><span></span>House Favourites</a></li>
</ul>
then in ts create model for menus
menus={allMenu:false,houseMenu:false}
with function first initialize it then change clicked one
changeCategory(el,event){
this.menus.allMenu=false;
this.menus.houseMenu=false;
this.menus[event]=!this.menus[event];
}

How to change texts colors in my case

I have bunch of links and I need to change the texts color to red after user clicks them
I have something like:
<li class="test" ng-repeat="item in items">
<a href="" ng-click="clickMe()" class="test-li">
{{item.name}}
</a>
</li>
Currently the style is like
.test-li {
color: black;
}
I want my texts to turn red after user clicks them.
So I do:
.test-li:visited {
color:red;
}
It works when I click the item, but the color changes back to black after I click another item. I feel like this can be archive simply in CSS without setting ng-class. Can anyone help me about it? Thanks a lot!
You don't have any destination url given in your links, so there really isn't a way for the browser to know which links have been visited. I think if you were to add a simple #test, #test1, #test2, etc to your href attribute in your links, you would find that your CSS does work as intended.
Since your link doesn't actually go anywhere, you'd be better off adding a 'visited' class to your <a> element when clicked, via JS.
jQuery exmample:
$('li a').click(function(){
$(this).addClass('visited');
// or you could use $(this).toggleClass('visited'); depending on what you want to achieve.
});

Struggling to make an icon into a button

Im trying to make the icon im using into a button that when pressed, triggers the navigation bar to open. Here is the HTML:
<div id="fixedBar">
<h1>Company</h1>
</div>
The class is the icon image and the id triggers the nav bar. The problem is that when I click the icon, the page scrolls back to the top due to the href of '#'.
Im not sure how I can get the icon to not link to anything when clicked.
Thanks!
a href is not needed just use a fake link class
<span class="fake-link" id="fake-link-1"> fake link</span>
.fake-link {
color: blue;
text-decoration: underline;
cursor: pointer;
}
You can remove the href attribute on your a , which is valid in HTML5. This will turn your link into a placeholder hyperlink.
If you're using Javascript in your application, you can set an event handler for the click, and use the preventDefault() method.
Code example with jQuery :
$('a').on('click', function(e){
e.preventDefault();
});

Disabled link in Bootstrap Pagination

I'm trying to use Bootstrap's Pagination style. The documentation says to create the page list like so:
<div class="pagination">
<ul>
<li class="disabled">«</li>
<li class="active">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>»</li>
</ul>
</div>
The first two links, the left arrow and the 1, should be disabled. When I incorporate it into my django template though, those two are still usable. Clicking them sends the user to the top of the page just like any other anchor link with an id "#". I think I still have to have the there in order for Bootstrap to style it correctly.
Is there a way to write this so that when the user clicks one of the disabled "buttons" it doesn't do anything?
In the docs, those buttons are just disabled manually. It has nothing to do with the .pagination styling.
You could use that
$('.pagination .disabled a, .pagination .active a').on('click', function(e) {
e.preventDefault();
});
Note: If you use an ajax based pagination you have to put this piece of code in the update handler or use delegated events instead
If you write the html dynamically server side (with django for example) and you don't want to use javascript you could do this:
pseudo code:
if (Model.HasNext()) {
<li> // normal link
next
</li>
} else {
<li class="disabled"> // disabled link
next
</li>
}
As a reference, here is what Bootstrap does:
&.disabled,
&[disabled] {
cursor: not-allowed;
pointer-events: none; // Future-proof disabling of clicks
.opacity(.65);
.box-shadow(none);
}
$('.disabled a').click(function(){
return false;
});
For PHPLD v 4.2 I used the following code to show Bootstrap 3 pagination
{* Display Paging Links *}
<ul class="pagination">
<li>{paginate_prev id="MainPaging"}</li>
{paginate_middle id="MainPaging" format="page" prefix="" suffix="" link_prefix="
<li>"link_suffix="</li>" current_page_prefix="
<li class=\"active\">"current_page_suffix="</li>"}
<li>{paginate_next id="MainPaging"}</li>
</ul>