<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>AjaxMasters Blog &#187; form</title> <atom:link href="http://blog.ajaxmasters.com/tag/form/feed/" rel="self" type="application/rss+xml" /><link>http://blog.ajaxmasters.com</link> <description>Just another WordPress weblog</description> <lastBuildDate>Fri, 27 Jan 2012 15:44:56 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>Awesome CSS+JS form styling</title><link>http://blog.ajaxmasters.com/awesome-cssjs-form-styling/</link> <comments>http://blog.ajaxmasters.com/awesome-cssjs-form-styling/#comments</comments> <pubDate>Tue, 09 Mar 2010 17:23:39 +0000</pubDate> <dc:creator>Chocksy</dc:creator> <category><![CDATA[Tutorial]]></category> <category><![CDATA[css]]></category> <category><![CDATA[form]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[js]]></category> <category><![CDATA[sexy]]></category> <category><![CDATA[styling]]></category><guid
isPermaLink="false">http://blog.ajaxmasters.com/?p=309</guid> <description><![CDATA[I was working on our new open source project that i think you will like and I was working on the registration page. This is what I got in the end and i will walk you trough the process with me. This new tutorial is about styling the forms of...]]></description> <content:encoded><![CDATA[<div
id="attachment_312" class="wp-caption alignleft" style="width: 310px"><a
href="http://blog.ajaxmasters.com/awesome-cssjs-form-styling/sexy-form/" rel="attachment wp-att-312"><img
src="http://blog.ajaxmasters.com/wp-content/uploads/2010/03/sexy-form-300x214.png" alt="Sexy CSS Form" title="sexy-form" width="300" height="214" class="size-medium wp-image-312" /></a><p
class="wp-caption-text">Sexy CSS+JS Form</p></div><p>I was working on our new open source project that i think you will like and I was working on the registration page. This is what I got in the end and i will walk you trough the process with me. This new tutorial is about styling the forms of your website, I find it very good looking and very simple to implement. We will use simple CSS and some JavaScript.</p><p>Usually for inserting text into the inputs or our forms we set the value attribute with the text and then use javascript to check for different scenarios for doing some fancy things. This is different we will use labels to fill the text and move them under the inputs and then just do our magic with JS.</p><p>The JavaScript library that we will use to create this effect for our forms is <a
href="http://jquery.com" target="_blank">Jquery</a></p><p><br/><br
/> <strong
class="in_title">1. Creating the markup!</strong><br
/> <br/></p><pre class="brush: xml; title: ; notranslate">
            &lt;div id=&quot;login&quot;&gt;
                &lt;div class=&quot;sayit&quot;&gt;Log In:&lt;/div&gt;
                &lt;form action=&quot;javascript:void(0)&quot; onsubmit=&quot;login()&quot; autocomplete=&quot;off&quot;&gt;
                    &lt;label for=&quot;username&quot;&gt;Username&lt;/label&gt;
                    &lt;input type=&quot;text&quot; id=&quot;username&quot;/&gt;
                    &lt;label for=&quot;password&quot;&gt;Password&lt;/label&gt;
                    &lt;input type=&quot;password&quot; id=&quot;password&quot;/&gt;
                    &lt;input type=&quot;submit&quot; class=&quot;medium button green&quot; value=&quot;Log me In&quot;/&gt;
                &lt;/form&gt;
            &lt;/div&gt;
</pre><p>The above code is our markup and as you can see is very simple and it can be changed as you like because the code that we will use for checking for different scenarios in javascript will work without necessary classes or ids. We have 2 inputs and 2 labels, one is password one is text and we can work with these ones, you can add as many as you like.</p><p>Now let&#8217;s style these bastards! <img
src='http://blog.ajaxmasters.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /></p><p><strong
class="in_title">2. Use CSS to style the form elements!</strong><br
/> <br/></p><pre class="brush: css; title: ; notranslate">
input[type=text],input[type=password]{padding: 5px 10px; background-color: transparent;	position: relative; z-index: 2;}
label{position: absolute; z-index: 1;-webkit-transition: opacity 0.15s linear; color: #bababa; background-color: #FFFFFF; }

#login{width: 290px; margin: 0 auto;}
#login input[type=text],#login input[type=password]{width:270px; margin: 5px 0; font-size: 24px; font-weight: bold; border: 1px solid #ccc; -moz-border-radius:5px; -webkit-border-radius:5px; color: #595959;}
#login label{font-size: 24px; margin: 14px 10px;}

#login .sayit{font-size:24px; color: #595959; font-style: italic; padding-bottom: 5px;}
</pre><p>What we did here is make the label absolute so it will go under the input. This is important you will have to place the label before the input so remember this! The input will have a position relative and a z-index of 2 so we can be sure it will land above the label. Next we define the login div by using his id(<i>#login</i>). We use CSS3 for creating the round borders for the input and style the label by setting a big font-size to fit the input. The rest is pretty obvious, if you have trouble understanding this then let us know in the comments.</p><p><strong
class="in_title">3. Make everything move with JS!</strong><br
/> <br/></p><pre class="brush: jscript; title: ; notranslate">
$(document).ready(function(){
    $.string(String.prototype);
    $(&quot;input,textarea&quot;).each(function (type) {
        $(this).focus(function () {
            if($(this).val().blank())
                $(this).prev(&quot;label&quot;).fadeTo('fast',0.45);
        });

        $(this).keypress(function () {
            $(this).prev(&quot;label&quot;).fadeTo('fast',0);
        });

        $(this).blur(function () {
            if($(this).val().blank()){
                $(this).prev(&quot;label&quot;).fadeTo('fast',1);
            }
        });
    });
});
</pre><p>We use here jQuery of course that we add using the google api like this:</p><pre class="brush: xml; title: ; notranslate">
        &lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js&quot;&gt;&lt;/script&gt;
</pre><p>And one plugin that I use to extend the jQuery string properties and that is <a
href="http://stilldesigning.com/dotstring/">$.string plugin</a>. After we do that we create the above code and we assign to input and textarea elements a focus, keypress and blur actions. We use the focus action to lower the labels opacity to 45% then on keypress we just hide it for good. Then on blur we check to see if anything was written in our sexy element and if not then we fade the label back to 100%. This is kind of everything we do here, pretty simple. <img
src='http://blog.ajaxmasters.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p><strong
class="in_title">4. Showing of a demo and download source</strong><br
/> <br/></p><p>I&#8217;ve set up a demo here: <a
href="http://tutorials.ajaxmasters.com/sexy-form/" target="_blank"><b><i>DEMO</i></b></a></p><p>The source code you can either pick it from the demo page or from here: <a
href="http://tutorials.ajaxmasters.com/sexy-form/source.zip"><b><i>SOURCE</i></b></a></p><p><strong
class="in_title">5. Wrapping up!</strong><br
/> <br/></p><p>So here is our nice form styling that you can use on your website and that can be done very easily. Feel free to leave us comments and suggestions. <b>Thanks a lot!</b></p><p>Have fun coding!</p> ]]></content:encoded> <wfw:commentRss>http://blog.ajaxmasters.com/awesome-cssjs-form-styling/feed/</wfw:commentRss> <slash:comments>8</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: basic (User agent is rejected)
Database Caching 1/9 queries in 0.014 seconds using disk: basic
Object Caching 350/360 objects using disk: basic

Served from: blog.ajaxmasters.com @ 2012-02-05 06:25:31 -->
