开发者

How do I create a Submit button mouseover?

开发者 https://www.devze.com 2023-01-05 14:19 出处:网络
I am creating an HTML contact form that uses a standard image for a submit button. Here is the html: <form action=\"#\">

I am creating an HTML contact form that uses a standard image for a submit button.

Here is the html:

<form action="#">
    <fieldset>
        <input type="text" name="name" value="FULL NAME" onfocus="if (this.value=='FULL NAME') this.value='';"/>
        <input type="text" name="" value="PHONE NUMBER" onfocus="if (this.value=='PHONE NUMBER') this.value='';"/>
        <input type="text" name="" value="EMAIL" onfocus="if (this.value=='EMAIL') this.value='';"/>
        <input type="text" name="" value="MOVE DATE" onfocus="if (this.value=='MOVE DATE') this.value='';"/>
        <input type="text" name="" value="ORIGINATING ADDRESS" onfocus="if (this.value=='ORIGINATING ADDRESS') this.value='';"/>
        <input type="text" name="" value="DESTINATION ADDRESS" onfocus="if (this.value=='DESTINATION ADDRESS') this.value='';"/>
        <select name="type">
            <option value="Private">Private</option>
            <option va开发者_JAVA百科lue="Commercial">Commercial</option>
        </select>
        <input id="quoteSubmit" type="image" src="_images/btn_submit.png" alt="" />
    </fieldset>
</form>

The static Submit button image is okay, but I would like change it on mouseover to btn_submit-over.png.

I am familiar with mouseovers useing css sprites, but they don't work for submit buttons. I would appreciate some help.

Thanks!


With pure CSS,

<input type="submit" value="::Submit Query::" id="foo" />

...

  #foo {
    background-image: url('_images/btn_submit.png');
    width: <width here>;
    height: <height here>;
    border-style: none;
    background-color: transparent;
    text-indent: 480px;    /* hack to hide the text */
  }

  #foo:hover {
    background-image: url('_images/btn_submit-over.png')
  }

If CSS is disabled it will revert to a simple submit button.

Demonstration: http://jsbin.com/aboxu3/2

You could then apply the CSS sprite techniques.


You can do this several ways... with jquery might be the best way, but this is how you do it without.

Change
<input id="quoteSubmit" type="image" src="_images/btn_submit.png" alt="" />

to
<input id="quoteSubmit" type="image" src="_images/btn_submit.png" alt="" onmouseover="javascript:this.src='_images/btn_submit-over.png'" onmouseout="javascript:this.src='_images/btn_submit.png'"/>

Just from the top of my head, I guess that should work.

Br, Paul


Classic solution (similar to Mitch's above):

For the HTML in the FORM, add a 'class':

<INPUT NAME="submit" class="submit" TYPE="submit" VALUE="Submit">   

For the CSS, make hover change text color (add 'width:' and 'height:' lines if you need to)

.submit {
text-decoration: none;
text-align: center;
border: 1px solid black;
background-color: #cccccc;
-moz-border-radius: 5px; /* I hate square buttons for mozilla*/
border-radius: 5px; /* I hate square buttons for everybody else*/
font-family: Arial,Helvetic1,Geneva,Swiss,SunSans-Regular;
font-size: 18px;
color: #0000aa; /* font is blue */
}

.submit:hover {
color: #ff0000; /* font changes to RED on hover) */
}


Wouldn't it be possible to use a class?

<input type="submit" class="submit" .../>

CSS:
input.submit:hover{
   color: Green;
} 

or you could use then a little JavaScript to handle the swapping of images and to cause the button to call submit() (javascript:document.theform.submit())


OldSchool:

        <a href="#" onclick="document.forms[0].submit(); return false"
onmouseover="document.subBut.src=document.subBut.src.replace('.png','over.png')"
onmouseout="document.subBut.src=document.subBut.src.replace('over.png','.png')"><img 
name="subBut" src="_images/btn_submit.png" alt="" border="0" /></a>


Basically this is what are you going to do:

HTML Markup:

<input type="submit" name="Submit" id="submit" value="&nbsp;" />

Notes: Create an ID for the CSS. In the "Value", put &nbsp; (the html markup for a blank space) and this will make the default "value" blank.

CSS Markup:

#submit {
width: 220px; 
height: 50px;
border: none;
background: url("images/submit.jpg") no-repeat; 
}
        #submit:focus {
        background: url("images/submit_over.jpg") no-repeat;    
        }

Notes: The width and height should be the width and height of your image. Then add border: none; to remove the default border that appears.

Hope this helps! Much simpler than any of the above answers.

0

精彩评论

暂无评论...
验证码 换一张
取 消