【问题标题】:React and Bulma: How to make column vertically scrollable using css?React 和 Bulma:如何使用 css 使列垂直滚动?
【发布时间】:2020-12-10 23:55:24
【问题描述】:

使用 React 和 Bulma columns,如何使用 css 使列垂直滚动(溢出-y)?

在下面提供的代码中,由于 Filters 组件,我只是获取了显示在第一列中的一堆过滤器。然后我想使用 DocumentListView 组件显示文档列表。这发生在第二列中。

请注意,我在第二列中添加了一个 scrollable 类,以使该列垂直滚动。

import React from 'react'
import Filters from './components/Filters/Filters'
import DocumentListView from './components/DocumentListView/DocumentListView'
import { fetchFilters } from './_actions'
import { connect } from 'react-redux'
import { BrowserRouter } from 'react-router-dom'

import './App.css'


class App extends React.Component {
    componentDidMount() {
        this.props.fetchFilters()
    }

    render() {
        return (
            <BrowserRouter>
                <div className='App'>
                    <div className='columns'>
                        <div className='column is-one-fifth'>
                            <Filters />
                        </div>
                        <div className='column scrollable'>
                            {/* This column should be vertically scrollable */}
                            <DocumentListView />
                        </div>
                        <div className='column'></div>
                    </div>
                </div>
            </BrowserRouter>
        )
    }
}

const mapDispatchToProps = (dispatch) => {
    return {
        fetchFilters: () => dispatch(fetchFilters()),
    }
}

export default connect(null, mapDispatchToProps)(App)

这是我正在使用的 App.css 文件:

html,
body {
    width: 100% !important;
    height: 100% !important;
    max-height: 100%;
    background-color: lightgray;
    overflow: hidden;
}

.App {
    width: 100%;
    height: 100%;
    padding: 2%;
}

.columns {
    height: 100%;
}

.scrollable {
    height: 100%;
    width: 100%;
    overflow-y: auto;
}

感谢您的帮助。

【问题讨论】:

    标签: css reactjs bulma


    【解决方案1】:

    将最大高度添加到列类。像这样:-

    .columns{
    max-height: 200px;
    }
    

    如果您希望中心 div 的高度取决于其兄弟,请执行以下操作:-

    .scrollable{
       height: 100%;
       position: relative;
    }
    
    .scrollable>div{
       position: absolute;
       height: 100%;
       width: 100%;
       left: 0;
       top: 0;
       overflow-y: auto
    }
    

    我希望它会工作

    【讨论】:

    • 非常感谢。我不得不将 max-height 更改为 650px,以便第二列使用几乎所有垂直空间。为什么我不能将列的最大高度设置为 100%?
    • max-height 100% 是 div 所包含的内容。这意味着最大高度等于 div 的高度
    猜你喜欢
    • 2012-03-31
    • 2017-12-07
    • 1970-01-01
    • 2016-01-28
    • 2022-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-20
    相关资源
    最近更新 更多