Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Active page link - :active only works when mouse button pressed

Featured Replies

I'd like my navigation menu to show a different link background color to reflect the current/active page of my website.

My html for the menu is this:

<!doctype html>
<html>
<head>
<link rel="shortcut icon" href="/img/favicon.ico">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>News - Lyle Christine</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
</head>

<body>
<div class="header"><h1><a href="http://www.lylechristine.com">LYLE CHRISTINE.com</a></h1></div>
<ul class="nav">
  <li><a href="news.html">News</a></li>
  <li><a href="greetings.html">Greetings</a></li>
  <li><a href="music.html">Music</a></li>
  <li><a href="media.html">Media</a></li>
  <li><a href="http://www.lylechristine.com/blog">Blog</a></li>
  <li><a href="links.html">Links</a></li>
</ul>

<div class="maincontainer">

<div class="newscontainer">
      <h3>NEWS</h3>
       *NEWS COPY*
  </div>
<p><a class="twitter-timeline" href="https://twitter.com/PithyArtist" data-widget-id="447044618178150400">Tweets by @LyleChristine</a> 
        <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> 
  </p>
 
</div>
<div class="maincontainer2">
<object id="EdgeID" type="text/html" width="420" height="220" data-dw-widget="Edge" data="edgeanimate_assets/shop_link_big/Assets/shop_link_big.html">
</object>
</div>
<ul class="socialmedia">
  <li><a href="https://twitter.com/PithyArtist"><img src="img/32x32_twitter.png" width="32" height="32" alt=""/></a></li>
  <li><a href="https://www.facebook.com/lyle.christine"><img src="img/32x32_facebook.png" width="32" height="32" alt=""/></a></li>
  <li><a href="https://www.youtube.com/user/LylieChristine/videos"><img src="img/32x32_youtube.png" width="32" height="32" alt=""/></a></li>
</ul> 

<div class="footer">
    <div class="copyright">© 2015 <a href="contact.html">CONTACT</a></div>
   
</div>
   
  </div>
    
  </div>
</body>
</html>

and the css is this:



 

/* CSS Document */
@charset "utf-8";



@import url(http://fonts.googleapis.com/css?family=Lato:400,700,400italic);

@import url(http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,900);

a, a:hover, a:visited {font-weight: bold;}



a {
	color: #FFFFFF;
	transition: 0.5s;
	text-decoration: none;
 }

	a:hover {color: #714BF0;}



	a:visited {color: #FFFFFF;}

.albumcover {
	width: 300px;
	height: 300px;
	float: right;
}

.albumdetails {
	float: left;
	width: 400px;
	height: 350px;	
}

.albumshop {
	width: 300px;
	height: 40px;
	float: right;
	text-align:center;
	transition: 0.5s;
	background-color: rgba(0,0,0,1.00);
	padding-top: 5px;
	
}

	.albumshop a:hover {
		-webkit-filter: brightness(50%);
		filter: brightness(50%);
		ms-filter: brightess(50%);
	 
	
}

#buyrecords {
	padding: 0px;
	
}

body {
	color: #FFFFFF;
	background-color: #000000;
	font-family: 'Lato', sans-serif;
	background-image: url(img/backgrounds/21.gif);
	background-repeat: no-repeat;
	background-attachment: fixed;
	background-size: cover;
	overflow-y: hidden;
	overflow-y: scroll;
	margin-top: 0;
	margin-right: 0;
	margin-left: 0;
 }
 

.containerleft {
	text-align: center;
	width: 200px;
	height: 400px;
	float: left;
	padding-left: 100px;
 }

	.containerleft p {margin: 0;}

.containermiddle {
	text-align: center;
	width: 200px;
	height: 400px;
	float: left;
 }

	.containermiddle p {margin: 0;}

.containerright {
	text-align: center;
	width: 200px;
	height: 400px;
	float: left;
 }

	.containerright p {margin: 0;}

.copyright {
	font-size: 12px;
	font-weight: lighter;
	letter-spacing: 5px;
	padding-top: 10px;
 }
 
.discogmaincontainer {
	text-align: center;
	margin-left: auto;
	margin-right: auto;
	margin-top: 50px;
	padding: 5px;
	background-color: rgba(0,0,0,0.3);
	width: 800px;
	height: 700px;
	overflow: hidden;
	transition: 0.5s;
 }
 
  	.discogmaincontainer h5 {
		color: rgba(88,88,88,1.00);
		letter-spacing: 2px;
		font-size:10px;
		margin: 0;
		padding: 0;
		
	}


.discogcontainertop {
	text-align: center;
	display: inline-block;
	width: 750px;
	height: 220px;



}
	.discogcontainertop ul li {
		display: inline-block;
		margin-right: 20px;
		margin-left: 20px;

	}
	
	
.discogcontainermiddle {
	text-align: center;
	display: inline-block;
	width: 750px;
	height: 230px;


}

		.discogcontainermiddle ul li {
		display: inline-block;
		margin-right: 20px;
		margin-left: 20px;
	}

.discogcontainerbottom {
	text-align: center;
	display: inline-block;
	width: 750px;
	height: 250px;

}

		.discogcontainerbottom ul li {
		display: inline-block;
	}

#discogtoprow {
list-style-type: none;	
}

#discogmiddlerow {
list-style-type: none;	
}

