Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Login button as two .png files

Posted on 2013-10-28
9
Medium Priority
?
211 Views
Last Modified: 2013-11-04
I have a login button that is two png files. I want Login1.png to be shown as standard, but when one press it, it should flip to  Login2.png, and thow do one handle that? Javascript?

Also, I want the text "Login" on top of the button.
0
Comment
Question by:mdoland
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 39607934
Yes, Javascript is one way you could do it. e.g.
<!DOCTYPE html>
<html>
<head>
	<style>
		.btnLogin1 {background-image:url('image1.png');font-size:"16px";}
		.btnLogin2 {background-image:url('image2.png');font-size:"16px";}
	</style>
	<script type="text/javascript">
		function login(btn) {
			btn.className="btnLogin2";
			
		}
	</script>
</head> 
	<p>
		Example of button with background changing once clicked<br>
		<input type="button" id="btnLogin" class="btnLogin1" value="Login" onclick="login(this)">
	</p>

<body>
    
</body>
</html>

Open in new window

0
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 39607937
I'll do it with colors you just need to change it to background-image.
<input id="btn" type="button" class="myButton" value="Click me!" />

Open in new window

.myButton{
    background-color: #f00;
}

.myButton:active{
    background-color: #0f0;    
}

Open in new window

Basically the idea is to use the :active pseudo selector to style your button when it's down.
0
 
LVL 14

Accepted Solution

by:
Pierre Cornelius earned 1400 total points
ID: 39607964
Alex and I have 2 different approaches. The question here is what do you need?

Do you want to show image 2
1) while the button is being pressed and revert to image1 when it is no longer pressed?
2) do you want to change to image2 after the button has been pressed and stay as image2 after it has been pressed

if (1), then the active css pseudo is the way to go. My example would then change as follows:
<!DOCTYPE html>
<html>
<head>
	<style>
		.btnLogin {background-image:url('image1.png');}
		.btnLogin:active {background-image:url('image2.png');}
	</style>
</head> 
	<p>
		Example of button with background changing once clicked<br>
		<input type="button" id="btnLogin" class="btnLogin" value="Login">
	</p>

<body>
    
</body>
</html>

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mdoland
ID: 39608192
Ok, it is the going back version I'm looking for. My problem is that the button is very wide. It's all over the screen.
0
 

Author Comment

by:mdoland
ID: 39608488
Also, a pressed button should also create a submit.
0
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 39608518
if you want a submit instead of just plain button use:
<input type="submit" id="btnLogin" class="btnLogin" value="Login">
0
 

Author Comment

by:mdoland
ID: 39613885
The submit works, but the look of the button is strange. First of all, it goes from the left to the right side of the browser and looks like it multiple-produces the button.

Also, the color does not work. Could it be that I should use some z-parameter on it? I think there already is a background on the page and maybe that is the one that messes this up.
button-pressed.jpg
login-page.png
0
 
LVL 30

Assisted Solution

by:Alexandre Simões
Alexandre Simões earned 600 total points
ID: 39613930
Do you have a width:100% set on the button?
Is that really a button? That looks more like the behavior of a div.

Can you give me the html of that login area?

And make sure you're only using the css classes like I told you above.
No javascript is necessary to accomplish what you need.
0
 
LVL 58

Expert Comment

by:Gary
ID: 39614292
Why don't you just post your code andcss instead of making everyone play a guessing game.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

610 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