954,591 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How can I specify the shape of form form fields?

Hello,

Different browsers render form fields differently. Some browsers will make the corners rounded while some will create rectangular fields.

I was wondering if anyone knows how to control this behavior.
Is there a CSS technique for specifying the shape of an input field?

ryy705
Junior Poster
171 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 

Unless you explicitly set CSS to control how the control is displayed, the browser renders it its own way by default. You can set the borders, padding, and background image of a text field just as you would any other web component.

Here's a nice example:
http://ryanfait.com/resources/custom-checkboxes-and-radio-buttons/

Phaelax
Practically a Posting Shark
858 posts since Mar 2004
Reputation Points: 92
Solved Threads: 51
 

I did not see any css on that page specifying the "SHAPE" (90 degree corner VS rounded corner) of input fields. Do you know how to do that?

ryy705
Junior Poster
171 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 

There are different settings for different browsers as far as rounded corners go. For instance, here is an example of how to change the corners in firefox.

#blahblah input {
 -moz-border-radius: 5px;
}


You can even individually set a border radius (-moz-border-radius-topright). You can change the value to give you more or less of a rounded edge. Here's the syntax for Safari.

#blahblah input {
 -webkit-border-radius: 5px;
}
papanyquiL
Junior Poster
168 posts since May 2009
Reputation Points: 55
Solved Threads: 18
 

Thank you. What do I do if I want a rectangular field?

ryy705
Junior Poster
171 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 

'Text' input fields are rectangular by default.

papanyquiL
Junior Poster
168 posts since May 2009
Reputation Points: 55
Solved Threads: 18
 

I'm having trouble with the "SELECT" field.

ryy705
Junior Poster
171 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 

-moz-border-radius: 5px; is for Firefox
and
-webkit-border-radius: 5px; is for other browser except IE.

In IE it won't work.

gaurang4
Newbie Poster
21 posts since Jul 2010
Reputation Points: 11
Solved Threads: 1
 

Use just 'border-radius' for Opera. IE needs some heavy lifting via jquery or similar. In short, IE blows.

The only form field I found impossible to style to my liking is the file upload field. As they are rendered completely differently in browsers, js browser detection is required to style successfully. This is not good. The file field unfortunately is not a button + textbox, it's one object. My own workaround was to make a 'faux button' with a transparent strip showing the 'filename area' beneath. It didn't work consistently across different resolutions.

Sorry - not a hijack - if anybody knows of a style system that includes file fields, please post here.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,795 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

Yes ....for File Uploading it's not working properly accessible way.

gaurang4
Newbie Poster
21 posts since Jul 2010
Reputation Points: 11
Solved Threads: 1
 

Doh! Here's a link to show file field styling. It uses the prototype library, so I assume it would be easy enough to port to jquery or just vanilla js.

http://valums.com/wp-content/uploads/ajax-upload/demo-prototype.htm

I've had that kicking around in my bookmarks for ages - didn't even think about it.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,795 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

Really nice solution. Thanks ... :)

gaurang4
Newbie Poster
21 posts since Jul 2010
Reputation Points: 11
Solved Threads: 1
 

I am trying to make the select field appear as rectangular boxes in all browsers.
Some browsers will try to give it rounded corners by default.

Does anyone have a solution for this?

ryy705
Junior Poster
171 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 

set borders to none or 0:

input[type=text]{
  border:none;
}


Then place a background graphic that has a rectangular shape:

input[type=text]{
  border:none;
  width: 400px;
  background-image: url(images/textbox_bg.gif);
  padding: 4px;
}


Should do it. Width is important to stop text from carrying on beyond the graphic.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,795 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You