html - 从 react-bootstrap 制作侧边栏

标签 html css twitter-bootstrap sidebar

我正在尝试在这里创建一个像这张图片一样的 Bootstrap 侧边栏。
sidebar
我已经查看了 react-bootstrap 和 Twitter Bootstrap 上的所有代码,但我还没有找到如何编写代码。基本上,如果他们在桌面上查看,我希望侧边栏可见,否则隐藏。
当页面上的内容上下滚动时,侧边栏应该保持静止。

最佳答案

好的,所以对于那些想要制作侧边栏的人来说,不幸的是,你必须自己制作。
我所做的是以下。

  • 请参阅 https://github.com/StartBootstrap/startbootstrap-simple-sidebar 中的示例
  • 在您的应用程序的某处创建 sidebar.js。

  • import React from "react";
    import {Nav} from "react-bootstrap";
    import { withRouter } from "react-router";
    import '../pages/style/Dashboard.css'
    
    const Side = props => {
       
    
        return (
            <>
        
                <Nav className="col-md-12 d-none d-md-block bg-light sidebar"
                activeKey="/home"
                onSelect={selectedKey => alert(`selected ${selectedKey}`)}
                >
                    <div className="sidebar-sticky"></div>
                <Nav.Item>
                    <Nav.Link href="/home">Active</Nav.Link>
                </Nav.Item>
                <Nav.Item>
                    <Nav.Link eventKey="link-1">Link</Nav.Link>
                </Nav.Item>
                <Nav.Item>
                    <Nav.Link eventKey="link-2">Link</Nav.Link>
                </Nav.Item>
                <Nav.Item>
                    <Nav.Link eventKey="disabled" disabled>
                    Disabled
                    </Nav.Link>
                </Nav.Item>
                </Nav>
              
            </>
            );
      };
      const Sidebar = withRouter(Side);
      export default Sidebar
    

  • 我的 Dashboard.css 中有以下内容。

  •  .sidebar {
            position: fixed;
            top: 0;
            bottom: 0;
            left: 0;
            min-height: 100vh !important;
            z-index: 100;
            padding: 48px 0 0;
            box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);
        }
        #sidebar-wrapper{
            min-height: 100vh !important;
            width: 100vw;
            margin-left: -1rem;
            -webkit-transition: margin .25s ease-out;
            -moz-transition: margin .25s ease-out;
            -o-transition: margin .25s ease-out;
            transition: margin .25s ease-out;
        }
        #sidebar-wrapper .sidebar-heading {
            padding: 0.875rem 1.25rem;
            font-size: 1.2rem;
        }
        
        #page-content-wrapper {
            min-width: 0;
            width: 100%;
        }
    

    然后最后一步
    在您希望它显示的文件中执行以下操作
    import React from "react";
    import {Container, Row, Col, Card, Form, Button } from "react-bootstrap";
    import { withRouter } from "react-router";
    import Sidebar from "../moduls/sidebar.js";
    import './style/Dashboard.css'
    
    const Dash = props => {
       
    
        return (
            <>
             <Container fluid>
                    <Row>
                        <Col xs={2} id="sidebar-wrapper">      
                          <Sidebar />
                        </Col>
                        <Col  xs={10} id="page-content-wrapper">
                            this is a test
                        </Col> 
                    </Row>
    
                </Container>
            </>
            );
      };
      const Dashboard = withRouter(Dash);
      export default Dashboard
    

    关于html - 从 react-bootstrap 制作侧边栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60482018/

    相关文章:

    javascript - 将输入动态保存到 JSON 后,将 JSON 文件中的数据调用到文本区域

    jquery - 如何根据页面滚动位置为对象设置动画

    javascript - 单击 anchor 时,如何定位没有任何 UL 的 LI

    css - 位于固定元素内的 100% 高度 div?

    php - 两个错误 - 在自定义管理面板上将一个项目标记为带有按钮

    javascript - HTML 重定向代码计时器

    javascript - BX-Slider 和 div 上的高度相等

    javascript - 当滚动到另一个 div 时,将 NavBar 放在顶部(即顶部 :100vh)

    html - Bootstrap 3 水平对齐文本和 div 中间的跨度

    javascript - jQuery:无法通过数据查找元素