www.webdeveloper.com
Results 1 to 2 of 2

Thread: Change background image and text colour when hovering on an image link

  1. #1
    Join Date
    Oct 2010
    Posts
    1

    Change background image and text colour when hovering on an image link

    Hi. Really hoping someone can help me with this... I'll try and explain this as best I can(!)

    Basically I've got a page containing a block of 9 images, with each linking to a video clip. At the moment I've got the CSS coded so that whenever the mouse is hovered over the 'infobar' (at the bottom of each image) it goes from having a transparent background with black text to having a grey background with white text.

    What I'm trying to achieve is that same effect whenever the mouse is hovered over any part of the image and infobar.

    The CSS is as as follows:
    Code:
    /*
     *  Page Stylesheet 
     */
    body {
      font-family: Arial, Helvetica, sans-serif;
      background-color: #eaeaea;
      border:0; margin:0; padding:0;
      height: 100%;
    }
    a:link {
    	text-decoration: none;
    }
    a:visited {
    	text-decoration: none;
    }
    a:hover {
    	text-decoration: none;
    }
    a:active {
    	text-decoration: none;
    }
    #container {
    	margin-left: auto;
    	margin-right: auto;
       	min-height: 100%;
    	width: 936px;
    }
    * html #container {
    	height: 100%;
    }
    #content {
    	float:left;
    	position: relative;
    	height: 528px;
    	width: 936px;
    	z-index: 0;
    }
    .miniscreen1, .miniscreen2, .miniscreen3, .miniscreen4, .miniscreen5, .miniscreen6, .miniscreen7, .miniscreen8, .miniscreen9 {
    	position: absolute;
    	float: left;
    	display: block;
    	width: 312px;
    	height: 176px;
    }
    .miniscreen1 {
    	top: 0;
    	left: 0;
    }
    .miniscreen2 {
    	top:0;
    	left: 312px;
    }
    .miniscreen3 {
    	top: 0;
    	left: 624px;
    }
    .miniscreen4 {
    	left: 0;
    	top:176px;
    }
    .miniscreen5 {
    	left: 312px;
    	top:176px;
    }
    .miniscreen6 {
    	left: 624px;
    	top:176px;
    }
    .miniscreen7 {
    	left: 0;
    	top:352px;
    }
    .miniscreen8 {
    	left: 312px;
    	top:352px;
    }
    .miniscreen9 {
    	left: 624px;
    	top:352px;
    }
    .info {
    	height: 30px;
    	top:3px;
    	left: 40px;
    	width: 265px;
    	float: left;
    	position: absolute;
    }
    .infobar  {
    	left:0px;
    	position: absolute;
    	top: 140px;
    	width: 312px;
    	height: 36px;
    	outline: none;
    	color:#000;
    	background: url("data/infobar.png") no-repeat 0 0;
    	z-index: 650;
    }
    .infobar:hover  { 
    	background-position: 0 -36px;
    	outline: none;
    	color:#fff;
    }
    #infobar span {
    	display: none;
    	outline: none;
    }
    .clip_title {
    	outline: none;
    	font-size: 85%;
    	font-weight: 700;
    	vertical-align: top;
    	text-align: left;
    }
    .clip_sub {
    	outline: none;
    	height: 13px;
    	font-size: 80%;
    	line-height: 13px;
    	font-weight: 700;
    	vertical-align: top;
    	text-align: left;
    }
    And the HTML is:
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <html>
    	<head>
    		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    		<title>Test Page</title>
    		<meta name="description" content=" " />
    		<meta name="keywords" content=" " />
    		<meta name="generator" content=" " />
    		<link rel="stylesheet" type="text/css" href="page.css" media="screen" />
    	</head>
    <body>
    
    <div id="container">
    
    	<div id="content">
    		<span class="miniscreen1">			
    		<a href="#"> <img src="img/clip1.jpg" width="312" height="176" border="0">
    		<span class="infobar"><span class="info clip_title">Test Clip 1<br><span class="clip_sub">123 Productions</span></span></span></a>
    		</span></span>
    					
    		<span class="miniscreen2">
    		<a href="#"><img src="img/clip2.jpg" width="312" height="176" border="0">
    		<span class="infobar"><span class="info clip_title">Test Clip 2<br><span class="clip_sub">123 Productions</span></span></span></a>
    		</span></span>
    		
    		<span class="miniscreen3">
    		<a href="#"><img src="img/clip3.jpg" width="312" height="176" border="0">
    		<span class="infobar"><span class="info clip_title">Test Clip 3<br><span class="clip_sub">123 Productions</span></span></span></a>
    		</span></span>
    			
    		<span class="miniscreen4">
    		<a href="#"><img src="img/clip4.jpg" width="312" height="176" border="0">
    		<span class="infobar"><span class="info clip_title">Test Clip 4<br><span class="clip_sub">123 Productions</span></span></span></a>
    		</span></span>
    	
    		<span class="miniscreen5">
    		<a href="#"><img src="img/clip5.jpg" width="312" height="176" border="0">
    		<span class="infobar"><span class="info clip_title">Test Clip 5<br><span class="clip_sub">123 Productions</span></span></span></a>
    		</span></span>
    	
    		<span class="miniscreen6">
    		<a href="#"><img src="img/clip6.jpg" width="312" height="176" border="0">
    		<span class="infobar"><span class="info clip_title">Test Clip 6<br><span class="clip_sub">123 Productions</span></span></span></a>
    		</span></span>
    	
    		<span class="miniscreen7">
    		<a href="#"><img src="img/clip7.jpg" width="312" height="176" border="0">
    		<span class="infobar"><span class="info clip_title">Test Clip 7<br><span class="clip_sub">123 Productions</span></span></span></a>
    		</span></span>
    	
    		<span class="miniscreen8">
    		<a href="#"><img src="img/clip8.jpg" width="312" height="176" border="0">
    		<span class="infobar"><span class="info clip_title">Test Clip 8<br><span class="clip_sub">123 Productions</span></span></span></a>
    		</span></span>
    	
    		<span class="miniscreen9">
    		<a href="#"><img src="img/clip9.jpg" width="312" height="176" border="0">
    		<span class="infobar"><span class="info clip_title">Test Clip 9<br><span class="clip_sub">123 Productions</span></span></span></a>
    		</span></span>
    				
    	</div>
    </div>
    	
    </body>
    </html>
    There must be a better (and easier?) way to do this. Any help would be very-much appreciated - and save an old bloke from tearing too much of his hair out(!)

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    /*
     *  Page Stylesheet 
     */
    body {
      font-family: Arial, Helvetica, sans-serif;
      background-color: #eaeaea;
      border:0; margin:0; padding:0;
      height: 100&#37;;
    }
    a:link, a:visited, a:hover, a:active {
    text-decoration: none;
    }
    #content {
    padding:0;
    margin: auto;
    min-height: 100%;
    width: 936px;
    }
    #content li {
    float:left;
    list-style:none;
    }
    #content a {
    position:relative;
    display:block;
    width:312px;
    height:176px;
    }
    #content a:hover span {
    color:#fff;
    background-color:#ccc;
    }
    #content a span {
    position:absolute;
    display:inline-block;
    top:130px;
    left:20px;
    font-size: 80%;
    font-weight: 700;
    color:#000;
    }
    .miniscreen1 {
    background:transparent url(img/clip1.jpg) no-repeat;
    }
    .miniscreen2 {
    background:transparent url(img/clip2.jpg) no-repeat;
    }
    .miniscreen3 {
    background:transparent url(img/clip3.jpg) no-repeat;
    }
    .miniscreen4 {
    background:transparent url(img/clip4.jpg) no-repeat;
    }
    .miniscreen5 {
    background:transparent url(img/clip5.jpg) no-repeat;
    }
    .miniscreen6 {
    background:transparent url(img/clip6.jpg) no-repeat;
    }
    .miniscreen7 {
    background:transparent url(img/clip7.jpg) no-repeat;
    }
    .miniscreen8 {
    background:transparent url(img/clip8.jpg) no-repeat;
    }
    .miniscreen9 {
    background:transparent url(img/clip9.jpg) no-repeat;
    }
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <title>Test Page</title>
            <meta name="description" content=" " />
            <meta name="keywords" content=" " />
            <meta name="generator" content=" " />
            <link rel="stylesheet" type="text/css" href="page.css" media="screen" />
        </head>
    <body>
    
        <ul id="content">
            <li><a href="#" class="miniscreen1"><span>Test Clip 1<br />123 Productions</span></a></li>
            <li><a href="#" class="miniscreen2"><span>Test Clip 2<br />123 Productions</span></a></li>
            <li><a href="#" class="miniscreen3"><span>Test Clip 3<br />123 Productions</span></a></li>
            <li><a href="#" class="miniscreen4"><span>Test Clip 4<br />123 Productions</span></a></li>
            <li><a href="#" class="miniscreen5"><span>Test Clip 5<br />123 Productions</span></a></li>
            <li><a href="#" class="miniscreen6"><span>Test Clip 6<br />123 Productions</span></a></li>
            <li><a href="#" class="miniscreen8"><span>Test Clip 7<br />123 Productions</span></a></li>
            <li><a href="#" class="miniscreen8"><span>Test Clip 8<br />123 Productions</span></a></li>
            <li><a href="#" class="miniscreen8"><span>Test Clip 9<br />123 Productions</span></a></li>
        </ul>
        
    </body>
    </html>
    At least 98% of internet users' DNA is identical to that of chimpanzees

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles