Skip to main content

Creating A Rocking CSS3 Search Field


CSS3 is the next generation style sheet language. It introduces a lot of new and exciting features like shadows, animations, transitions, border-radius etc. Although the specifications have not been finalized yet, many browser manufacturers have already started supporting many of the new features.
In this tutorial, we will explore some of these features like text-shadowborder-radiusbox-shadows and transitions to create a rocking search field. The image below shows how the search filed looks like, or check out a working demo.
css search preview Creating A Rocking CSS3 Search Field
The photoshop version of this search field was created by Alvin Thong and can be downloaded from here. I have tried to recreate this search field using pure CSS3. It is to be noted that not all browsers support CSS3 features and to trying out this tutorial, you should use one of the modern browsers that support CSS 3 features.
Ready? Let’s get started!

1. HTML5 Doctype

We’ll start with the HTML markup. It is very simple, after the  HTML5 doctype and the  declaration, we have a 
 with an ID called #wrapper inside . This is done simply to define the width of the content box and to align it to the centre of the page.
This is followed by a 
 with an ID called #main. This ID contains the styles that define the big white box around the input field and the search button. This 
 has a 
 declared inside it. The form has the text input field and the search button. Here is how the form looks like without any styles applied to it:
without css Creating A Rocking CSS3 Search Field
Here’s how the code looks like:
	CSS3 Search Field   	

CSS3 Search Field

2. Creating the bounding box

To create the big box around the form, we will add styles to the 
 with the ID of #main. From the code shown below, you will notice that the box has been given a width of 400px and a height of 50px.
#main { 	width: 400px; 	height: 50px; 	background: #f2f2f2; 	padding: 6px 10px; 	border: 1px solid #b5b5b5;  	-moz-border-radius: 5px; 	-webkit-border-radius: 5px; 	border-radius: 5px; 	-moz-box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.8), inset 0 2px 2px rgba(255, 255, 255, 1), 0 5px 0 #ccc, 0 6px 0 #989898, 0 13px 0 #dfdede; 	-webkit-box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.8), inset 0 2px 2px rgba(255, 255, 255, 1), 0 5px 0 #ccc, 0 6px 0 #989898, 0 13px 0 #dfdede; 	box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.8), inset 0 2px 2px rgba(255, 255, 255, 1), 0 5px 0 #ccc, 0 6px 0 #989898, 0 13px 0 #dfdede; } 
The important piece of code here is the border-radius declaration and the box-shadow declaration. For creating rounded corners, we have used the CSS3 border-radius declaration, "-moz-" and "-webkit-" browser prefixes have been used to ensure that this works in gecko and webkit based browsers. The box shadow declarations might look a bit confusing but it is actually very simple.
box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.8), inset 0 2px 2px rgba(255, 255, 255, 1), 0 5px 0 #ccc, 0 6px 0 #989898, 0 13px 0 #dfdede; 
Explanation: Here, the keyword inset specifies if the shadow will be inside the box. The first two zero’s indicate the x-offset and the y-offset and the 3px indicates the blur. Next is the color declaration. I have used rgba values here; rgba stands for red green blue and alpha (opacity). Thus the 4 values inside the parenthesis indicate the amount of red, green, blue and its alpha (opacity). You will notice that 5 sets of shadow declarations have been clubbed together. This can be done by separating them with a comma. The first two shadows define the white "inner glow" effect and the next there declarations gives the box its solid/chunky look.
Play around with these values to understand how it works.
search box Creating A Rocking CSS3 Search Field
(Preview)

3. Styling the input field

Now that the box is complete, lets move on to styling the input field.
input[type="text"] { 	float: left; 	width: 230px; 	padding: 15px 5px 5px 5px; 	margin-top: 5px; 	margin-left: 3px; 	border: 1px solid #999999;   	-moz-border-radius: 5px; 	-webkit-border-radius: 5px; 	border-radius: 5px;   	-moz-box-shadow: inset 0 5px 0 #ccc, inset 0 6px 0 #989898, inset 0 13px 0 #dfdede; 	-webkit-box-shadow: inset 0 5px 0 #ccc, inset 0 6px 0 #989898, inset 0 13px 0 #dfdede; 	box-shadow: inset 0 5px 0 #ccc, inset 0 6px 0 #989898, inset 0 13px 0 #dfdede; } 
The styles declared for the input field are pretty similar to those decared for the big box #main. We have used the same border radius (5px). Again, multiple box-shadows have been clubbed.
box-shadow: inset 0 5px 0 #ccc, inset 0 6px 0 #989898, inset 0 13px 0 #dfdede; 
Explanation: You will notice that this time, the shadow blur has been kept at 0 to obtain a sharp shadow and a vertical offset of 5px is used. In the successive declarations, the blur has been kept at 0px but the color and the y-offset have been changed. Again, play around with these values to obtain different results.
with search box Creating A Rocking CSS3 Search Field
(Preview)

4. Styling the submit button

Let’s style the search button.
input[type="submit"].solid { 	float: left; 	cursor: pointer; 	width: 130px; 	padding: 8px 6px; 	margin-left: 20px; 	background-color: #f8b838; 	color: rgba(134, 79, 11, 0.8); 	text-transform: uppercase; 	font-weight: bold; 	border: 1px solid #99631d;   	-moz-border-radius: 5px; 	-webkit-border-radius: 5px; 	border-radius: 5px;   	text-shadow: 0 1px 2px rgba(255, 255, 255, 0.7), 0 -1px 0 rgba(64, 38, 5, 0.9);    	-moz-box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.6), inset 0 1px 2px rgba(255, 255, 255, 0.7), 0 5px 0 #b8882a, 0 6px 0 #593a11, 0 13px 0 #ccc; 	-webkit-box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.6), inset 0 1px 2px rgba(255, 255, 255, 0.7), 0 5px 0 #b8882a, 0 6px 0 #593a11, 0 13px 0 #ccc; 	box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.6), inset 0 1px 2px rgba(255, 255, 255, 0.7), 0 5px 0 #b8882a, 0 6px 0 #593a11, 0 13px 0 #ccc; 	-webkit-transition: background 0.2s ease-out; } 
Apart from the colors, the search button has mostly the same styles as that of the outer box. Similar border-radius and box-shadows have been used on the button. The new feature introduced is the text-shadow.
text-shadow: 0 1px 2px rgba(255, 255, 255, 0.7), 0 -1px 0 rgba(64, 38, 5, 0.9); 
Explanation: In the text-shadow declaration, the first three numeric values are the x-offset, y-offset and the blur respectively. The rgba values indicate the shadow color. In the next set of declaration (separated by a comma), the y-offset is given a value of -1. This is done to give the text an “inner shadow” effect.
The hover/focus state of the submit button has different values of background color and shadows.
with search button Creating A Rocking CSS3 Search Field
(Preview)

"Active" state for button

The active state of the button has a bit more changes. In this, I have given the button a position of absolute and a ‘top’ value of 5px. This has been done to give it a more natural look, such that it feel that the button has actually been pushed down by 5 pixels. Other changes to the active state are that of background-color and shadows. Notice that I have reduced the y-offset of the shadows to give it a ‘pressed-down’ look. Here is the code for the active state of the submit button:
input[type="submit"].solid:active { 	background: #f6a000; 	position: relative; 	top: 5px; 	border: 1px solid #702d00;   	-moz-box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.6), inset 0 1px 2px rgba(255, 255, 255, 0.7), 0 3px 0 #b8882a, 0 4px 0 #593a11, 0 8px 0 #ccc; 	-webkit-box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.6), inset 0 1px 2px rgba(255, 255, 255, 0.7), 0 3px 0 #b8882a, 0 4px 0 #593a11, 0 8px 0 #ccc; 	box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.6), inset 0 1px 2px rgba(255, 255, 255, 0.7), 0 3px 0 #b8882a, 0 4px 0 #593a11, 0 8px 0 #ccc; } 

The Complete (CSS) Code

This completes our search field. We have used quite a few of the new CSS3 features. Here is the complete CSS and HTML of this search field.
#main { 	width: 400px; 	height: 50px; 	background: #f2f2f2; 	padding: 6px 10px; 	border: 1px solid #b5b5b5;   	-moz-border-radius: 5px; 	-webkit-border-radius: 5px; 	border-radius: 5px;   	-moz-box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.8), inset 0 2px 2px rgba(255, 255, 255, 1), 0 5px 0 #ccc, 0 6px 0 #989898, 0 13px 0 #dfdede; 	-webkit-box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.8), inset 0 2px 2px rgba(255, 255, 255, 1), 0 5px 0 #ccc, 0 6px 0 #989898, 0 13px 0 #dfdede; 	box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.8), inset 0 2px 2px rgba(255, 255, 255, 1), 0 5px 0 #ccc, 0 6px 0 #989898, 0 13px 0 #dfdede; }   input[type="text"] { 	float: left; 	width: 230px; 	padding: 15px 5px 5px 5px; 	margin-top: 5px; 	margin-left: 3px; 	border: 1px solid #999999;   	-moz-border-radius: 5px; 	-webkit-border-radius: 5px; 	border-radius: 5px;   	-moz-box-shadow: inset 0 5px 0 #ccc, inset 0 6px 0 #989898, inset 0 13px 0 #dfdede; 	-webkit-box-shadow: inset 0 5px 0 #ccc, inset 0 6px 0 #989898, inset 0 13px 0 #dfdede; 	box-shadow: inset 0 5px 0 #ccc, inset 0 6px 0 #989898, inset 0 13px 0 #dfdede; }   input[type="submit"].solid { 	float: left; 	cursor: pointer; 	width: 130px; 	padding: 8px 6px; 	margin-left: 20px; 	background-color: #f8b838; 	color: rgba(134, 79, 11, 0.8); 	text-transform: uppercase; 	font-weight: bold; 	border: 1px solid #99631d;   	-moz-border-radius: 5px; 	-webkit-border-radius: 5px; 	border-radius: 5px;   	text-shadow: 0 1px 2px rgba(255, 255, 255, 0.7), 0 -1px 0 rgba(64, 38, 5, 0.9);    	-moz-box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.6), inset 0 1px 2px rgba(255, 255, 255, 0.7), 0 5px 0 #b8882a, 0 6px 0 #593a11, 0 13px 0 #ccc; 	-webkit-box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.6), inset 0 1px 2px rgba(255, 255, 255, 0.7), 0 5px 0 #b8882a, 0 6px 0 #593a11, 0 13px 0 #ccc; 	box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.6), inset 0 1px 2px rgba(255, 255, 255, 0.7), 0 5px 0 #b8882a, 0 6px 0 #593a11, 0 13px 0 #ccc;   	-webkit-transition: background 0.2s ease-out; }   input[type="submit"].solid:hover, input[type="submit"].solid:focus { 	background: #ffd842;   	-moz-box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.9), inset 0 2px 1px rgba(255, 250, 76, 0.8), 0 5px 0 #d8a031, 0 6px 0 #593a11, 0 13px 0 #ccc; 	-webkit-box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.9), inset 0 2px 1px rgba(255, 250, 76, 0.8), 0 5px 0 #d8a031, 0 6px 0 #593a11, 0 13px 0 #ccc; 	box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.9), inset 0 2px 1px rgba(255, 250, 76, 0.8), 0 5px 0 #d8a031, 0 6px 0 #593a11, 0 13px 0 #ccc; }   input[type="submit"].solid:active { 	background: #f6a000; 	position: relative; 	top: 5px; 	border: 1px solid #702d00;   	-moz-box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.6), inset 0 1px 2px rgba(255, 255, 255, 0.7), 0 3px 0 #b8882a, 0 4px 0 #593a11, 0 8px 0 #ccc; 	-webkit-box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.6), inset 0 1px 2px rgba(255, 255, 255, 0.7), 0 3px 0 #b8882a, 0 4px 0 #593a11, 0 8px 0 #ccc; 	box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.6), inset 0 1px 2px rgba(255, 255, 255, 0.7), 0 3px 0 #b8882a, 0 4px 0 #593a11, 0 8px 0 #ccc; } 

Demo and Download

If you are lost at any point or couldn’t follow up with the tutorial, no worries, we’ve got the tutorial zipped in a single file. Download it to your desktop and it’ll work just fine.
Hope you enjoyed this tutorial. Feel free to experiment with these features and don’t forget to share your thoughts.

Comments

Popular posts from this blog

Hot and Sexy Big ass girls

There are very sexy and cute big ass girls images with very good resolution. visit here and get this nice hot collection with good resolution.    If you like to these images please comments here it is very important to us. Thank you for visiting here.

Upeksha Swarnamali

There are very large image collections of Sri Lankan famous Actress Upeksha Swarnamali with very good resolution. Visit here and download all hot images of Sri Lankan Actress & Models. Upeksha Swarnamali is a very famous actress in Sri Lanka and also She is very Hot & Cute. Now she has married.  And also She was elected as a member of the Sri Lanka Parliament in the 2010 General Elections held on 8 April 2010 representing the United National Party.There are large image collections for understanding her beauty with previous and nearly released images. Starting her carrier as a model, she appeared on several song videos including "Chanchala", and took a major role in the television drama series "PABA". She also participated in the reality dancing show Sirasa Dancing Stars, on 8 June 2008 she was eliminated. She gained national attention due to the controversial removal from the Paba teledrama aired by State run ITN, due to what she claimed as her open support ...

Shalani Tharaka (sirasa kumari)

There are large image collection of Sri Lankan very famous star Shalani Tharaka. These images only with very good resolution. You  can download these all images quickly now. Shalani Tharaka is a very famous upcoming young Actress and Model in Sri Lanka.She has won  Sirasa Kumariya Competition which was organized by Sirasa TV. After that all Sri Lankan known her as the Sirasa Kumariya.Sri Lankan youngsters are love this cute actress because of the beauty and romantic performance in Sinhalese Teledramas. Now She has married. She is now becoming the most famous Actress of Sri Lankan Teledrama industry. Her performance in all teledramas are very great and attractive. Because of her this popular She will be the most popular Actress in Sri Lanka as soon as possible. There are few images of Sirasa Kumariya winning time which was organized by Sirasa TV. If you want see all images of Sirasa Kumariya you can visit her face book account. Below Images have been taken when she was Acting. ...