?
Solved

Login button as two .png files

Posted on 2013-10-28
9
Medium Priority
?
210 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

770 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