Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flexbox not working in buttons in Firefox

Apparently Firefox doesn't like display: flex on buttons. Is there a way to t correct this?

CSS:

button {
    width: 100%;
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-box;
    display: -ms-flexbox;
    display: flex;
}

    button div:first-child {
        -webkit-box-ordinal-group: 2;
        -webkit-order: 2;
        -moz-box-ordinal-group: 2;
        -ms-flex-order: 2;
        order: 2;
    }

    button div:last-child {
        -webkit-box-ordinal-group: 1;
        -webkit-order: 1;
        -moz-box-ordinal-group: 1;
        -ms-flex-order: 1;
        order: 1;
    }

HTML:

<button>
    <div>
        <p>First</p>
    </div>
    <div>
        <p>Second</p>
    </div>
</button>

Live demo: http://jsbin.com/ziwadabo/2

like image 754
JacobTheDev Avatar asked Jun 18 '14 15:06

JacobTheDev


People also ask

Does flexbox work on all browsers?

Flexbox is very well supported across modern browsers, however there are a few issues that you might run into.

Is flexbox and flex the same?

A flex layout can also wrap in multiple rows or columns and flexbox treats each row or column as a separate entity, based on its content and the available space. On the other hand, CSS Grid lets you work along two axes: horizontally and vertically.

Does flexbox work with position fixed?

position:fixed makes flexbox not workable, since it overrides the position of <p>Hello</p> Try to remove it and see the difference. If you want align-items:center works; try to set height: 100vh; since the body height of webview is not set to screen height by default.


1 Answers

tl;dr: Just put a div inside of your <button>, and make that div display:flex.

See https://bugzilla.mozilla.org/show_bug.cgi?id=984869#c2 for why display doesn't do what you expect on <button> in Firefox (and for similar things that don't work in Firefox or Webkit/Blink, for similar reasons).

Here's your modified jsbin: http://jsbin.com/ziwadabo/4/

like image 92
dholbert Avatar answered Oct 08 '22 20:10

dholbert