{"id":742,"date":"2012-09-06T13:18:41","date_gmt":"2012-09-06T13:18:41","guid":{"rendered":"http:\/\/www.sitekickr.com\/blog\/?p=742"},"modified":"2012-09-06T13:18:41","modified_gmt":"2012-09-06T13:18:41","slug":"cross-browser-field-dimensions","status":"publish","type":"post","link":"https:\/\/www.sitekickr.com\/blog\/cross-browser-field-dimensions\/","title":{"rendered":"Cross-browser field dimensions"},"content":{"rendered":"<p>Yesterday I was tasked with fitting a new design on a very old site. As expected, the existing site made heavy use of the rows, cols and size attributes for textareas and inputs (not that there&#39;s anything wrong with that). The difficulty for me stemmed from the tight specifications on the design &#8211; form field sizes really needed to be consistent across all browsers.<\/p>\n<p>Enter jQuery. Since there wasn&#39;t a clear CSS solution, I decided the easiest way to do this was with JavaScript, in particular, jQuery. By looping over all form fields and assigning a &quot;hard&quot; width and height based on their rows and cols values.<\/p>\n<p><code>function hardSizeInputs(multiplier, defaultWidth, defaultHeight) {<\/p>\n<p>\t&nbsp; if(typeof defaultWidth=== &#39;undefined&#39;)<br \/>\n\t&nbsp;&nbsp;&nbsp; var defaultWidth = 10;<\/p>\n<p>\t&nbsp; if(typeof defaultHeight=== &#39;undefined&#39;)<br \/>\n\t&nbsp;&nbsp;&nbsp; var defaultHeight = 1;<\/p>\n<p>\t&nbsp; $(&#39;textarea,input&#39;).each(function() {<br \/>\n\t&nbsp;&nbsp;&nbsp; $(this).css( { width: ($(this).attr(&#39;cols&#39;) || $(this).attr(&#39;size&#39;) || defaultWidth) * multiplier, <br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; height: $(this).attr(&#39;rows&#39;) || defaultHeight * multiplier } );<br \/>\n\t&nbsp; });<\/p>\n<p>\t}<br \/>\n\t<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday I was tasked with fitting a new design on a very old site. As expected, the existing site made heavy use of the rows,&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"amp_status":""},"categories":[5],"tags":[37],"_links":{"self":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/742"}],"collection":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/comments?post=742"}],"version-history":[{"count":1,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/742\/revisions"}],"predecessor-version":[{"id":743,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/742\/revisions\/743"}],"wp:attachment":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/media?parent=742"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/categories?post=742"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/tags?post=742"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}