The search capability in modern web sites is an established feature. Visitors should always have the possibility to look for text or else, and search a whole site for specific things.
A search form can stay anywhere, however, it seems that the best way is to insert the feature on every page, possibly in the top right corner. If we browse all major web sites, we will notice that the search box is always there, ready to be used when needed.
In the following post, we will create a search form and style it a bit. The resulting box will be:
Note that the above is an image, so please do not try to use it.
Ok! Now let's try to build it. We are going to use plain HTML and CSS.
First of all the HTMLThe HTML behind the search box is plain and simple. We need an input box and a button. The image inside the button will be something like:
The search box, as said, is an input box and a button, all wrapped inside a container div. Let's see the code:
In details, the div has a class="container".
<input name="search" type="text" class="search" value="Search..."><button name="button" title="Search" class="button"><img src="l.png" alt="Search" class="mg"></button>
The form has no attribute in the example, you can add them according to your needs.
The input tag has a class="search".
The button tag has a class="button".
And finally the image (l.png) has a class="mg".
We are going to create rules for the container, the search box, the button and the image.
The CSSLet's start from the beginning: the container div:
Nothing special here.
The input box ("search" class):
Here we set the borders which are all the same except for the right hand side one. We then set the background color to a light grey (#EEEEEE).
The height is set to 20px with no margin and no padding. Note that we float the box to the left.
Now the button ("button" class):
The button has styles very similar to the input box. This time, the only missing border is the left hand side one, so that our search box will look like as whole piece. Note that the height is set to 22px: it is important that the button height is greater than the input box height. The button height value should always be the input box value + the top and bottom border heights (in our example is 20+1+1).
Now the image ("mg" class):
As you can see, the CSS is not that complicated. The final result will work in FireFox, IE 6+, Opera, Safari and Chrome.
Hope you enjoyed the above. Let me know what you think about it.