Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    New Coder
    Join Date
    Nov 2010
    Posts
    27
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Images Changing - Mouse Over

    I am also looking for a bit of help with regards to images changing when the mouse goes over them.

    E.g. When someone hovers (with their cursor) over a Contact Button ("photos/contact.png") image, it changes to another image darker colour ("photos/contact2.png")

    Can someone point me in the right direction with this? I dont seem to be getting anywhere

  • #2
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,333
    Thanks
    5
    Thanked 363 Times in 360 Posts
    You would create a second image like the first, but changing the color or whatever you wanted to be different about it, then set the style like so:

    a:hover{background-image: (myImagePath.gif);}

  • #3
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    If your image is a foreground image you can also change the opacity on hover, so that the background color blends with it. That way you only need the one image. For older versions of IE you need the 'filter' css code.

  • #4
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,673
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Hello davm22,
    I have a CSS rollover demo you can follow here.
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #5
    New Coder
    Join Date
    Nov 2010
    Posts
    12
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Here's where I learned how to do it.

    you can just change the "onClick" to "onMouseover"

  • #6
    New Coder
    Join Date
    Nov 2010
    Posts
    27
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks all, still doesnt work!

    Code:
    <div id="rollover1"><a href="index2.html"></div>
    then my external CSS file is:

    Code:
    #rollover1 a {
    display: block;
    height: 45px;
    width: 155px;
    background: url(photos/contact.png);
    }
    
    
    #rollover1 a hover {
    display: block;
    height: 45px;
    width: 155px;
    background: url(photos/rates.png);
    }
    The thing doesnt appear at all
    Last edited by davm22; 11-07-2010 at 08:06 PM.

  • #7
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,673
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Hard to say why without seeing all your code. When dealing with images, it's always best just to link us to the test site so we can see them.

    Code:
    #rollover1 a {
    display: block;
    height: 45;
    width: 155;
    background: url(photos/contact.png);
    }
    height and width both require some sort of measurement. Usually px?
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #8
    New Coder
    Join Date
    Nov 2010
    Posts
    27
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Excavator View Post
    Hard to say why without seeing all your code. When dealing with images, it's always best just to link us to the test site so we can see them.

    Code:
    #rollover1 a {
    display: block;
    height: 45px;
    width: 155px;
    background: url(photos/contact.png);
    }
    height and width both require some sort of measurement. Usually px?
    Sorry px is now included but the images still dont show, it does have the link now but its only the background colour

  • #9
    New Coder
    Join Date
    Nov 2010
    Posts
    27
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Im not cut out for this . I am trying to do a simpler navigation system bar where by its only text and no images. I have the following within my home page:

    Code:
    <div id="navbar">
    <ul>
    <li><a href="#home">Home</a></li>
    <li><a href="#news">News</a></li>
    <li><a href="#contact">Contact</a></li>
    <li><a href="#about">About</a></li>
    </ul>
    </div>
    The following is in my CSS file:

    Code:
    #navbar ul
    {
    list-style-type:none;
    margin:0;
    padding:0;
    overflow:hidden;
    }
    
    #navbar li {
    float:left;
    }
    
    #navbar a:link,a:visited
    {
    display:block;
    width:120px;
    font-weight:bold;
    color:#FFFFFF;
    background-color:#98bf21;
    text-align:center;
    padding:4px;
    text-decoration:none;
    text-transform:uppercase;
    }
    
    #navbar a:hover,a:active
    {
    background-color:#7A991A;
    }
    and everything works like it is supposed to as looked at here: http://www.w3schools.com/css/tryit.a...float_advanced.

    However, the </div> doesnt seem to stop it and the green background applies itself to my footer also which I dont want. Here is my footer:

    Code:
    <div id="footer">
    <a href="index.html">Home</a> | <a href="news.html">News</a> | <a href="contact.html">Contact</a> | <a href="about.html">About</a></div>
    and my CSS:

    Code:
    #footer a:link {
    font-weight: bold;
    text-decoration: underline;
    color: #ffffff;
    }
    
    #footer a:visited {
    font weight: bold;
    text-decoration: underline;
    color: #990000;
    }
    
    #footer a:hover {
    font-weight: bold;
    text-decoration: none;
    color: #ed1c24;
    background: #ffff00;
    }
    I would like these to stay separate and the green background not to appear on my footer also. Can someone help?

    Thanks again

  • #10
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    878
    Thanks
    0
    Thanked 114 Times in 113 Posts
    you have:
    Code:
    #navbar a:hover,a:active
    The rules will apply to a:hover within #navbar and all a:active within the document, including #footer.

    When separating with "," you are starting a hole new identifier

    you also have:
    Code:
    #navbar a:link,a:visited
    but since
    Code:
    #footer a:visited
    is more specific, this will be applied.

    change
    #navbar a:hover,a:active to #navbar a:hover,#navbar a:active
    and
    #navbar a:link,a:visited to #navbar a:link,#navbar a:visited

  • Users who have thanked Lerura for this post:

    davm22 (11-07-2010)

  • #11
    New Coder
    Join Date
    Nov 2010
    Posts
    27
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by lerura View Post
    you have:
    Code:
    #navbar a:hover,a:active
    The rules will apply to a:hover within #navbar and all a:active within the document, including #footer.

    When separating with "," you are starting a hole new identifier

    you also have:
    Code:
    #navbar a:link,a:visited
    but since
    Code:
    #footer a:visited
    is more specific, this will be applied.

    change
    #navbar a:hover,a:active to #navbar a:hover,#navbar a:active
    and
    #navbar a:link,a:visited to #navbar a:link,#navbar a:visited

    Thats it working now! Thanks a lot for that, Ill keep going until I encounter my next problem

  • #12
    New Coder
    Join Date
    Nov 2010
    Posts
    27
    Thanks
    4
    Thanked 0 Times in 0 Posts
    And Im back!

    Why does the above "Contact" etc on the navigation bar appear as capitals? I would like them to appear as I type them. e.g. "Contact".

    Is it due to me trying to use this font: Brush Script Std. Actually just tried it with Arial and it is capitalised also

  • #13
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,673
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Hello again davm22,
    Your off to a great start really - don't give up yet.

    When you specify an anchor like this #navbar a:link, a:visited { you apply the styling to both #navbar a:link and all visited a's.

    Does that make sense?

    Your CSS should look more like this:
    Code:
    		#navbar a:link, #navbar a:visited {
    			display: block;
    			width: 120px;
    			font-weight:bold;
    			color: #fff;
    			background: #98bf21;
    			text-align: center;
    			padding: 4px;
    			text-decoration: none;
    			text-transform: uppercase;
    		}
    That way it applies the styles to the visited anchor in #navbar only. Instead of all visited anchors like you originally had it.

    Have a look at this:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    html, body {
    	font: 100% "Comic Sans MS";
    	background: #FC6;
    }
    #container {
    	width: 800px;
    	margin: 30px auto;
    	background: #999;
    	overflow: auto;
    	font-size: 0.8em;
    }
    #navbar ul {
    	list-style-type: none;
    	margin: 0;
    	padding: 0;
    	overflow: hidden;
    }
    	#navbar li {float: left;}
    		#navbar a:link, #navbar a:visited {
    			display: block;
    			width: 120px;
    			font-weight:bold;
    			color: #fff;
    			background: #98bf21;
    			text-align: center;
    			padding: 4px;
    			text-decoration: none;
    			text-transform: uppercase;
    		}
    		#navbar a:hover, #navbar:active {background: #7A991A;}
    #footer {
    	text-align: center;
    	background: #ccc;
    	margin: 300px 0 0; /*delete this - it's just some top margin for display purposes*/
    }
    #footer a:link {
    	font-weight: bold;
    	text-decoration: underline;
    	color: #ffffff;
    }
    #footer a:visited {
    	font-weight: bold;
    	text-decoration: underline;
    	color: #990000;
    }
    #footer a:hover {
    	font-weight: bold;
    	text-decoration: none;
    	color: #ed1c24;
    	background: #ffff00;
    }
    </style>
    </head>
    <body>
    <div id="container">
        <div id="navbar">
            <ul>
                <li><a href="#home">Home</a></li>
                <li><a href="#news">News</a></li>
                <li><a href="#contact">Contact</a></li>
                <li><a href="#about">About</a></li>
            </ul>
        <!--end navbar--></div>
            <div id="footer">
                <a href="index.html">Home</a> | 
                <a href="news.html">News</a> | 
                <a href="contact.html">Contact</a> | 
                <a href="about.html">About</a>
            <!--end footer--></div>
      <!--end container--></div>
    </body>
    </html>
    Plenty of text only menus to look over here.



    p.s. The validator found an error or two in your CSS. Have a look at the links about validation in my sig below.
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #14
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,673
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Quote Originally Posted by davm22 View Post
    And Im back!

    Why does the above "Contact" etc on the navigation bar appear as capitals? I would like them to appear as I type them. e.g. "Contact".

    Is it due to me trying to use this font: Brush Script Std. Actually just tried it with Arial and it is capitalised also
    You're telling it to with text-transform: uppercase;
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #15
    New Coder
    Join Date
    Nov 2010
    Posts
    27
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Excavator View Post
    You're telling it to with text-transform: uppercase;
    I copied most of it from a website so I never noticed that or the bold, I have now amended it.

    Thanks for the post before the quoted reply also, very informative and I see what to do now. I have just started attempting to use HTML/CSS after buying a book and reading up on it a couple of days ago so Ive still got a long way to go yet.

    Really big help though, thanks a lot


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •