Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross Browser input field width stylization

I have a shipping/billing input form and I'm having trouble styling the input fields to be the same width...

The Problem:
-a field <input type="text" size="X" /> appears to render with different sizes in different browsers (see link).
-In addition, select fields seem to render on a differently as well.
-Chrome/safari do not seem to respond to the font-size property for select fields.

Any guidance on how to stylize the size of text-input and select fields cross-browser would be oh so very helpful.

Must I result to having a different sytlesheet for each browser... just for these input fields? -thanks

like image 329
Derek Adair Avatar asked Mar 16 '10 16:03

Derek Adair


People also ask

How do you increase the width of an input field?

In HTML, you can use the width attribute to set the width of an element. Alternatively, you can also use the size attribute to define the width of the <input> .

How do you style input elements in CSS?

Styling Input Fields If you only want to style a specific input type, you can use attribute selectors: input[type=text] - will only select text fields. input[type=password] - will only select password fields. input[type=number] - will only select number fields.

What is cross browser in CSS?

Cross-browser development is making a web page look and behave the same on different desktop and mobile browsers. Five years ago, this was a real challenge for front-end developers. Thankfully, it's has gotten much easier now with the support for modern CSS tools like Grid and Flexbox.

How do you input CSS in HTML?

CSS can be added to HTML documents in 3 ways: Inline - by using the style attribute inside HTML elements. Internal - by using a <style> element in the <head> section. External - by using a <link> element to link to an external CSS file.


1 Answers

Remove that inline "size" attribute, first. You should use CSS to style the input form:

input[type="text"] {
    width: 100px;

    /* You can also style padding, margins and everything else,
     * just remember that inputs of type "text" can only be one line. 
     */
}

Don't use [type="text"] as a selector. I was just using it in this example to associate with input fields of type "text", but it's not fully cross-browser supported. You should give your text input fields their own class to stylize with.

Also, don't forget your CSS reset to make sure your margins, borders, et. al. are reset for all browsers. http://meyerweb.com/eric/tools/css/reset/

like image 50
dclowd9901 Avatar answered Sep 30 '22 13:09

dclowd9901