css - Ant 设计中的卡片漂浮在固定的导航栏上

标签 css reactjs antd

我使用 ant design 制作了一个单页应用程序。我固定了顶部的导航栏,现在滚动时内容中的卡片会 float 在导航栏上。

顶部菜单/导航栏代码

import React,{Component} from 'react'
import {Layout, Menu, Row, Col, Icon} from 'antd'
import Logo from './Glogo.png'
const {Header}=Layout
const SubMenu = Menu.SubMenu;
const MenuItemGroup = Menu.ItemGroup;

export default class TopMenu extends Component{

render(){
return(
        <Header style={{position: 'fixed', width: '100%' }}>
        <img src={Logo} style={{height:"40px", width:"140px", 
float:"left", marginTop:"10px"}}alt="Logo"/>
            <Menu
                theme="dark"
                mode="horizontal"
                style={{ lineHeight: '64px' }}
            >

            </Menu>
        </Header> 
)
}
}

在标题中我声明位置是固定的。 内容代码:

import React, {Component} from 'react';
import {Layout, Card, Row, Col, List} from 'antd';

const {Content} = Layout;

class Dashboard extends Component{
    constructor(props){
        super();
        this.state={
            session_id:[
                {
                    event:"underline",
                    timestamp:"10:30",
                    observation:["magnetic effect","flemings right hand rule","magnetic effect","flemings right hand rule","magnetic effect","flemings right hand rule","magnetic effect","flemings right hand rule","magnetic effect","flemings right hand rule"], 
                    suggestions:["take a look at this concept", " watch this video"]
                },
                {
                    event:"underline",
                    time:"10:30",
                    observation:["magnetic effect","flemings right hand rule"], 
                    suggestions:["take a look at this concept", " watch this video"]
                },

                {
                    event:"underline",
                    time:"10:30",
                    observation:["magnetic effect","flemings right hand rule"], 
                    suggestions:["take a look at this concept", " watch this video"]
                },

            ]


        }
    }

    render(){

        return(
            <Content style={{ padding: '0 50px', marginTop: 64, minHeight: "calc(100vh - 128px)" }}>
                <div style={{ background: '#fff', padding: 24, minHeight: 500, marginBottom:"30px" }}>
                    {this.state.session_id.map((val, i)=>
                    <Card key={i}hoverable style={{margin:"15px", boxShadow:"0 0 10px gray "}}>
                        <Row gutter={16}>
                        <Col xs={24} sm={24} md={8} lg={8} >
                            <Card title="Event" hoverable bordered={false}>
                            Name: {val.event}<br/>Time: {val.time}
                            </Card>
                        </Col>
                        <Col xs={24} sm={24} md={8} lg={8} >
                            <Card title="Observation" hoverable bordered={false}>
                            <List
                                size="small"
                                bordered
                                dataSource={val.observation}
                                renderItem={item => (<List.Item>{item}</List.Item>)}
                            />
                            </Card>
                        </Col>
                        <Col xs={24} sm={24} md={8} lg={8} >
                            <Card title="Suggestions" hoverable bordered={false}>
                            <List
                                size="small"
                                bordered
                                dataSource={val.suggestions}
                                renderItem={item => (<List.Item>{item}</List.Item>)}
                            />
                            </Card>
                        </Col>
                        </Row>
                    </Card>)}
                </div>
            </Content>
        )
    }
}

export default Dashboard;

内容中的卡片 float 在固定标题上方,而内容本身位于标题下方。

我希望导航栏位于其他所有内容之上。我能做些什么。 enter image description here

最佳答案

May z-index 会在您的情况下为您提供帮助。

<Header style={{position: 'fixed', width: '100%', zIndex: 100}}>

关于css - Ant 设计中的卡片漂浮在固定的导航栏上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48822683/

相关文章:

javascript - 有没有办法缩小我的菜单按钮的回调?

javascript - React 实例值或 State 以进行较小的 UI 更新

javascript - 我如何正确地进行插入?

javascript - 在没有 getFieldDecorator 的情况下将 react-input-mask 与 antd 一起使用

javascript - antd 上传控件需要 action 函数,但我不需要它

html - MVC 中的样式下拉列表

html - 某些括号内容未显示

javascript - 在我的 AngularJS 动画中,这个动画延迟来自哪里?

javascript - React-router 4 滚动恢复可防止 anchor 链接的 native 行为

javascript - 如何将数据API放入Ant Design Cascader中?