Showing posts with label web tips. Show all posts

2009-05-15

Image

Custom Search Bars with Image and CSS


Attention to detail is what separates great web layouts from average ones. Incorporating custom elements, like bullet points and search boxes, can elevate your website into a clean, cohesive design. However, creating a custom search box with OnMouseOver-like effects can be difficult, particularly when styling for multiple browsers.
This tutorial will teach you how to add custom form boxes (a search bar) to your designs, and in browsers that format CSS correctly (read: not IE anything, although there is an IE fix for other problems) we’re going to have nice, fancy image replacements when you click on the search box, using the :focus pseudo class. Note: This does NOT work right in Safari, because it doesn’t know how to render transparent form inputs. Shame.

We’re going to step away from trade shows for this post to let me, the webmaster, write a short “how to:” for creating custom search bars with image replacement using CSS. When I was first presented with the idea of a custom search box, I searched the Google for hours trying to come up with a solution, but in the end I couldn’t find one to achieve what I wanted, hence this tutorial.
Although this example is tailored to a search bar, the same principles can be applied to any <form>.What’s the point of creating a beautiful web layout if you’re going to slap default form boxes on it?

Overview

When it comes to adding search boxes to websites, the vast majority of them are plain and boring. Replacing the search button is pretty common, but the actual input box remains white and boxy. About the most creative that the majority of websites get is adding a colored border or changing the inside color.
I’ve seen examples of custom search bars, but most of them break down in IE7, like Sacbee.com. It looks nice and Mac-esque, but type more characters than can fit on one screen and the image exits stage left, leaving you with a blank search box. You could add an image that repeats-x, but that is pretty limited. Using some basic HTML and advanced CSS, we can get the desired effect (almost in IE) without having to use Javascript.
Example: (Note: the positioning will be off in IE, because Wordpress is rudely changing a <div> tag into a <p> tag that closes too early for reasons that baffle me)

Creating the Search Form

The first step is creating your search box form. If you are planning on upgrading your current website’s search box, this step will be easy. If you have to implement a search script yourself, it can be a little harder, but not by much. There are plenty of free search scripts that will index and search your website, and most hosting packages with some kind of accessible control panel will come with one, which is what I will be using in my example. However, note that the result page is probably going to be very ugly, and requires some formatting to get it to look like your web template. A bigger job for another day.
Below is a standard search form input, as dictated to me by the cgi search script when I set it up on my server.
<form action=”/cgi-sys/entropysearch.cgi” target=”searchwindow”>
<input name=”query” value=”search” type=”text”>
<input name=”user” value=”nimlok” type=”hidden”>
<input name=”basehref” value=”http://nimlok-louisiana.com” type=”hidden”>
<input name=”template” value=”default” type=”hidden”>
<input value=”Search” type=”submit”>
</form>
Which looks like this:


Pretty ugly, wouldn’t you say?

Assembly

Let’s start with the images I want to put there instead: two search input boxes (one for normal and one for focused state) and a search button.


These images are really easy to make in Photoshop; they’re just rounded rectangle shapes with a pattern fill and a 2px stroke. The search button itself uses the magnifying glass shape included in Photoshop, so you can recreate simple images like these in about 15 minutes.

The Search Button

The first step is changing out the default images with our new ones. Start with the search button, the code for which currently looks like this:
<input value=”Search” type=”submit”>
change the type to “image” and add in the path to your new image, in my case, src=”http://www.nimlok-louisiana.com/images/search-btn.gif”. This is also a good time to add a “search_button” class to give it a 0 border and positioning.
<input value=”Search” class=”search_button” src=”images/search-btn.gif” type=”image”>
It’s not positioned quite correctly, but we’ll fix that later.

The Search Box

