简体   繁体   English

React Bootstrap 列未填充整个宽度

[英]React Bootstrap column not filling entire width

I'm using React and React Bootstrap 4.0.我正在使用 React 和 React Bootstrap 4.0。 I want a side-bar of 300px on the left side of the screen which is collapsible and the rest of the screen to be where the content is rendered.我希望屏幕左侧有一个 300px 的侧边栏,它是可折叠的,屏幕的 rest 是呈现内容的位置。

The parent component for the side-bar and content is the following:侧边栏和内容的父组件如下:

 import React from "react"; import './Home.scss'; import {Col, Container, Row} from "react-bootstrap"; import Sidebar from "./Sidebar/Sidebar"; const Home = () => { return ( <Container fluid className={"no-gutters mx-0 px-0"}> <Row xs={2} md={2} lg={2} xl={2} noGutters={true} className={""}> <Col lg={"auto"} xl={"auto"} className={""}> <Sidebar/> </Col> <Col className={""}> <div className={"nav-bar"}/> </Col> </Row> </Container> ) } export default Home;
 .nav-bar { width: 100%; height: 100px; outline: 1px solid blue; }.col { outline: 1px solid green; }

The Sidebar component is simply a div with a width of 300px and a height of 100vh. Sidebar 组件只是一个宽度为 300px,高度为 100vh 的 div。 My issue is that the second column (where the content will be rendered) seems to only take 50% of the screen up, leaving a gap to the right of it.我的问题是第二列(将呈现内容的地方)似乎只占据了屏幕的 50%,在它的右侧留下了一个空隙。 I want it to take up the entire remaining space as the Bootstrap documentation states it should.我希望它按照 Bootstrap 文档所述占用整个剩余空间。

Can anyone spot where I have gone wrong?谁能发现我哪里出错了?

The problem is the props on the Row .问题是Row上的道具。 It should just look like this...它应该看起来像这样......

<Container fluid className={"no-gutters mx-0 px-0"}>
    <Row noGutters={true}>
        <Col sm={"auto"}>
            <Sidebar/>
        </Col>
        <Col className={"border"}>
            <div className={"nav-bar"}/>
        </Col>
    </Row>
</Container>

Demo: https://codeply.com/p/IdzE9Wtvt4演示: https://codeply.com/p/IdzE9Wtvt4

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

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