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

Udari Warnakulasooriya

There are nice cute and sexy large image collection of Udari Warnakulasooriya with good resolution. You can quickly download now. Udari Warnakulasooriya is a very hot and famous actress in SriLanka. Not only that but also she is a very famous Television presenter.There are newly released and previous large photos collection with  good resolution.when you see this images you will try to download it because actually she is very cute and sexy. Now she has married. She has come in to the industry by Miss Sri Lanka competition and theb she work as a Television presenter in Derana Television network. Her first film was "Paya enne hiruse".After that she can be a very famous actress among young generation. This film was directed by Udayakantha Warnakulasooriya. She will be a very famous star among our world. This is our wish for it . Good Luck Dear Udari. .................................................................................................. For more images of Udari Warnak

Nadini Premadasa

There are very large image Collection of Super Star Singer and Very famous singer in Sri Lanka, Nadini Premadasa with very good resolution. Newly and Previous Hot and Cute images via this site. Nadini Premadasa is a very famous Singer & TV presenter in Sri Lanka.She was born on 19th December & her school was Musaeus College. Her first audio "Sapu Kusume" & video "Madesha Balannai" was released in 2007.She has released a her first music album is out now.There are large image collection with her previous and newly released hot and cute images. The year 2007 is the revolutionary year of Nadini Premadasa. She unleashed her potential by entering to the “Sirasa Super Star Singing Competition”. This is the most competitive reality singing program in Sri Lanka. She had the courage and talent to compete with the best singing personalities in the country. As a result, she ended becoming an attractive and talented female singer.(via nadinilive.com ) She is very cut

Nirosha Perera

There are many Sexy and Beautiful images of Nirosha Perera. Dont waist your time the all images which you want can get from here Get these quickly. Nirosha Perera is the famous TV presenter and actress in Sri Lanka. She has act many Teledramas that are very famous among young generation. Previous time she has act new film is "Ekamath Eka Rataka". We could see very clever acting from Nirosha Perera. Nirosha studied at Buddhist Ladies College, Colombo and popular figure from schooldays onwards since everywhere where things were happening. Nirosha is the second in the Perera. Her sister is Irosha Perera also she is a TV presenter.Both Nirosha and Irosha were grateful to Sydney Chandrasekara for moulding them into what they are today as television presenters. As others she will make a new presentation style nearly. so this is our wishes for her. Good Luck Nirosha Perera. .............................................................................................................