容器,行,列-在React-Bootstrap中不起作用

Fra*_*ank 0 html javascript css reactjs react-bootstrap

我目前正在尝试学习React和React-Bootstrap。

我试图充分利用React-Bootstrap网格布局。我不确定是否执行不正确。我的直觉说我在某个地方使用了不合适的版本,因为据我所知,“容器,列,行”功能根本不起作用。

可能是什么问题?我没主意了。

package.json中的版本:

  "dependencies": {
    "bootstrap": "^4.3.1",
    "jquery": "^3.0.0",
    "react": "^16.8.4",
    "react-bootstrap": "^1.0.0-beta.6",
    "react-dom": "^16.8.4",
    "react-scripts": "2.1.8",
    "typescript": "^3.3.4000"

Run Code Online (Sandbox Code Playgroud)

来自“ bootstrap”目录的package.json:

  "_from": "bootstrap@latest",
  "_id": "bootstrap@4.3.1",
Run Code Online (Sandbox Code Playgroud)

来自“ react-bootstrap”目录的package.json:

  "_from": "react-bootstrap@^1.0.0-beta.6",
  "_id": "react-bootstrap@1.0.0-beta.6",
Run Code Online (Sandbox Code Playgroud)

请注意,我也尝试过安装和使用bootstrap@3时没有运气:

npm install bootstrap@3 --save npm i --save bootstrap@3

index.js的主要代码段:

import React from 'react';
import ReactDOM from 'react-dom';
import Container from 'react-bootstrap/Container';
import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';

class Module extends React.Component
{
  constructor(props)
  {
    super(props);
  }

  clickHandler = (command) =>
  {
    // ... some handler code here
  }

  render()
  {
    return (
      <Container>
        <Row>
          <Col>
            <table>
              <tr>
                <th class="r1_header"> Header 1 </th>
                <th class="r1_header"> Header 2 </th>
                <th class="r1_header"> Header 3 </th>
              </tr>
              <tr>
                <td> <button/> </td> // some more button stuff here
                <td> <button/> </td>
                <td> <button/> </td>
              </tr>
              <tr>
                <td> <button/> </td>
                <td> <button/> </td>
                <td> <button/> </td>
              </tr>
              <tr>
                <td> <button/> </td>
                <td> <button/> </td> 
                <td> <button/> </td>
              </tr>
              <tr>
                <th class="r2_header"> Header 1 </th>
                <th class="r2_header"> Header 2 </th>
                <th class="r2_header"> Header 3 </th>
              </tr>
              <tr>
                <td> <button/> </td>
                <td> <button/> </td>
                <td> <button/> </td>
              </tr>
              <tr>
                <td> <button/> </td>
                <td> <button/> </td>
                <td> <button/> </td>
              </tr>
              <tr>
                <td> <button/> </td>
                <td> <button/> </td>
                <td> <button/> </td>
              </tr>
            </table>
          </Col>
          <Col>
            // another table here... should be aligned next to the
            // prev "col" horizontally but is going underneath (vertically)
          </Col>
        </Row>
      </Container>
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

*更新*

这是MCVE ...

代码框

显示的文本应为HelloWorld

Hello
World
Run Code Online (Sandbox Code Playgroud)

B1z*_*zle 18

根据反应文档,您必须先安装引导程序

npm 安装 react-bootstrap 引导程序

那么你必须在你的 index.js 或 App.js 中导入这一行

import 'bootstrap/dist/css/bootstrap.min.css';
Run Code Online (Sandbox Code Playgroud)

然后你可以在你的组件中像这样导入import { Container, Row, Col } from 'react-bootstrap'; 并像这样使用

 <Container>
                <Row>
                    <Col>1</Col>
                    <Col>2</Col>
                    <Col>3</Col>
                </Row>
            </Container>
Run Code Online (Sandbox Code Playgroud)


Fra*_*ank 5

我已经解决了这个问题。对我而言,这是一个错过的步骤。我错过了关于样式表的react-bootstrap主要概述中设置的关键部分。

index.html复制和粘贴的路径,最新的引导样式表:

<link
  rel="stylesheet"
  href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
  integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
  crossorigin="anonymous"
/>
Run Code Online (Sandbox Code Playgroud)