Solved

Login button as two .png files

Posted on 2013-10-28
9
205 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

786 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