4

I'm having an issue in Chrome 40.0.2214.93 where if I override the justify-content for an element I get some unexpected behavior.

I've created a JS Fiddle for this here: http://jsfiddle.net/n670tmeu/

html

<header id="top">
  <div id="box1">
    This is Box 1
  </div>
  <div id="box2">
    This is Box 2
  </div>
</header>

css

header {
  background-color: #ccc;
  width: 100%;
  display: -webkit-flex;
  display: -moz-flexbox;
  display: -ms-flexbox;
  display: flex;
  -webkit-justify-content: flex-end;
     -moz-justify-content: flex-end;
      -ms-justify-content: flex-end;
          justify-content: flex-end;
}

header#top {
  -webkit-justify-content: space-between;
     -moz-justify-content: space-between;
      -ms-justify-content: space-between;
          justify-content: space-between;
}

#box1, #box2 {
  border-width: 1px;
  border-style: solid;
  border-color: red;
}

You'll notice that the more specific header#top overrides the justify-content however in Chrome it ends up pushing the first item to the flex-end position then adds extra space for for the space-between.

I've tried this in FireFox 35.0.1 and Safari 7.1.2 and they both work properly. Is this a bug in Chrome or did I do something wrong?

Eric Norcross
  • 4,177
  • 4
  • 28
  • 53

1 Answers1

2

This is a known bug that is fixed as of the latest canary build (42.0.2289.0):

https://code.google.com/p/chromium/issues/detail?id=452606

In the meantime, you can use this jQuery workaround as a temporary fix:

$('body *').each(function(i, el) {
    var justifyContents = $(el).css('justify-content').split(' ');
    var flexFlows = $(el).css('flex-flow').split(' ');
    if (flexFlows[0] == 'row' && justifyContents.length > 1) {
        if (justifyContents[0] == 'space-between' || justifyContents[0] == 'flex-start') {
            $(el).css('justify-content', justifyContents[0]+' left');
        } else if (justifyContents[0] == 'flex-end') {
            $(el).css('justify-content', justifyContents[0]+' right');
        }
    }
});
Elemental
  • 36
  • 3
  • And here is another SO question addressing the same bug: http://stackoverflow.com/questions/28109129/is-this-a-chrome-css-bug – Elemental Jan 28 '15 at 23:51