|
|
How do you have rounded-edge HTML form text input boxes?I was cruising around on the Web last night and came across a Web site that has cool rounded edges on its text input boxes within its search forms. Super cool. How do they do that? All of my HTML forms end up with the same boring square edges... And exactly what site were you visiting that you saw these sexy curves in the input box? :-) Nevermind. Let's just make sure that we're talking about the same thing here, because I think you're just asking me a question about applying some CSS (cascading style sheets) styling to a standard HTML form with a text input box. Right? So, for example, if you go to the Google home page, you see a big box where you can type in your search query. It's square, and it's rudimentary. Works for Google and its approach to minimal, uncluttered design, but, yeah, something a bit more rounded does add a bit of pizazz to things. The basic of an HTML form can be summarized easily enough: <form method="get" action="targeturl">
query: <input type="text" name="q" /> </form> This type of basic HTML form produces something like this: Yeah, boring is the word for it. Now we can wrap it in a box by adding a "div" tag, but let's actually figure out what the site you visited was doing to get the input box itself to have rounded edges. Turns out what you're asking about is one of a number of super-cool additions to HTML forms that come courtesy of the new HTML 5 standard. In fact, simply replacing "text" with "search" magically transforms that input box to be exactly what you want: Tip: if you don't see it, it's because your Web browser isn't HTML5 compatible. Get a newer one, it should be different! :-) Easy enough, isn't it? Now it turns out that upon reading the HTML 5 input element spec that there's a bunch of neat stuff you can do, like automatically have page focus jump to that input box (as Amazon does with its search box) by adding autofocus, and you can even now have text that appears in the box, just to vanish as soon as someone starts typing, by using the attribute placeholder="text". Let's see "placeholder" in action. Source code first: <form method="get" action="targeturl">
<input type="search" placeholder="Enter query" /> </form> And the resultant input box, all tricked out: What do ya think? HTML5 now also includes a bunch of other specific data types, though how the browser handles those specific types is still up for grabs. If nothing else, I'm sure it helps with filling out forms automatically. The most useful? type="email", type="url", and type="number". Actually, HTML5 has some very cool tricks for entering numbers, including the ability to have a slider (that's type="range" if you want to Google it), but type="number" is my favorite. Here's a simple example: <form method="get" action="targeturl">
Pick a number between 0-100: <input type="number" min="0" max="100" value="50" /> </form> and the result: Tell me that's not darn cool! Armed with those you should be able to quickly and easily spiff up your HTML forms on your site. Now, it won't work with every single Web browser out there, but by definition, it'll all default to reasonable behaviors anyway, so there's really no reason not to do it. Now excuse me while I check the forms on my site to see if they're updated for HTML5...
More Useful HTML, JavaScript and Web Site Programming Articles:
✔ How to Create Predefined Google Image Search Links?
Thanks for the Amazon URL [see Creating Amazon Search Links]. That worked beautifully. In fact, I sent you $5.00 for coffee in thanks....
✔ Can I embed a Facebook search box on my blog site?I've seen your articles about how to add a Twitter or Google search box on a Web page, but I have a tougher...
✔ Can I use CSS for drop shadows on my blog?I want to give my site a bit of a facelift and add some neat graphical elements. One of which is drop shadows....
✔ How can I embed interactive photo panoramas on my site/blog?I read through your blog entry about how to take panoramic photos with iOS 6 and an iPhone 5 and got enthused. I've...
✔ How can I create a Twitter search URL shortcut?I'd like to add a few Twitter search links to my Web site. Is that possible, or does Twitter prohibit this sort of...
Let's stay in touch!
Sign up for my weekly AskDaveTaylor Newsletter and you'll receive even more tech and gadget help
right to your inbox, along with exclusive news and industry updates. It's good stuff. I promise!
Categorized:
HTML, JavaScript and Web Site Programming
,
HTML, JavaScript and Web Site Programming
(Article 9819,
Written by Dave Taylor)
Tagged: css, form design, html, html5, user input, web design Previous: How do I add photos to my iPod from my Windows PC? Next: Add names and contacts to my iPod from Windows PC? Reader Comments To Date: 4John Smith said, on March 4, 2011 2:21 PM:
"something a bit more rounded does add a bit of pizazz to things." I'm sorry but I see no "rounded" edges when viewing the examples in Firefox 4 (beta 12), Chrome 9 and Internet Explorer 8. Sure, the "search" examples in these newer browser do show a text input box with an [x] and with a placeholder comment, but I think the author might have misunderstood what "type='search'" is intended to do visually to an input field ... or perhaps is using a browser (Mac Safari?) that does make the fields curved and assumes this is an HTML 5 standard feature on all browsers? Article's claims need checking, though. Tammy said, on March 15, 2011 12:33 AM:
"Tip: if you don't see it, it's because your Web browser isn't HTML5 compatible. Get a newer one, it should be different!" Dave Taylor said, on March 15, 2011 6:47 AM:
John and Tammy, HTML5 is so new, and there are so many elements to it that it's possible that it's only the beta releases (not the main public releases) of the latest browsers that are starting to include HTML5 elements. Soooo.... it might be a while before this shows up in your browser and when it does, odds are good that it will be without any fanfare. You'll just notice one day - as I did - that the search box is shaped differently.
I do have a comment, now that you mention it!Check This Out Too... |
Recent Entries
Look for Answers
Recommended
All Our Categories
Apple iPad Help
Articles and Reviews Auctions and Online Shopping Blogs and Blogging Building Web Site Traffic Business and Management Computer and Internet Basics d) None of the Above Facebook Help Google Gmail Help Google Plus Help HTML, JavaScript and Web Site Programming Industry News and Trade Shows iPhone and Cell Phone Help iPod, Sony PSP and MP3 Player Help Kindle Fire Help Mac OS X Help Pay Per Click (PPC) Advertising Pinterest Help Search Engine Optimization (SEO) Shell Script Programming Tech Support Video Help The Writing Business Twitter, LinkedIn and Social Network Help Unix and Linux Help Video Game Tips and Help Windows PC Help Find Me on Google+ ADT on G+ |
It looks no different in Firefox 3.6, Chrome or Internet Explorer 9?