Solved

Login button as two .png files

Posted on 2013-10-28
9
201 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
  • 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
 

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

706 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

18 Experts available now in Live!

Get 1:1 Help Now