[英]Different behaviour of Flexbox in chrome and firefox
I am trying to build a web page with dynamic layout using Flexbox and React. 我正在尝试使用Flexbox和React构建具有动态布局的网页。 When flex-direction is toggled from column to row and back to column, width of flex items is not reflecting as expected in chrome. 当将弹性方向从一列切换到一列然后再切换到一列时,弹性项目的宽度不会像预期的那样反映在chrome中。
I created a jsfiddle to explain this problem 我创建了一个jsfiddle来解释这个问题
http://jsfiddle.net/kirana/u44fjqdj/4/ (Reactjs Version) http://jsfiddle.net/kirana/u44fjqdj/4/(Reactjs版本)
http://jsfiddle.net/kirana/vm9jcr1t/2/ (Jquery version) http://jsfiddle.net/kirana/vm9jcr1t/2/(jQuery版本)
In the above jsfiddle example, Flex container has a width of 400px and the four child flex items has a width of 400px flowing from top to bottom. 在上面的jsfiddle示例中,Flex容器的宽度为400px,四个子flex项的宽度从顶部到底部为400px。 When flex-direction is changed to row, child items width is reduced to 100px to fit in the row. 当flex-direction更改为row时,子项的宽度减小到100px以适合该行。 When the flex-direction is changed back to column, child items width should revert back to 400px, but width is remaining at 100px in Chrome and it is working as expected in firefox; 当flex-direction改回column时,子项的宽度应恢复为400px,但是Chrome中的宽度保持在100px,并且在firefox中可以正常工作;
How to get around this problem ? 如何解决这个问题?
var FlexItem = React.createClass({
render: function () {
var itemStyle = {
width: 400,
height: 100,
border: '1px solid red',
};
return React.DOM.div({
style: itemStyle
}, 'some text');
}
});
var FlexContainer = React.createClass({
getInitialState: function () {
return {
direction: 'column'
};
},
toggle: function () {
this.setState({
direction: (this.state.direction === 'row') ? 'column' : 'row'
});
},
render: function () {
var containerStyle = {
display: '-moz-flex',
display: '-webkit-flex',
display: 'flex',
MozFlexDirection: this.state.direction,
WebkitFlexDirection: this.state.direction,
flexDirection: this.state.direction,
width: 400,
border: '1px solid green',
};
var container = React.DOM.div({
style: containerStyle
}, FlexItem(), FlexItem(), FlexItem(), FlexItem());
var button = React.DOM.button({
onClick: this.toggle,
className: 'button'
}, 'Toggle');
return React.DOM.div({}, button, container);
}
});
React.renderComponent(FlexContainer(), document.body);
Seems like this isn't an issue with React nor jQuery at all. 似乎这根本不是React和jQuery的问题。 You appear to be hitting a bug in Chrome. 您似乎在Chrome中遇到了错误。 You should make sure it's not present in Canary and find/file on https://code.google.com/p/chromium/issues/list . 您应该确保它不存在于Canary中,并在https://code.google.com/p/chromium/issues/list上找到/文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.