简体   繁体   English

无法将按钮换行到新行而不是溢出容器

[英]Can't get buttons to wrap to new line instead of overflowing container

I couldn't get a JSFiddle to work properly with React and some other dependencies, so I hope the link to this Github repo is sufficient for demonstrating the issue: 我无法让JSFiddle与React和其他一些依赖项一起正常工作,所以我希望与此Github存储库的链接足以说明问题:

https://github.com/ishraqiyun77/button-issues/ https://github.com/ishraqiyun77/button-issues/

Basically, a group of buttons is rendered and they should be auto-widened to fill white space and take up the whole row. 基本上,呈现了一组按钮,应该将它们自动加宽以填充空白并占据整个行。 This works in Chrome, Edge, Safari, and Firefox. 这适用于Chrome,Edge,Safari和Firefox。 It looks like this: 看起来像这样:

在此处输入图片说明

This isn't happening in IE. IE中不会发生这种情况。 I've been messing with it for hours and haven't made much progress: 我已经把它弄弄了好几个小时,但进展不大:

在此处输入图片说明

Here is the code, although could clone the repo I posted above: 这是代码,尽管可以克隆我上面发布的仓库:

// component.jsx
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import {
    Button,
    Col,
    Modal,
    ModalBody,
    ModalHeader,
    Row
} from 'reactstrap';

import styles from '../assets/scss/app.scss';

class TestPrint extends Component {
    constructor(props) {
        super(props);
        this.state = {
            modal: false,
        }
        this.toggle = this.toggle.bind(this);
    }

    toggle() {
        this.setState({
            modal: !this.state.modal
        })
    }

    renderContent() {
        let buttons = [];
        for (let i = 1; i < 50; i++) {
            buttons.push(
                <Col key={i}>
                    <Button
                        key={i}
                        className='cuts-btn'
                    >
                        {i} - Test
                    </Button>
                </Col>
            );
        };
        return buttons;
    }

    render() {
        return (
            <div>
                <Button
                    style={
                        {
                            position: 'fixed',
                            top: '50%',
                            left: '50%',
                            transform: 'translate(-50%, -50%)'
                        }
                    }
                    onClick={this.toggle}
                >
                    Open Modal for Buttons
                </Button>
                <Modal
                    size='lg'
                    isOpen={this.state.modal}
                    toggle={this.toggle}
                    className='results-modal'
                >
                    <ModalHeader toggle={this.toggle}>
                        Button Issues
                    </ModalHeader>
                    <ModalBody>
                        <div className='results-bq-cuts'>
                            <Row>
                                {this.renderContent()}
                            </Row>
                        </div>
                    </ModalBody>
                </Modal>
            </div>
        )
    }
}

ReactDOM.render(<TestPrint />, document.getElementById('app'));

.results-modal {
    max-width: 1200px;

    .modal-content {

        .modal-body {
            margin-left: 13px;
            margin-right: 13px;

            .results-bq-cuts {
                width: 100%;

                .col {
                    padding:2px;
                }

                .cuts-btn {
                    font-size: 11px;
                    padding: 3px;
                    width: 100%;
                    box-shadow: none;
                }

                // .col {
                //     padding: 2px;
                //     display: table-cell;
                //     flex-basis: 100%;
                //     flex: 1;
                // }

                // .cuts-btn {
                //     font-size: 11px;
                //     padding: 3px;
                //     width: 100%;
                //     box-shadow: none;
                // }


            }
        }
    }
}

I have all of the <Button> wrapped in <Col> because that should be what is filling the white space by increasing the size of the button. 我将所有<Button>包裹在<Col>因为那应该是通过增加按钮的大小来填充空白的地方。

Thanks for the help! 谢谢您的帮助!

IE11 doesn't like working out the width of flex items. IE11不喜欢计算弹性项目的宽度。 If you add flex-basis: calc( 100% / 24 ); 如果添加flex-basis: calc( 100% / 24 ); to .col it works :) Obviously use any width you want, but what I've given replicates the 21 boxes on one line. 到.col它起作用:)显然可以使用您想要的任何宽度,但是我给出的内容将21个框复制到一行上。 But essentially flex-basis needs a defined width to work. 但是本质上,flex-basis需要定义的宽度才能工作。

Or add an extra class to each element (such as col-1 ) This'll also achieve the same thing. 或向每个元素添加一个额外的类(例如col-1 ),这也将实现相同的目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM