color on a div tag 100points, simple

Posted on 2004-11-19
Last Modified: 2011-08-18
I have a simple div tag that makes a black square on the screen... How would I make it so that when I mouse over it changes to a different color
Question by:puotta

    Author Comment

    <div style="position: absolute; left: 100px; top: 30px; width: 45px; height: 45px; background-color: rgb(0, 0, 0);"></div>
    LVL 5

    Accepted Solution

    <div style="background-color: black" onmouseover=" 'red'">


    <div style="position: absolute; left: 100px; top: 30px; width: 45px; height: 45px; background-color: rgb(0, 0, 0);" onmouseover=" = rgb(255,255,255)"></div>

    To change it back, use onmouseout
    LVL 49

    Expert Comment

    When you are planning to do more that just the backgroundcolor it could be wise just to use classed. This keeps things orderly also, and shortens the javascript onmouse.. in your html:

    <style type="text/css">
    .divNormal {background-color:black;}
    .divHover   {background-color:red;}

    <div class="divNormal" onmouseover="this.className='divHover';" onmouseout="this.className='divNormal';">


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Article by: Matthew
    I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
    The viewer will learn how to dynamically set the form action using jQuery.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now