Solved

Login button as two .png files

Posted on 2013-10-28
9
209 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 350 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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 

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 150 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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

705 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