Skip to main content
Dewan9598
Known Participant
August 6, 2018
Answered

a hover not working

  • August 6, 2018
  • 2 replies
  • 4533 views

What I am doing wrong. This has worked everytime. Not this time though. Checked online, no errors.

At the head section, I have declared the properties:for a

a   { text-decoration:none; }

a:link  { color:#000000; }

a:visited { color:#000000; }

a:active { color:coral; }

a:focus  { color:coral; }

a:hover  { color:coral; }

At the individual div level:

#topnav {
font-size: 18px;
border-top: 2px #333 solid;
border-bottom: 2px #333 solid;
margin: 10px 0;
padding: 5px 10px;
}

#topnav ul li {display: inline; padding: 5px 15px;}

#topnav ul li:hover { background-color: #333;}

#topnav ul li:hover a {   color:coral; }

The background color changes but not the font color on hover, active of focus.

This topic has been closed for replies.
Correct answer Jon Fritz

Here is the html code followed by CSS code. Just to add. the background color changes on hover to 333on for the topnav (or bottomnav, which essentially is the same), however, the font color does not change from black to coral and that is the problem. I have tried other colors. I never had a problem with code like this before.

<!doctype html>
<html>

<head>
<meta charset="utf-8">
<title>The Enigmatic Brain Reveals</title>
<link href="css/styles.css" rel="stylesheet" type="text/css" media="screen">

<!--start Google analytics code-->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i=i||function(){
  (i.q=i.q||[]).push(arguments)},i.l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-70459726-1)', 'auto');
  ga('send', 'pageview');

</script>

<!--end Google analytics code-->
</head>
<body>
  <div id="outer">
<div id="wrapper">
  <div id="logo">
   <img src="images/sitephotos/logo.jpg" alt="logo" />
  </div><!--logo-->
  <div id="icon">
   <ul>
    <li><img src="images/sitephotos/link2.png" alt "photography site" /></li>
    <li><img src="images/sitephotos/link1.png" alt="book site" /></li>
   </ul>
  </div><!--icon-->
  <div id="topnav">
   <ul>
    <li>Home</li>
    <li>Book</li>
    <li>Excerpt</li>
    <li>About</li>
    <li>Contact</li>
   </ul>
  </div><!--topnav-->
  <div id="banner">
   <img src="images/banner/banner1.jpg" alt="banner" />
  </div><!--banner-->
  <div id="content">
   <h2>Main Heading</h2>
   <p>placeholder</p>
  </div><!--contemnt-->
  <div id="links">
   <ul>
    <li><img src="images/sitephotos/button2.png"  alt="link" /></li>
    <li><img src="images/sitephotos/button1.png" alt="link" /></li>
   </ul>

  </div><!--links-->
  <div id="bottomnav">
   <ul>
    <li>Home</li>
    <li>Book</li>
    <li>Excerpt</li>
    <li>About</li>
    <li>Contact</li>
   </ul>
  </div><!--bottomnav-->
  <div id="footer">
   <p>Copyright &copy; Dewan Jaglul. All rights reserved.</p>
  </div><!--footer-->
</div><!--wrapper-->
  </div><!--outer-->
</body>
</html>

/* CSS Document */

* {margin: 0px; padding: 0px; border: 0px; }
body  {
font-family: "Arial", "Cambria", "Candara", "Hoefler Text", "Liberation Serif",  "serif",  "Tahoma", "Times", "Times New Roman" ;
color: black;
}
html {
background-image: url(../images/sitephotos/background.jpg);
background-attachment: fixed;
background-position: center center;
    background-repeat: no-repeat;
    background-size: cover;
}

a   { text-decoration:none; }
a:link  { color:#000000; }
a:visited { color:#000000; }
a:active { color:coral; }
a:focus  { color:coral; }
a:hover  { color:coral; }

/* text elements*/

h2  { margin-bottom: 10px; }

p  { margin-bottom: 10px;
line-height: 150%;
}

/* containers*/
#outer {
width:1044px;
margin: auto;
background-color:#333;
padding: 10px 0;
}
#wrapper {
width:990px;
background-color:coral; }
#wrapper { margin: 8px auto; }

#logo {
overflow: hidden; }

#icon {
margin: 20px;
padding: 10px;
border: 5px coral solid;
}

#icon ul li {display: inline; padding: 0px 10px;}

#topnav {
font-size: 18px;
border-top: 2px #333 solid;
border-bottom: 2px #333 solid;
margin: 10px 0;
padding: 5px 10px;
}

#topnav ul li {display: inline; padding: 5px 15px;}

#topnav ul li:hover { background-color: #333;}

#topnav ul li:hover a {   color:red; }

#banner {
width: 980px;
    height: 326px;
margin: 0 auto;
overflow: hidden;
}

#content {
padding: 10px;
}

#links {
margin: 20px;
padding: 10px;
border: 5px coral solid;
}

#links ul li {display: inline; padding: 0 53px;}

#bottomnav {
font-size: 18px;
border-top: 2px #333 solid;
border-bottom: 2px #333 solid;
margin: 10px 0;
padding: 5px 10px;
}
#bottomnav ul li {display: inline; padding: 5px 15px;}

#bottomnav ul li:hover { background-color: #333;}

#bottomnav ul li:hover a:  {   color: coral}

#footer  {
border-top: 2px #333 solid;
}
#footer p {
text-align: center;
font-style: italic;
padding: 10px 0;
}


You have no <a> tags in your menus, your selectors won't work until they're added in.

2 replies

Jon Fritz
Community Expert
Community Expert
August 7, 2018

Your code as written above works fine, if your html structure matches what you're trying to target with the css.

Could you share your actual HTML so we can see where the mismatch is between your html structure and your css selectors?

Dewan9598
Dewan9598Author
Known Participant
August 7, 2018
As I have already mentioned, the code works in three other websites I had built on DW. I cannot understand why It won’t work this time. Here is the html code that pertains to the topnav.



    • Book

    • Excerpt

    • About

    • Contact



<!topnav>
Jon Fritz
Community Expert
Community Expert
August 7, 2018

Don't send code via email reply, it doesn't come through in the forum.

Use a web browser so you can copy/paste the code here, or post a link to your work in progress.

Legend
August 6, 2018

Check that there is actually a color named coral would be my initial thoughts.......as a test replace it with red and see if it works.

The css below should work without the necessity to include ul li:

#topnav a:hover {

color: coral;

}

Dewan9598
Dewan9598Author
Known Participant
August 6, 2018

I tried with other colors as well as without ul li. This code works for three other sites I have built but for some reason not for this one.

John Waller
Community Expert
Community Expert
August 7, 2018

Got a link to the site?