Twitter-style login with jQuery & CSS3
- February 27, 2010
- Javascript & AJAX
- jQuery
- Tutorials
Following my posting of the Twitter-style confirmation message with jQuery method, I thought it would be fun to recreate the Twitter login form. It's actually pretty straightforward and took me about a half hour to develop. Using a splash of jQuery to toggle the form and some CSS3 to apply the design you can implement a similar approach on your own web site.
As you can see via the markup & code below, the jQuery is ridiculously simple, as is the XHTML. The real fun comes with the CSS, which uses some CSS3 for rounded corners and the text shadow effect on the login button.
Yes, it works across all browsers...except IE6 (big whoop) and IE7/8 does not apply the CSS3.
I have not integrated a database and login function in the demo but if you'd like to see one, post a comment and if the demand warrants it, I'll whip one up for y'all.
The XHTML markup:
<!-- I USED THE DEMO DIV TO CENTER-ALIGN ON THE PAGE --> <div id="demo"> <!-- THE LOGIN WRAPPER FLOATS TO THE RIGHT WITHIN THE DEMO DIV AND HOLDS THE BUTTON AND HIDDEN FORM TO ENSURE ALIGNMENT --> <div id="loginWrapper"> <!-- BEGIN LOGIN BUTTON --> <div id="loginButton"> <a href="#">Sign in</a> </div> <!-- END LOGIN BUTTON --> <!-- BEGIN HIDDEN FORM --> <div id="loginForm"> <form action="#" method="#"> <fieldset> <label for="usernameOrEmail">Username or email:</label> <input type="text" id="usernameOrEmail" class="textfield" /> <label for="pass">Password:</label> <input type="password" id="pass" class="textfield" /> <input type="submit" value="Sign in" class="loginButton" /> <input type="checkbox" id="rememberMe" class="checkBox" /> Remember me </fieldset> </form> <ul> <li><a href="#">Forgot your password?</a></li> <li><a href="#">Forgot your username?</a></li> <li><a href="#">Already using Twitter on your phone?</a></li> </ul> </div> <!-- END HIDDEN FORM --> </div> </div>
The jQuery:
$(document).ready(function(){
// Toggle the login form
$("#loginButton").click(function() {
$("#loginForm").toggle();
$("#loginButton a").toggleClass("active");
return false;
});
});
Pretty it up with some CSS:
#demo { /* CENTERS THE DIV CONTAINING THE ELEMENTS */
width: 980px;
height: 20px;
margin: 0 auto;
padding: 20px 0 0 0;
}
#loginWrapper { /* WRAPS THE BUTTON AND LOGIN FORM FOR ALIGNMENT PURPOSES */
float: right;
width: 230px;
height: auto;
}
#loginButton {
float: right;
width: 80px;
height: 30px;
}
#loginButton a {
display: block;
font-size: 0.9em;
font-weight: bold;
line-height: 30px;
text-align: center;
color: #fff;
text-decoration: none;
padding: 0 22px 0 0;
background: #88bbd4 url(../img/loginSprite.png) 0px 0px no-repeat;
cursor: pointer;
border: 1px solid #88bbd4;
-moz-border-radius: 6px;
-webkit-border-radius: 6px;
border-radius: 6px;
outline: none;
}
#loginButton a:hover {
color: #fff;
background: #5599bb url(../img/loginSprite.png) 0px -30px no-repeat;
}
#loginButton a.active {
color: #477;
border: 1px solid #ddeef6;
background: #ddeef6 url(../img/loginSprite.png) 0px -60px no-repeat;
-moz-border-radius: 6px;
-webkit-border-radius: 6px;
border-radius: 6px;
-moz-border-radius-bottomright: 0px;
-webkit-border-bottom-right-radius: 0px;
-moz-border-radius-bottomleft: 0px;
-webkit-border-bottom-left-radius: 0px;
}
/* THIS IS THE HIDDEN FORM */
#loginForm {
position: fixed;
width: 200px;
font-size: 0.8em;
color: #477;
margin: 32px 0 0 0;
padding: 15px;
background: #ddeef6;
-moz-border-radius-topleft: 6px;
-webkit-border-top-left-radius: 6px;
-moz-border-radius-bottomleft: 6px;
-webkit-border-bottom-left-radius: 6px;
-moz-border-radius-bottomright: 6px;
-webkit-border-bottom-right-radius: 6px;
display: none;
}
#loginForm ul {
margin: 0;
padding: 0;
list-style: none;
}
#loginForm ul li {
margin: 0;
padding: 0;
}
#loginForm ul li a {
display: block;
color: #27b;
text-decoration: none;
padding: 6px 0;
}
#loginForm ul li a:hover {
color: #27b;
text-decoration: underline;
}
#loginForm form,fieldset {
margin: 0;
padding: 0;
border: 0;
}
#loginForm label {
display: block;
margin: 0 0 5px 0;
}
.textfield {
display: block;
width: 186px;
font: 1.2em arial;
color: #000;
margin: 0 0 10px 0;
padding: 6px;
background: #fff;
border: 1px solid #0bacea;
}
.loginButton {
font: bold 1.1em tahoma;
color: #fff;
margin: 0 0 10px 0;
padding: 5px;
background: #33bef6 url(../img/loginButtonBackgr.png) repeat-x;
border: 1px solid #0bacea;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
text-shadow: 1px 1px 1px #044660;
}
.checkBox {
vertical-align: middle;
}
Stay well.













Really amazing stuff.. great login control. Thankx for the code. this is a help help for my web designing applications
Sheena Rai
Website Designing Team Technetto
Posted: March 4, 2010
Thanks, Sheena :)
Posted: March 4, 2010
I like the way you describe that.
Thanks !
Posted: March 5, 2010
Very impressive. An additional to my knowledge.
Posted: August 3, 2010