Quick tip: coding beautiful form into html and css3

Posted by Mtuts on August 26, 2011 in HTML & CSS | 18 Comments
Quick tip: coding beautiful form into html and css3

Hello. Couple days ago I wrote tutorial about creating form with photoshop. Now I give You a quick tip how you can code it to html and css. I’ll be using CSS3 for this.

What will be needed in this tutorial?

Step 1. Folder and files structure

First create Your folder structure. We will need index.html, style.css, images folder and js folder.

photo 1

In images folder we will have background image and icons from input fields

photo 2

In js folder we will have cufon files for our font

photo 3

For cufon go to Cufon page and download cufon-yui.js file. Also You have to create a js file for Museo Slab. You have nice documentation on the site so I will skip this. You can find ready js file in tutorial package.

Step 2. HTML structure

I will use a mix of xhtml and CSS3 in this tutorial. Create html file for now

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<link rel="stylesheet" type="text/css" href="style.css" media="all" />
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
	<script type="text/javascript" src="js/cufon-yui.js"></script>
	<script type="text/javascript" src="js/Museo_Slab_500_400.font.js"></script>
	<script type="text/javascript">
		Cufon.replace('label', {
			textShadow: '1px 1px 1px #000'
		});
	</script>
	<title>Form</title>
</head>
<body>
	<div id="wrapper">
		<form action="#" id="form">
			<label for="name">Name</label>
			<input type="text" id="name" />
			<label for="email">Email</label>
			<input type="text" id="email" />
			<label for="telephone">Telephone</label>
			<input type="text" id="telephone" />
			<label for="message">Message</label>
			<textarea name="message" id="message" cols="30" rows="10"></textarea>
			<input type="submit" value="Send" name="submit" id="submit" />
		</form>
	</div>

	<script type="text/javascript"> Cufon.now(); </script>

</body>
</html>

As You can see it’s XHTML Transitional 1.0. We have link to our stylesheet, link to jquery and two scripts for font, also we have trigget fo cufon labels. Form is really simple, only necessary things here. Right before we have script for Cufon.now();. And that’s it. For this tutorial we don’t have to write more code in here.

Step 3. Styling

In this step we have some of CSS3 features. I used Prefixr for some of the lines to just speed up the whole process. So here’s whole css code

* {
	margin:0;
	padding:0;
}

body {
	background: #59799e url(images/bg.jpg) no-repeat top center;
	color: #444;
	font-size: 14px;
}

#wrapper {
	margin: 30px auto 0;
	width: 400px;
}

label {
	display: block;
	font-size: 24px;
	padding: 13px 0;
	color: #fff;
	text-shadow: 1px 1px 1px #666;
}

input {
	height: 20px;
	padding: 15px;
	width: 330px;
	-webkit-border-radius: 6px;
	-khtml-border-radius: 6px;
	-moz-border-radius: 6px;
	border-radius: 6px;
	-webkit-box-shadow: 0 0 10px #444;
	-moz-box-shadow: 0 0 10px #444;
	box-shadow: 0 0 10px #444;
	border: 1px solid #fff;
}

textarea {
	height: 220px;
	width: 330px;
	padding: 15px;
	border: 1px solid #fff;
	-webkit-border-radius: 6px;
	-khtml-border-radius: 6px;
	-moz-border-radius: 6px;
	border-radius: 6px;
	-webkit-box-shadow: 0 0 10px #444;
	-moz-box-shadow: 0 0 10px #444;
	box-shadow: 0 0 10px #444;
}

input[type="text"]:hover, textarea:hover {
	border: 1px solid #fff;
	-webkit-box-shadow: 0 0 20px rgba(0, 0, 0, 0.25) inset, 0 0 5px rgba(255, 255, 255, 0.4);
	-moz-box-shadow: 0 0 20px rgba(0, 0, 0, 0.25) inset, 0 0 5px rgba(255, 255, 255, 0.4);
	box-shadow: 0 0 20px rgba(0, 0, 0, 0.25) inset, 0 0 5px rgba(255, 255, 255, 0.4);
}

input#submit {
	width: 150px;
	text-align: center;
	color: #fff;
	height: 50px;
	padding: 0;
	text-shadow: 1px 1px 1px #000;
	font-size: 18px;
	text-transform: uppercase;
	margin-top: 50px;
	float: right;
	border: 1px solid #000;
	background: #000;
	background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #3b3b3b), color-stop(100%, #000000));
	background: -webkit-linear-gradient(top, #3b3b3b 0%,#000000 100%);
	background: -moz-linear-gradient(top, #3b3b3b 0%,#000000 100%);
	background: -o-linear-gradient(top, #3b3b3b 0%,#000000 100%);
	background: -ms-linear-gradient(top, #3b3b3b 0%,#000000 100%);
	background: linear-gradient(top, #3b3b3b 0%,#000000 100%);
	opacity: 0.5;
}

input#submit:hover {
	color: #ccc;
	cursor: pointer;
	opacity: 0.8;
}

#name {
	background: #f0f0f0 url(images/name.png) 10px center no-repeat;
	padding-left: 50px;
}

#email {
	background: #f0f0f0 url(images/email.png) 10px center no-repeat;
	padding-left: 50px;
}

#telephone {
	background: #f0f0f0 url(images/telephone.png) 10px center no-repeat;
	padding-left: 50px;
}

#message {
	background: #f0f0f0 url(images/message.png) 10px 10px no-repeat;
	padding-left: 50px;
}

Finished!

As You can see in the browser there are some problems. Cufon can’t be attached with inputs value. So there is Arial I belive. Of course there as some tricks that fix this (javascript) but for this tutorial I don’t think it’s really neccesary.

Hope You enjoyed this little quick tip. You can find coded form below.

18 Comments to Quick tip: coding beautiful form into html and css3

  1. Web Fix says:

    Thanks for all your help and your great post looking forward to more :)

  2. I adore your wordpress web template, exactly where did you download it from?

  3. Hello may I quote some of the information found in this site if I reference you with a link back to your site?

    • Mtuts says:

      Hello. While they’re be clear backlinks than there won’t be any problem. Of course You can’t copy the whole tutorials, just some pieces of it.

  4. Prince says:

    it great man and i should u such an inspiration to people like me who are web developers…….continue with good work

  5. young muya says:

    mhhh this definetly what i have been looking for

  6. Heyho, good entry! I will keep surfing your site ;)

  7. damn, this was awesome!

  8. Sven says:

    Hmm where can i change where emails go ?? :/

  9. Vijay says:

    Thanks for sharing your work, its really good ui, Can you share the css for drop down input element?

  10. Thank you very much! I love the result form.

    By the way your wordpress theme is outstanding!!

Leave a Reply

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>