Next, we need to switch out that ugly white rectangle for something that matches your website’s design. You’ll note the search script told me to add several type=”hidden” fields to my search form. We’re going to add another one to get the desired background effect, allowing us to effectively stack the background underneath the search field.
Immediately after the INPUT line that controls the text input (the one of type=”text”) add a new hidden field. This hidden field will not show up in IE, although it will in Firefox. We’ll fix IE later; for now, let’s focus on getting it to work in Firefox.
<input name=”searchbg” value=”” type=”hidden” class=”searchbg”>
Then, add the searchbg class into your style sheet. This will determine which image shows up originally in Firefox (and other browsers that I haven’t tested). It has no effect on IE.
.searchbg
{
background:url(http://www.nimlok-louisiana.com/images/search-box-3.gif) no-repeat;
width:101px;
height:23px;
display:block;
border: 0;
}
This still looks pretty rough. Add class=”search_field” to your <input type=”text”> field (the actual search bar), and add the following style code.
.search_field
{
float:left; /* this will make the images line up */
border:0;
padding:0;
width:92px; /* the width of the actual search box, must be shorter than your image so it fits inside it. */
height:20px; /* again, must be slightly less than the image size */
background-color:transparent; /* Makes the search field invisible so you can see the image we want underneath. This doesn’t work in Safari, so I may go back later and give them their own style sheet. For now, I’m not bothered by this small inconvenience. */
}

:Focus Pseudo Class

Now it’s time for the fun part, making the images change in Firefox when you click on the search box.
This is achieved with an advanced CSS psuedo class called :focus. The focus tag is how you get an element to change when you click on it. You can also do :hover and :active (which have similar effects) to act as an OnMouseOver-like tag.
.search_field:focus + .searchbg
{
background:url(http://www.nimlok-louisiana.com/images/search-box.gif) no-repeat;
}
The + .searchbg tells the code to change the .searchbg class whenever you focus on the .search_field.
Looks pretty good, doesn’t it? In Firefox, I mean.

IE Calamity

Now, if you’ve been following along in IE, you may be curious as to why the image isn’t showing up for you. IE interprets hidden fields differently–maybe more correctly, I mean, they ARE hidden–and so you’re left in the dark.
There’s an easy solution to this, and it involves conditional comments.
We’re going to add a new class called .searchbgIE, and use it in a div to wrap around the entire form. Putting the image as a div background is important. If you put it on the form input background (.search_field) it will move to the left and out of view in IE7 as you type.
As a plus, we’re going to make it only appear in IE by using the <!–[if IE]> <![endif]–> conditional comment. Since this isn’t technically a “CSS hack,” it will still validate.
<!–[if IE]><div class=”searchbgIE”><![endif]–>
<form action=”/cgi-sys/entropysearch.cgi” target=”searchwindow”>
<input name=”query” value=”search” class=”search_field” type=”text”>
<input name=”searchbg” value=”” class=”searchbg” type=”hidden”>
<input name=”user” value=”nimlokl” type=”hidden”>
<input name=”basehref” value=”http://nimlok-louisiana.com” type=”hidden”>
<input name=”template” value=”default” type=”hidden”>
<input value=”Search” class=”search_button” src=”images/search-btn.gif” type=”image”>
</form>
<!–[if IE]></div><![endif]–>
The class .searchbgIE looks like this
.searchbgIE
{
background:url(http://www.nimlok-louisiana.com/images/search-box.gif) no-repeat;
width:101px;
height:23px;
display:block;
border:0;
}

It’s not positioned quite right, but I’ll fix all the positioning later, when Wordpress isn’t screwing it up. The plus of this is that I don’t have to worry about the positioning for the IE background messing up the positioning for Firefox’s; they use different classes.

Tie off loose ends

Now, wrap the entire thing in a div using the class .search, so you can position everything together. Throw a position:relative on it so that we can absolutely position everything inside. (Note: again, this doesn’t appear correctly in this tutorial, because of the way Wordpress converts my code into nonsense. Check the Nimlok Homepage for a working example in IE.)
.search
{
position:relative;
height:23px;
padding:0;
margin: 0px 0px 0px 0px; /* change this to position how you like */
}
Your HTML code should look like this:
<div class=”search”><!–[if IE]><div class=”searchbgIE”><![endif]–>
<form action=”/cgi-sys/entropysearch.cgi” target=”searchwindow”>
<input name=”query” value=”search” class=”search_field” type=”text”>
<input name=”searchbg” value=”” class=”searchbg” type=”hidden”>
<input name=”user” value=”nimlokl” type=”hidden”>
<input name=”basehref” value=”http://nimlok-louisiana.com” type=”hidden”>
<input name=”template” value=”default” type=”hidden”>
<input value=”Search” class=”search_button” src=”images/search-btn.gif” type=”image”>
</form>
<!–[if IE]></div><![endif]–> </div>
Completed Style Sheet, with positioning fixed. This is just how it looked best positioned on mine.
.search
{
margin: -8px 0px 0px 11px;
padding: 0;
position:relative;
height:23px;
}
.searchbgIE
{
background:url(http://www.nimlok-louisiana.com/images/search-box.gif) 3px 1px no-repeat;
width:101px;
height:23px;
display:block;
border: 0;
}
.searchbg
{
background:url(http://www.nimlok-louisiana.com/images/search-box-3.gif) 2px 1px no-repeat;
width:101px;
height:23px;
display:block;
border: 0px;
}
.search_button
{
position:absolute;
top:-1px;
left:100px;
border: 0px;
margin: 0px 0px 0px 2px;
}
.search_field
{
float:left;
border:0;
margin-left: 7px;
margin-top: 4px;
padding: 0;
width:92px;
height: 20px;
padding: 0px 0px 0px 0px;
font: 1.0em Arial;
background-color:transparent;
}
.search_field:focus + .searchbg
{
background:url(http://www.nimlok-louisiana.com/images/search-box.gif) 2px 0px no-repeat;
}

The End

This is it for the tutorial. By this point, you should have a working custom search bar, with a delightful :focus effect in Firefox.
I’m by no way an advanced CSS user, so if anyone has any suggestions for improvement, please leave me a comment, and I will update this guide accordingly.
Image

101 CSS Resources And Tutorials To Your Site

CSS ResourcesAll the cool kids are using CSS to separate content from appearance on their sites. Here is 101 resources that will get your feet wet with CSS, teach you some new tricks and techniques, clean your code, and hit the ground running with pre-made layouts.


CSS Templates and Layouts

A collection of 40 CSS layouts based on the same markup and ready for download! - blog.html.it
CSS Layouts - layouts.ironmyers.com
CSS Templates - free-css-templates.co.uk
The Web’s CSS Site - cssvault.com
CSS Stars -cssstars.com
Open Source Web Design - Download free web design templates - oswd.org
Dynamic Drive CSS Layouts- Tableless, CSS based templates - dynamicdrive.com
Free CSS Templates - free-css-templates.com
Free Design Templates - smashingmagazine.com
Free Website Templates - andreasviklund.com
CSS Design Gallery - didloo.com
Free Website Templates, Free Web Templates, Photoshop Layouts - freshtemplates.com
Free XHTML/CSS Website Templates - templateworld.com
Nice and Free CSS Templates - mycelly.com
Open Design Community - opendesigns.org
The CSS Tinderbox - csstinderbox.raykonline.com
The only CSS layout you need(?) Strictly CSS - strictlycss.com

CSS Tips and Techniques

10 CSS Tips from a Professional CSS Front-End Architect - 72dpiintheshade.com
15 CSS Properties You Probably Never Use (but perhaps should) - seomoz.org
53 CSS-Techniques You Couldn’t Live Without - smashingmagazine.com
A CSS Crossfader Demo - mikeomatic.net
Attach icons to anything with CSS - hunlock.com
Beginner's guide from a seasoned CSS designer - cameronmoll.com
CSS Advisor beta adobe.com
CSS Image Text Wrap Tutorial - bigbaer.com
CSS Navigation Techniques (37 entries) - alvit.de
CSS techniques I use all the time - christianmontoya.com
CSS Techniques Roundup - 20 CSS Tips and Tricks - petefreitag.com
CSS tips and tricks - blogherald.com
CSS: Getting Into Good Coding Habits - communitymx.com
Erratic Wisdom: 5 Tips for Organizing Your CSS - erraticwisdom.com
Everything You Need to Know About CSS3 - css3.info
Little Boxes - thenoodleincident.com
Master Stylesheet: The Most Useful CSS Technique - crucialwebhost.com
Max Design - Sample CSS Page Layouts - maxdesign.com.au
My 5 CSS Tips - businesslogs.com
Playing Nice with the Other CSS Kids - contentwithstyle.co.uk
Showing Hyperlink Cues with CSS - askthecssguy.com
Squeaky Clean CSS - huddletogether.com
Ten CSS tricks you may not know - webcredible.co.uk
Ten more CSS tricks you may not know - webcredible.co.uk
Three Column Layouts - css-discuss - css-discuss.incutio.com
Turning a list into a navigation bar - 456bereastreet.com
Turning Lists into Trees - odyniec.net
Unordered List Rollover Gallery - destinedtodesign.com
Web Page Reconstruction with CSS - digital-web.com
Yahoo! UI Library: Grids CSS - com1.devnet.scd.yahoo.com

CSS Tutorials

53 CSS-Techniques You Couldn’t Live Without - smashingmagazine.com
A Slacker’s Guide to Style Sheets - slackerhtml.tripod.com
Advanced CSS Layouts: Step by Step - webreference.com
Advanced HTML Tables and CSS Tutorial - lynchconsulting.com.au
Alternative Style: Working With Alternate Style Sheets - alistapart.com
Cascading Style Sheets in 7 Easy Steps: A CSS Tutorial - javascript-page.com
Creating a CSS layout from scratch - subcide.com
CSS - Quirks mode and strict mode - quirksmode.org
CSS Basics - Making Cascading Style Sheets Easy to Understand - cssbasics.com
CSS Design, News, Jobs, Community, Web Standards - cssbeauty.com
CSS Design: Creating Custom Corners & Borders - nidahas.com
CSS Library- Practical CSS codes and examples - dynamicdrive.com
CSS shorthand properties - an introduction - home.no.net
CSS Tutorial - w3schools.com
css Zen Garden: The Beauty in CSS Design - csszengarden.com
CSS: cascading style sheets tutorials and style guide - yourhtmlsource.com
Making Complex CSS Simple! - leftjustified.net
Making Headlines With CSS - webreference.com
MIS Web Design: Fancy Paragraphs With CSS - miswebdesign.com
More Rounded Corners with CSS - schillmania.com
Simple Styling with CSS - adobe.com
Single Image Multi Replacement - web-graphics.com
Spiderpro: How To justify text with CSS - spiderpro.com
The Complete CSS tutorial - echoecho.com
Tools : Link Thumbnail- lab.arc90.com
Tutorials: Uberlinks CSS List Menus - projectseven.com
Using CSS and a simple list to create radically different list options - css.maxdesign.com.au

CSS Utilities

Cascading Style Cheatsheet - home.tampabay.rr.com
Clean CSS - A Resource for Web Designers - Optmize and Format your CSS - cleancss.com
CSS Browser Selector - rafael.adm.br
CSS Cheat Sheet - Cheat Sheets - ilovejackdaniels.com
CSS Compressor - iceyboard.no-ip.org
CSS Creator - csscreator.com
CSS Editor - pixy.cz
css filters (css hacks) - centricle.com
CSS Formatter and Optimiser/Optimizer - cdburnerxp.se
CSS Properties to JavaScript Reference - codepunk.hardwar.org.uk
CSS Rounded Box Generator - neuroticweb.com
CSS Source Ordered 1-3 Columned Page Maker by ClevaTreva Designs - The Generator Form v2.90 - positioniseverything.net
CSS Superdouche
CSS Tweak ~ Web Based CSS Tweaker! - cssdev.com
CSSCheck, a Cascading Style Sheets Lint - htmlhelp.com
CSSTidy - csstidy.sourceforge.net
Firdamatic: the Design Tool for the Uninspired Webloggers - wannabegirl.org
Free CSS Template Code Generator - Maker for 3 Column Layout (tableless) - ibdjohn.com
Iconize Textlinks with CSS - pooliestudios - pooliestudios.com
JotForm - jotform.com
Live CSS editing with Internet Explorer and Firefox simultaneously - sitevista.com
OverZone Software - CSS Tab Designer - highdots.com
Simple CSS - hostm.com
Sky CSS Tool - skycsstool.sourceforge.net
Stylesheet Generator - Scriptomizers’ Webmaster Tools - scriptomizers.com
The W3C CSS Validation Service - jigsaw.w3.org
i will sure , you do the best

2009-05-06

Image

80+ AJAX-Solutions For Professional Coding

AJAX Auto Completer

1. AJAX AutoSuggest: An AJAX auto-complete text field

2. AJAX Autocompleter / script.aculo.us library
 
3. AJAX AutoCompleter

4. Ajax autosuggest/autocomplete from database
 
5. Ajax dynamic list

AJAX Instant Edit

6. AJAX inline text edit 2.0
 
7. AJAX & CSS Flickr-like Editing Fields
 
8. AJAX Instant Edit

AJAX Menus, Tabs

9. 14 Tab-Based Interface Techniques
10. AJAX Menu Widget


11. AJAX Accordion Navigation: mootools demos
12. AJAX Dialogs, Menus, Grids, Trees and Views

13. AJAX Tab Module - Closeable Implementation

14. Ajax Tabs Content

15. AJAX Tabbed Content
16. MooTabs - Tiny tab class for MooTools

17. Dynamically loaded articles

AJAX Date, Time, Calendars

18. AJAX Datetime Toolbocks - Intuitive Date Input Selection

19. AJAX Calendars

AJAX Interactive Elements

20. AJAX Floating Windows

21. AJAX Star Rating Bar

22. Ajax poller

AJAX Developer’s Suite

23. AJAX HistoryManager, Pagination

24. AJAX Login System Demo

25. AJAX image preloader

26. AJAX Tooltips: Nice Titles revised | Blog | 1976design.com

27. 40+ Tooltips Scripts With AJAX, JavaScript & CSS | Smashing Magazine

28. AJAX Web Controls

29. AJAX syntaxhighlighter

30. GMail Ajax Style Username Signup
31. Gmail Ajax Style Check Username
32. Transparent Message

33. ModalBox — An easy way to create popups and wizards

34. AJAX File Uploads progress bar
35. Chained select boxes

36. Fly to basket

37. AJAX Key Events Signal

38. Disable form submit on enter keypress

Enhanced AJAX Solutions

39. AJAX Instant Completion: Rico Framework

40. Novemberborn: Event Cache

41. Altering CSS Class Attributes with JavaScript

42. Select Some Checkboxes JavaScript Function

43. AJAX Emprise Charts: 100% Pure JavaScript Charts

44. amCharts: customizable flash Pie & Donut chart

45. PJ Hyett : The Lightbox Effect without Lightbox

Ajax Forms

46. AJAX Upload Form

47. An AJAX contact form

48. AJAX contact form

49. Ajax.Form: mootools demo

50. Ajax form validation

51. Really easy field validation

52. AJAX fValidate: a high quality javascript form validation tool

53. Ajax newsletter form

54. wForms: A Javascript Extension to Web Forms - The Form Assembly

AJAX Grids, Tables

55. Data Grids with AJAX, DHTML and JavaScript | Smashing Magazine

56. Grid3 Example

57. AJAX Table Sort Script (revisited)

58. AJAX Sortable Tables: from Scratch with MochiKit

59. AJAX TableKit

AJAX Lightboxes, Galleries, Showcases

60. 30 Scripts For Galleries, Slideshows and Lightboxes | Smashing Magazine

61. AJAX LightBox, Sexy Box, Thick Box

62. AJAX Lightbox JS

63. AJAX Unobtrusive Popup - GreyBox

64. SmoothGallery: Mootools Mojo for Images | Full gallery

65. AJAX Libraries and Frameworks

Visual Effects, Animation

66. How to Create Digg Comment Style Sliding DIVs with Javascript and CSS

67. How to Create a Collapsible DIV with Javascript and CSS

68. How to Create an Animated, Sliding, Collapsible DIV with Javascript and CSS

69. AJAX Shopcart

70. Draggable content

71. Dragable RSS boxes

72. AJAX Pull Down Effect: Rico Framework

73. AJAX Animation Effects: Rico Framework

74. Combination Effects in scriptaculous wiki

75. AJAX Motion Transition: Fx.Morph

Useful Basic JavaScripts

76. 9 Javascript(s) you better not miss !!

77. Top 10 custom JavaScript functions of all time

78. Hyperdisc Materials: JavaScript: Top 10: Automatic Breadcrumb Trail

79. JavaScript: Top 10 Most Useful JavaScripts

80. My Favorite Javascripts for Designers: Blakems.com ?

Galleries, Resources

81. MiniAjax.com: a showroom of nice looking simple downloadable DHTML and AJAX scripts.

82. Ajax Rain: growing showcase of AJAX-examples.

83. Max Kiesler - mHub : Ajax and rails examples & how-to’s

84. Ajax Resources

85. DZone Snippets: Store, sort and share source code, with tag goodness

Total Pageviews