Skip to main content
BenSCR
Inspiring
Jan 13, 2021 9:21 PM UTC
Question

Hover (Change colour of RollOver)

How can I change the colour of a RollOver during Hover, when I press the word 'Portfolio' so it changes from "White" to "Yellow" when touched.

 

Where about in the below code would I add the Hover/RollOver for colour change?

 

<!DOCTYPE html>
<html><head>
<meta charset="UTF-8">
<title>Ben</title>
 
<style>
img {
  display: block;
  margin-left: auto;
  margin-right: auto;
 
}
h1 {
  background-color: ;
  color: white;
}
 
h2 {
  background-color: ;
  color: white
}
 
body {
font-family: 'DotMatrix',sans-serif, sans-serif;
font-size: 7px;
color: #000;
position: relative;
line-height: 24px;
line-height: 1.5em;
background: #000;
 
-webkit-font-smoothing: antialiased;
 
 
</style>
</head>
<body>
 
<style>A {text-decoration: none;} </style>
 
<a href="Ben.html" >
<h1>PORTFOLIO</h1>
</a>
<h1>ABOUT</h1>
 
 <img src="NIKE Air Tailwind 79.jpg"/"NIKE" width="229" style="width:37%">
 
</body>
</html>
 
 
 
    This topic is closed to new replies. Start a new post to keep the conversation going.

    12 replies

    Nancy OShea
    Community Expert
    Community Expert
    Jan 14, 2021 12:39 AM UTC

    It goes without saying that HOVER has no effect on touch screen devices which the majority of site visitors are using these days. So more than half of users will probably never see the a:hover effect. 

     

    Experienced developers would NEVER waste precious heading tags on navigation.  <h1> headings are intended for the most important keywords on your page.  That's usually your site or business name, not navigation links.  Also <h1> is rarely if ever used more than 1 x per page.

     

    The way you structure content in the markup is ranked by search engines.  And since search engines drive traffic to your site, you want to get this right the first time. Google's SEO starter guide is a MUST READ for anyone new to building web sites.

    https://developers.google.com/search/docs/beginner/seo-starter-guide

     

    Below is a quick code example to get you started in the right direction.

     

     

     

    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>Ben's Awesome Portfolio ~ since 2021 </title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
    * { box-sizing: border-box; }
    body {
    width: 96%;
    margin: 0 auto;
    font-family: Consolas, "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", Monaco, "Courier New", "monospace";
    background: #222;
    color: antiquewhite;
    /**scale fonts to fit any size screen**/
    font-size: calc(14px + 1vw);
    line-height: calc(1.2em + 1.5vw);
    }
    header img {
    vertical-align: baseline;
    margin: 0 auto;
    max-width: 100%;
    }
    nav li {
    list-style-type: none;
    text-align: right;
    font-size: 1.75rem;
    text-transform: uppercase;
    letter-spacing: 0.16rem;
    line-height: 1;
    }
    nav li a {
    color: #FFF;
    font-weight: bold;
    text-decoration: none;
    }
    nav li a:hover, 
    nav li a:active, 
    nav li a:focus {
    color: yellow;
    text-decoration: underline;
    }
    </style>
    </head>
    
    <body>
    <header>
    <nav>
    <ul>
    <li><a href="#">Home</a></li>
    <li><a href="#">About</a></li>
    <li><a href="#">Contact</a></li>
    </ul>
    </nav>
    <h1>Ben's Awesome Portfolio</h1>
    <h2>Home Page</h2>
    <img src="https://dummyimage.com/1200x400" alt="placeholder">
    </header>
    <main>
    <h3>Heading 3</h3>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam magnam, praesentium asperiores. Et temporibus facilis, vel aliquam nostrum nam distinctio iure nisi consequuntur minus ea explicabo voluptate quo debitis. Fugiat!</p>
    <hr>
    <h3>Heading 3</h3>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam magnam, praesentium asperiores. Et temporibus facilis, vel aliquam nostrum nam distinctio iure nisi consequuntur minus ea explicabo voluptate quo debitis. Fugiat!</p>
    <hr>
    <h3>Heading 3</h3>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam magnam, praesentium asperiores. Et temporibus facilis, vel aliquam nostrum nam distinctio iure nisi consequuntur minus ea explicabo voluptate quo debitis. Fugiat!</p>
    </main>
    <hr>
    <footer>
    <p>© 2021 all rights reserved by XYZ Website</p>
    </footer>
    </body>
    </html>
    

     

     

     

     

    Translate
    Nancy O'Shea— Product User & Community Expert
    BenSCR
    BenSCRAuthor
    Inspiring
    Jan 14, 2021 12:31 PM UTC

    Thanks for this information etc.

     

    Do you know of a good beginners guide book (or web forum) to making a website with HTML/CCS

    Translate
    BenSCR
    BenSCRAuthor
    Inspiring
    Jan 14, 2021 12:34 PM UTC

    I bascially want to make a basic web page that looks like this...

    Translate
    Legend
    Jan 13, 2021 9:29 PM UTC

    Just add the below to your css styles, insert between the css <style> </style> block.

     

    a:hover {

    color: yellow;

    }

     

    This will turn every link on your page yellow on hover.

     

    If you only want a set of specific links in a specific <div> to turn yellow on hover you would target only that div:

     

    .myDivName a:hover {

    color: yellow;

    }

     

    Translate
    BenSCR
    BenSCRAuthor
    Inspiring
    Jan 13, 2021 10:31 PM UTC

    I'm not sure what I'm doing wrong, as it's not working.

     

    Do I create a separate <style></style> or add it to to the already existing style in my HTML

     

    <!DOCTYPE html>
    <html><head>
    <meta charset="UTF-8">
    <title>Ben</title>
     
    <style>
    img {
      display: block;
      margin-left: auto;
      margin-right: auto;
     
    }
    h1 {
      background-color: ;
      color: white;
    }
     
    h2 {
      background-color: ;
      color: white
    }
     
    body {
    font-family: 'DotMatrix',sans-serif, sans-serif;
    font-size: 7px;
    color: #000;
    position: relative;
    line-height: 24px;
    line-height: 1.5em;
    background: #000;
     
    -webkit-font-smoothing: antialiased;

     

    a:hover {

    color: yellow;

    }

    </style>
    </head>
    <body>
     
    <style>A {text-decoration: none;} </style>
     
    <a href="Ben.html" >
    <h1>PORTFOLIO</h1>
    </a>
    <h1>ABOUT</h1>
     
     <img src="NIKE Air Tailwind 79.jpg"/"NIKE" width="229" style="width:37%">
     
    </body>
    </html>
     
    Translate
    Legend
    Jan 13, 2021 10:45 PM UTC

    Well your body css is missing a closing } see in red below:

     

    body {
    font-family: 'DotMatrix',sans-serif, sans-serif;
    font-size: 7px;
    color: #000;
    position: relative;
    line-height: 24px;
    line-height: 1.5em;
    background: #000;

    -webkit-font-smoothing: antialiased;

    }

     

    a:hover {

    color: yellow;

    }

     

     

     

    You dont want links surrounded by <h1></h1> tags, reserve heading tags for headers.

     

    Try:

     

    <a href="Ben.html" >PORTFOLIO</a>

    Translate