{"id":528,"date":"2010-02-25T16:21:00","date_gmt":"2010-02-25T22:21:00","guid":{"rendered":"http:\/\/cssnewbie.com\/?p=528"},"modified":"2010-02-25T16:21:00","modified_gmt":"2010-02-25T22:21:00","slug":"input-button-line-height-bug","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/input-button-line-height-bug\/","title":{"rendered":"The Firefox Input Button Line-Height Bug"},"content":{"rendered":"<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2010\/02\/button-sizes-by-browser.png\" alt=\"\" title=\"Button Sizes Using Line-Height by Browser\" width=\"500\" height=\"101\" class=\"alignnone size-full wp-image-529\" \/><\/p>\n<p>I recently ran into a bug in Firefox and Opera when I tried to set the line height of text inside a button (which affects input &#8220;submit&#8221; buttons as well as the HTML button tag). The bug? The line height can&#8217;t be changed!<\/p>\n<p>For example, take the following code:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">input#button {\n\tborder: 2px solid #06f;\n\tcolor: #06f;\n\tbackground-color: #6cf;\n\tfont: bold 12px Arial, Helvetica, sans-serif;\n\tline-height: 50px;\n}<\/pre>\n<p>In a perfect world, this code would be a quick and easy way to vertically center text inside a button and set the button&#8217;s height, since text is always centered inside of the space created by its line-height. <\/p>\n<p>But the results are inconsistent. Chrome, Safari, and (I can&#8217;t believe this either) Internet Explorer 8 all center the text and resize the button just like I&#8217;d expect. But the results are less than perfect in Firefox and Opera (see the image above). <!--more--><\/p>\n<h3>The Problem, Defined<\/h3>\n<p>A quick look at Firebug proves enlightening: even though I&#8217;ve specified a line-height of 50px, Firefox is using a line-height of 15px instead.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2010\/02\/firebug-firefox-line-height.png\" alt=\"\" title=\"Firebug showing Firefox&#039;s incorrect line-height\" width=\"500\" height=\"220\" class=\"alignnone size-full wp-image-530\" \/><\/p>\n<p>So what gives?<\/p>\n<p>It seems our bug isn&#8217;t really a bug at all, but a &#8220;feature&#8221;: that is, it&#8217;s a deliberate decision by Firefox to limit line heights on buttons. This is evidenced by this line of CSS in Firefox&#8217;s default CSS:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">button, input[type=\"reset\"], input[type=\"button\"], input[type=\"submit\"] {\n\tline-height:normal !important;\n}<\/pre>\n<p>Basically, Firefox is setting the line-height to &#8220;normal&#8221; on buttons and is enforcing this decision with an !important declaration. This is a frustrating decision on their part, particularly considering (as Eric Meyer has pointed out at great and detailed length), <a href=\"http:\/\/meyerweb.com\/eric\/thoughts\/2008\/05\/06\/line-height-abnormal\/\">line-height: normal is anything but.<\/a> <\/p>\n<p>And while trying to work around this rule, I discovered something that makes the situation a little more dire: browser-defined !important rules cannot be over-ruled by author-defined !important rules. This rule cannot be overruled by a CSS file, an inline style &mdash; anything.<\/p>\n<p>So what&#8217;s to be done?<\/p>\n<p>After a couple of hours of teeth-gnashing, I&#8217;ve settled on the following as an acceptable workaround. <strong>Instead of using line-height, use padding.<\/strong><\/p>\n<p>So to take the example from earlier, we&#8217;d convert it to look like this instead:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">input#button {\n\tborder: 2px solid #06f;\n\tcolor: #06f;\n\tbackground-color: #6cf;\n\tfont: bold 12px Arial, Helvetica, sans-serif;\n\tpadding: 18px 6px;\n}<\/pre>\n<p>This effectively centers the text inside our buttons, but it isn&#8217;t ideal. It means there&#8217;s no easy way to ensure our buttons are using the same line-height as the rest of our content, and it means the size of the button can&#8217;t be dependent upon the size of the button text. But I&#8217;ll take what I can get on this one.<\/p>\n<div class=\"wp-socializer wpsr-share-icons \" data-lg-action=\"show\" data-sm-action=\"show\" data-sm-width=\"768\" ><h3>Share and Enjoy !<\/h3><div class=\"wpsr-si-inner\"><div class=\"wpsr-counter wpsrc-sz-32px\" style=\"color:#000\"><span class=\"scount\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook,twitter,linkedin,pinterest,print,pdf\">0<\/span><\/span><small class=\"stext\">Shares<\/small><\/div><div class=\"socializer sr-popup sr-32px sr-circle sr-opacity sr-pad sr-count-1 sr-count-1\"><span class=\"sr-facebook\"><a rel=\"nofollow\" href=\"https:\/\/www.facebook.com\/share.php?u=\" target=\"_blank\"  title=\"Share this on Facebook\"  style=\"color: #ffffff\" ><i class=\"fab fa-facebook-f\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-twitter\"><a rel=\"nofollow\" href=\"https:\/\/twitter.com\/intent\/tweet?text=%20-%20%20\" target=\"_blank\"  title=\"Tweet this !\"  style=\"color: #ffffff\" ><i class=\"fab fa-twitter\"><\/i><\/a><\/span>\n<span class=\"sr-linkedin\"><a rel=\"nofollow\" href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=\" target=\"_blank\"  title=\"Add this to LinkedIn\"  style=\"color: #ffffff\" ><i class=\"fab fa-linkedin-in\"><\/i><\/a><\/span>\n<span class=\"sr-pinterest\"><a rel=\"nofollow\" href=\"https:\/\/www.pinterest.com\/pin\/create\/button\/?url=&amp;media=&amp;description=\" target=\"_blank\"  title=\"Submit this to Pinterest\"  style=\"color: #ffffff\" data-pin-custom=\"true\"><i class=\"fab fa-pinterest\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"pinterest\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-print\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Print this article \"  style=\"color: #ffffff\" ><i class=\"fa fa-print\"><\/i><\/a><\/span>\n<span class=\"sr-pdf\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Convert to PDF\"  style=\"color: #ffffff\" ><i class=\"fa fa-file-pdf\"><\/i><\/a><\/span><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>I recently ran into a bug in Firefox and Opera when I tried to set the line height of text inside a button (which affects input &#8220;submit&#8221; buttons as well as the HTML button tag). The bug? The line height can&#8217;t be changed! [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/input-button-line-height-bug\/\" title=\"Click to read 'The Firefox Input Button Line-Height Bug'\">Read Article<\/a><\/p>\n","protected":false},"author":18,"featured_media":530,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[169,170],"tags":[211,212,215,265,288,310],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/528"}],"collection":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/comments?post=528"}],"version-history":[{"count":0,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/528\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media\/530"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}