#discogbottomrow {
list-style-type: none;
}

#discogbottomrow h{
	margin: 0;
	padding: 0;
	font-size: 14px;
	
}
.footer {
	color: #FFFFFF;
	position: fixed;
	text-align: center;
	left: 0px;
	bottom: 0px;
	height: 35px;
	width: 100%;
	background: #000000;
	z-index: 10;
 }

	.footer a {color: FFFFF;}

		.footer a:hover {color: #66D06B;}
		
		
.greetingscontainer {
	margin-left: auto;
	margin-right: auto;
	margin-top: 50px;
	padding: 10px;
	background-color: rgba(0,0,0,0.3);
	width: 800px;
	height: 700px;
	overflow: auto;
	transition: 0.5s;
 }
 
 .greetingscontainer a {
	color: #C36700; 
 }
 
 .greetingscontainer a:hover {
	color: #4B4B4B; 
	 
 }

h1 {
	letter-spacing: 10px;
	font-size: 46px;
	margin: 0;
	padding: 0;
	font-weight: 900;
 }

h2 {
	font-size: 12px;
	font-style: italic;
	font-weight: lighter;
 }

h3 {
	font-size: 18px;
	font-style: bold;
 }

h4 {font-size: 16px;}

h5 {
	font-size: 12px;
	font-weight: lighter;
	letter-spacing: 5px;
 }
 
h6 {
	font-size: 24px;
	margin: 0px;
	
}

h7 {
	font-size: 12px;
	margin: 0px;
}

.header {
	font-family: 'Source Sans Pro', sans-serif;
	font-weight: 900;
	text-align: center;
	transition: 0.5s;
	background-color: #000000;
	padding-top: 10px;
	width: 100%;
	
 }

	.header a {color: #FFFFFF;}

		.header a:hover {color: #FBA75F;}
		

.link {
	height: 68px;
	width: 88px;
	transition: 0.5s;
	padding: 0px;
 }

	.link:hover {
		-webkit-filter: brightness(50%);
		filter: brightness(50%);
		ms-filter: brightess(50%);
	 }
	 
.linkdiscog {
	text-align: center;
	height: 190px;
	width: 150px;
	transition: 0.5s;
	padding: 0px;
 }

	.linkdiscog:hover {
		-webkit-filter: brightness(50%);
		filter: brightness(50%);
		ms-filter: brightess(50%);
	 }

	 
.linkscontainer  {
	text-align: center;
	margin-left: auto;
	margin-right: auto;
	margin-top: 50px;
	padding: 10px;
	background-color: rgba(0,0,0,0.3);
	width: 800px;
	height: 480px;
	overflow: auto;
	transition: 0.5s;
 }
 
.linkscontainer h4 {
	font-size: 12px;
	font-weight: lighter;
	letter-spacing: 5px;
		
}
	


.linkscontainertop {
	text-align: center;
	display: inline-block;
	width: 750px;
	height: 137px;
	

 }

	.linkscontainertop ul li {
		display: inline-block;
			margin-right: 40px;
		margin-left: 40px;
		
		
		
}

.linkscontainermiddle {
	text-align: center;
	display: inline-block;
	width: 750px;
	height: 137px;
 }

	.linkscontainermiddle ul li {
		display: inline-block;
		margin-right: 40px;
		margin-left: 40px;
	
		
	 	
		
	}

.linkscontainerbottom {
	text-align: center;
	display: inline-block;
	width: 750px;
	height: 137px;
 }

		
		.linkscontainerbottom ul li {
		display: inline-block;
			margin-right: 40px;
		margin-left: 40px;
	 
		
	}


.maincontainer {
	margin-left: auto;
	margin-right: auto;
	margin-top: 50px;
	padding: 10px;
	background-color: rgba(0,0,0,0.3);
	width: 800px;
	height: 415px;
	overflow: auto;
	transition: 0.5s;
 }
 
 .maincontainer a {
	color: #C36700; 
 }
 
 .maincontainer a:hover {
	color: #4B4B4B; 
	 
 }
 
 .maincontainer2 {
	 text-align: center;
	margin-left: auto;
	margin-right: auto;
	padding: 10px;
	background-color: rgba(0,0,0,0.3);
	width: 800px;
	height: 210px;
 }

.mediacontainer {
	text-align: center;
	margin-left: auto;
	margin-right: auto;
	margin-top: 50px;
	padding: 10px;
	background-color: rgba(0,0,0,0.3);
	width: 800px;
	height: 700px;
	overflow: auto;
 }

	.mediacontainer div {
		display: inline-block;
		transition: 0.5s;
	 }

		.mediacontainer div:hover {
			-webkit-filter: brightness(50%);
			filter: brightness(50%);
			ms-filter: brightess(50%);
		 }

.nav {
	list-style-type: none;
	margin: 0;
	padding: 0;
	overflow: hidden;
	margin-left: auto;
	margin-right: auto;
	text-align: center;
	background-color: #000000;
 }

	.nav li {display: inline;}

	.nav a:link {
		display: inline-block;
		width: 120px;
		font-weight: lighter;
		color: #FFFFFF;
		background-color: #000000;
		text-align: center;
		padding: 4px;
		text-decoration: none;
		text-transform: uppercase;
		transition: 0.5s;
	 }
	 
	 .nav li a:focus {background-color: lightgreen;}

	.nav a:hover {background-color: #222222;}




.newscontainer {
	float: left;
	height: 380px;
	width: 400px;
	overflow: auto;
	margin-bottom: 20px;
 }

	.newscontainer a {
		color: rgba(185,109,0,1.00);
		transition: 0.5s;
	 }

		.newscontainer a:hover {color: rgba(66,66,66,1.00);}


#socialmedia {
	padding: 0px;
	
}
.socialmedia {
	list-style-type: none;
	float: right;
	background-color: #000000;
	padding: 0;
	margin: 0;
	bottom: 0px;
	z-index: 11;
	position: fixed;
	right: 10px;
 }

	.socialmedia li {display: inline;}

	.socialmedia a:link, a:visited {
		display: inline-block;
		width: 32px;
		color: #FFFFFF;
		background-color: #000000;
		transition: 0.5s;
	 }

	.socialmedia a:hover, .socialmedia a:active {background-color: #222222;}

.twitter-timeline {
	float: right;
	height: 380px;
	width: 300px !important;
 }
 
 #streaming {
	padding: 0px;
	
}

@media screen and (max-width: 480px) {
	
body {
	background-image: none !important;	
	overflow-x: hidden;
}

#boxes {
	display: none;
	
	
}

.containerleft {
	text-align: center;
	width: 200px;
	height: 280px;
	padding-left: 70px;

 }


.containermiddle {
	text-align: center;
	width: 200px;
	height: 250px;
	padding-left: 70px;
 }


.containerright {
	text-align: center;
	width: 200px;
	height: 250px;
	padding-left: 70px;
	padding-bottom:20px;
 }


.copyright {
	font-size: 12px;
	font-weight: lighter;
 }
 
 .discogmaincontainer {
	height: auto;
	width: 90%;
	padding-bottom: 40px;
	text-align: center;
}



		
.discogcontainertop {
	text-align: center;
	width: 200px;
	height: 280px;
	padding-left: 70px;
	float:left;

 }
 

 
 .discogcontainermiddle {
	text-align: center;
	width: 200px;
	height: 280px;
	padding-left: 70px;
	float:left;
	margin-top: 250px;

 }
 
 .discogcontainerbottom {
	text-align: center;
	width: 200px;
	height: 280px;
	padding-left: 70px;
	float:left;

 }

#EdgeID {
	margin-top: 30px;
	
}


.greetingscontainer {
	width: 90%;
	padding-bottom: 20px;
	
}


h1 {
	letter-spacing: 4px;
	font-size: 20px;
	margin: 0;
	padding: 0;
 }

.header {
	text-align: center;
	background-color: #000000;
	padding-bottom: 20px;
 }

	.header a {color: #FFFFFF;}

		.header a:hover {color: #FBA75F;}
		
		
.link {
	height: 68px;
	width: 88px;
	transition: 0.5s;
	padding: 0px;
	margin-bottom: 20px;
 }

	.link:hover {
		-webkit-filter: brightness(50%);
		filter: brightness(50%);
		ms-filter: brightess(50%);
	 }
			
.linkscontainer {
	height: auto;
	width: 90%;
	padding-bottom: 40px;
	
}

.linkscontainer h4 {
	font-size: 12px;
	font-weight: lighter;
	letter-spacing: 5px;
		
}
	
		
.linkscontainertop {
	text-align: center;
	width: 200px;
	height: 280px;
	padding-left: 70px;
	float:left;

 }
 


.linkscontainermiddle{
	text-align: center;
	width: 200px;
	height: 250px;
	padding-left: 70px;
	float:left;
	margin-top: 30px;
 }


.linkscontainerbottom {
	text-align: center;
	width: 200px;
	height: 250px;
	padding-left: 70px;
	margin-top: 60px;
	
	float:left;
 }
		
.maincontainer {
	height: auto;
	width: 90%;
	padding-bottom: 40px;
	
}

.maincontainer2 {
	height: auto;
	width: 90%;
	
}

.mediacontainer {
	text-align: center;
	margin-left: auto;
	margin-right: auto;
	margin-top: 50px;
	padding: 10px;
	background-color: rgba(0,0,0,0.3);
	width: 90%;
	height: 400px;
	overflow: auto;
 }
 
 

.newscontainer {
	
	height: 300px;
	width: 85%;
	margin-bottom: 20px;
	padding-right: 5px;
	padding-left: 60px;
	overflow-y: scroll;
}


p {
	font-size: 14px;	
	
}

.shoplink {
	width: 250px;
	height: 43px;
	display: none;
	
}

.socialmedia {
	display: none;
				
}

.twitter-timeline {
	float: left;
	padding-left: 10px !important; 
}

When I click on the 'news' link, the background changes to green for as long as I hold down the mouse button, but it doesn't stay green when on the active news page.

Any ideas what I should change so that the green link background remains while on the active page?

 

Many thanks for your time and help.

Give this a whirl

 

On the News page add an ID to the <body> tag

<body id="news">

Add a class to the <a> element in the nav

<li><a class="news" href="news.html">News</a></li>

Now add the following CSS

#news .news {
    background: lightgreen;
    border-bottom: 2px solid #fff;
    color: #000;
    font-weight: 700;
}

Now add an id to each page body tag eg:<body id="greet">, and a class to each link in the nav

<ul class="nav">
  <li><a class="news" href="news.html">News</a></li>
  <li><a class="greet" href="greetings.html">Greetings</a></li>
  <li><a class="music" href="music.html">Music</a></li>
  <li><a class="media" href="media.html">Media</a></li>
  <li><a class="blog" href="http://www.lylechristine.com/blog">Blog</a></li>
  <li><a class="links" href="links.html">Links</a></li>
</ul>

Then add the following CSS

#news .news, #greet .greet, #music .music, #media .media, #blog .blog, #links .links {
    background: lightgreen;
    border-bottom: 2px solid #fff;
    color: #000;
    font-weight: 700;
}

Adding the above styles to the focus event also adds a quite nice effect

.nav li a:focus {font-weight:700;background:lightgreen;color:#000;border-bottom:2px solid #fff;}

The CSS for the nav should then be like this

.nav {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
    background-color: #000000;
 }

    .nav li {display: inline;}

    .nav a:link {
        display: inline-block;
        width: 120px;
        font-weight: lighter;
        color: #FFFFFF;
        background-color: #000000;
        text-align: center;
        padding: 4px;
        text-decoration: none;
        text-transform: uppercase;
        transition: 0.5s;
     }
    
     .nav li a:focus {font-weight:700;background:lightgreen;color:#000;border-bottom:2px solid #fff;}
    
    .nav a:hover {background-color: #222222;}

     #news .news, #greet .greet, #music .music, #media .media, #blog .blog, #links .links
     {font-weight:700;background:lightgreen;color:#000;border-bottom:2px solid #fff;}

If you then want to add another page say a contact.html page. Just add id="contact" to the body tag. Add the <li> and link with class="contact" and then add the ID/Class pair to the CSS.

The method above will work fine, but there's a lot of additional classes and ID's needed, which only increases page size.

 

You can do this by adding a single class and styling against that:

<ul class="nav">
    <li><a href="/">Home</a></li>
    <li class="current"><a href="about.html">About</a></li>
    <li><a href="services.html">Services</a></li>
    <li><a href="contact.html">Contact</a></li>
</ul>

Then, in your CSS can do something along the lines of:

.nav .current {
    /* Active Styles Here */
}

Need any help with this, let me know!

Hmm, do you actually think the handful of bytes are going to cause that big a performance hit?

 

If your pages are so bloated that you need to start worrying about a few bytes of text/html and text/css you need to rethink your design strategies.

 

The method of using a single class on each element of the nav means you need to have as many versions of the nav as you have pages. Alright if you have four pages but it becomes a riddle if you have perhaps 16 pages.

 

Another benefit is that it can be called dynamically as an include and will work in each page. So you can have a simple page call nav.php or whatever you want that just contains

<ul class="nav">
  <li><a class="news" href="news.html">News</a></li>
  <li><a class="greet" href="greetings.html">Greetings</a></li>
  <li><a class="music" href="music.html">Music</a></li>
  <li><a class="media" href="media.html">Media</a></li>
  <li><a class="blog" href="http://www.lylechristine.com/blog">Blog</a></li>
  <li><a class="links" href="links.html">Links</a></li>
</ul>

Then include it in the page where required.

 

Plus if it's good enough for Eric Meyer it's good enough for me.

It may be a bit picky, but it's what I'm used to. In my job we have to keep page sizes to minimum, when all our clients (who pay us quite a sum of money) demand it. Just force of habit - less code, faster sites, happy clients, happy me :)

Edited by Ash Scott

i agree with nfc212: you'd be better spending your - and your client's - time shaving those bytes (or kb) off of images (then minifying css and possibly html then gzipping. ) sparing a few bytes for something that is harder to maintain is worth it.

The amount of time taken to download a few hundred extra bytes of data in what is essentially plain text is negligible even for a 2G connection.

 

Images and HTTP requests are the killers where download times are concerned. Using GZip on the HTML, CSS and Javascript resources will reduce their size by up to 80%

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.