• Home
  • Archives
Subscribe: Posts | Comments | E-mail
  • Tech CornerNews and tips on latest gadgets.
  • Web Analytics / MarketingTips on SEO, Google Analytics, WebTrends
  • Web DevelopmentHTML, CSS, JavaScript, Ajax, jQuery, PHP, Flash.

Dr. Div

Posted on September 29, 2009 - by Dr. Div

How to Style Google Custom Search Field with CSS + Rounded Corners (curves)

Web Development

How to Style Google Custom Search Field with CSS + Rounded Corners

The idea is simple: The Custom Search code that Google provides has this structure:
FIELD + BUTTON.

The only thing we are adding here is a DIV (leftCurve image) right before the field. So the structure becomes: DIV + FIELD + BUTTON. The rest is pure CSS.

For this example, I set the body background color to navy blue in order to display rounded corners (curves) properly. You can change this color to any color of your choice or you can experiment with transparent graphics if you prefer.

Please write a comment if you found this helpful or if you have any questions.

Dr.Div




CSS

#searchField #fieldContainer {
	margin: 0px;
	padding: 0px;
}
#searchField #fieldContainer #myField{
	margin-left:-1px;
	margin-top:-1px;
	height:18px;
	float: left;
	width: 160px;
	color: #666666;
	border-top-style: none;
	border-right-style: none;
	border-bottom-style: none;
	border-left-style: none;
	background-position: left top;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 11px;
	padding: 3px 0px 0px 0px;
}
#searchField #fieldContainer #googleSearch{
	height:20px;
	width:auto;
	overflow:hidden;
	float:left;
}
#searchField #fieldContainer #leftCurve {
	float: left;
	background-image: url(bg_searchbar_left.gif);
	background-repeat: no-repeat;
	width:15px;
	height:20px;
	background-position: left top;
}
#searchField #fieldContainer #mySearch {
	float: left;
	background-image: url(bg_searchbar_right.gif);
	background-repeat: no-repeat;
	width:23px;
	height:20px;
	background-position: left top;
	display:block;
	margin-left:-1px;
	text-indent:-999px;
	overflow:hidden;
	border:none;
	color:#fff;
	font-size:1px;
}


BODY

<body bgcolor="#1d4f6e">
<div id="searchField">
<div id="fieldContainer">
<div id="leftCurve"></div>
<form action="http://www.drdiv.com" id="cse-search-box">
<div id="googleSearch">
<input type="hidden" name="cx" value="yourcxvalue" />
<input type="hidden" name="cof" value="FORID:9" />
<input type="hidden" name="ie" value="UTF-8" />
<input type="text" name="q" id="myField"/>
<input type="image" src="bg_searchbar_right.gif" name="sa" value="Search" id="mySearch"/>
</div>
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&lang=en"></script>
</form>
</div>
</div>
</body>


ROUNDED CORNERS

To download, right click on each image and select “Save Image As” or “Save As”. Make sure to save them with .gif extension.

bg_searchbar_left
bg_searchbar_right

Note: After you’re done with implementing this code, make sure to look at your original Google Custom Search code and add the correct website names and variables that are specific to your website.

5 Comments



  1. Visit My Website

    October 12, 2009

    Permalink

    Dr. Div said:

    If you’d like to remove the “Google Custom Search” watermark from the field, you can insert a blank value into the field, such as:

    input type="text" name="q" id="myField" value=" "

    For your information, according to Google Custom Search Terms of Service 2.3, changing this background graphic is not allowed (http://www.google.com/cse/docs/tos.html).



  2. Visit My Website

    January 15, 2010

    Permalink

    X said:

    THAAAAANK YOU! ;)



  3. Visit My Website

    February 3, 2010

    Permalink

    Dr. Div said:

    You’re very welcome!



  4. Visit My Website

    February 19, 2010

    Permalink

    Henry said:

    Thanks for the code. It is just what I was looking for. Are there any restrictions on re-using your code?



  5. Visit My Website

    February 19, 2010

    Permalink

    Dr. Div said:

    Glad it was helpful. Absolutely no restrictions. Helping out a fellow developer is my pleasure. Enjoy!



Leave a Comment

All Symptoms Welcome

  1. Name (required)

    Mail (required)

    Website

    Message

  • Worth-a-watch Ads

  • RSS Latest Gadget News by Engadget

    • Best Buy to slash prices for old Xbox 360 special edition bundles tomorrow?
    • Hacker intercepts phone calls with homebuilt $1,500 IMSI catcher, claims GSM is beyond repair
    • Switched On: The Galaxy S paradox
    • Dell Studio XPS 9100 arrives with six cores, little fanfare
    • Engadget Podcast 207 - 07.31.2010
  • Tag Cloud

    • Adobe Amazon Android apple App Store AT&T BlackBerry Bluetooth Chrome Engadget Facebook Gadgets Gaming Google Hardware Hewlett-Packard Home Theater HTC Intel iPad iPhone Kindle latest gadgets LG Mac Microsoft Mobile Motorola Nexus One Nokia Online Other PC Samsung Software Sony Sprint Steve Jobs T-Mobile Twitter Verizon wifi Windows 7 Windows Mobile YouTube
© 2009 Dr. Div - Website Prognosis & Therapy