简体   繁体   English

使用 React jsx 在页面渲染中重叠的组件

[英]Components overlapping in page render with react jsx

I want to add multiple components to route but when they render they are overlapping one another at the top of the page.我想添加多个组件来路由,但是当它们渲染时,它们在页面顶部相互重叠。 Individually they render fine, but when stacked in the.jsx route they overlap.它们单独渲染得很好,但是当堆叠在 .jsx 路由中时,它们会重叠。 I have tried many options to mitigate this without any change.我已经尝试了许多选项来减轻这种情况而没有任何改变。 I know I am missing something simple.我知道我错过了一些简单的东西。 Any help appreciated.任何帮助表示赞赏。 Thank you.谢谢你。

Header component Header组件

    import React from "react";

const Header = () => {
    return (
        <div className="fixed-top border-bottom">
            <h1 className="font-weight-medium display-1 text-center">
                Master Tracker
            </h1>
            <h3 className="font-weight-light text-center">
                Welcome to the Master Tracker System
            </h3>
        </div>
    );
};

export default Header;

Add New Form Component添加新的表单组件

import React from "react";

const AddNewFileMT = () => {
    return (
        <div className="m-2 pt-6 position-relative">
            <h2>
                Add New File to Master Tracker
            </h2>
            <form action="">
                <div className="row">
                    {/* Row 1 Column 1 */}
                    <div className="col-md-6">
                        <div className="form-group">
                            <label htmlFor="fcbc-rec-date">FCBC RECEIVED DATE</label>
                            <input type="text" className="form-control" placeholder="15/12/2020" id="fcbc-rec-date"/>
                        </div>
                    </div>
                    {/* Row 1 Column 2 */}
                    <div className="col-md-4">
                        <div className="form-group">
                            <label htmlFor="vfcbc">vFCBC</label>
                            <input type="text" className="form-control" placeholder="123456" id="vfcbc"/>
                        </div>
                    </div>
                    {/* Row 1 Column 3 */}
                    <div className="col-md-2">
                        <legend className="col-form-label">MULTIAGENCY</legend>
                        {/* CHECKBOX YES */}
                        <div className="form-check-inline">
                            <input className="form-check-input" type="checkbox" id="multiagency"/>
                            <label className="form-check-label" for="multiagency">
                                YES
                            </label>
                        </div>
                        {/* CHECKBOX NO */}
                        <div className="form-check-inline">
                            <input className="form-check-input" type="checkbox" id="multiagency"/>
                            <label className="form-check-label" for="multiagency">
                                NO
                            </label>
                        </div>
                    </div>
                </div>

                
            </form>
        </div>
    );
};

export default AddNewFileMT;

This is the route:这是路线:

import React from 'react';
import Header from '../components/Header';
import AddNewFileMT from '../components/AddNewFileMT';


const WTOminecaAddNew = () => {
    return (
        <div>
            <Header />
            <AddNewFileMT />
        </div>
    );
};

export default WTOminecaAddNew;

组件重叠反应jsx

First I would make sure that you have installed the Bootstrap npm package so that the css styles you've applied will take proper effect. First I would make sure that you have installed the Bootstrap npm package so that the css styles you've applied will take proper effect.

Secondly, you can also over-ride the bootstrap styles (or add your own additional classes) - by including a locally imported css file.其次,您还可以通过包含本地导入的 css 文件来覆盖引导程序 styles(或添加您自己的其他类)。

Here is an example: https://react-u4gpvw.stackblitz.io这是一个例子: https://react-u4gpvw.stackblitz.io

So in the React AddNewFileMT component, import a css file:所以在 React AddNewFileMT 组件中,导入一个 css 文件:

import "./NF.css";

And then in the css file, set over-riding styles to the bootstrap classes that are already in your html layout.然后在 css 文件中,将覆盖 styles 设置为已经在 html 布局中的引导类。

.form-group {
  border: 2px solid rgb(136, 136, 179);
  padding: 4px;
}

label {
  margin-right: 20px;
}

legend {
  padding: 8px;
  border: 2px solid rgb(136, 136, 179);
}

.form-check-label {
  padding-left: 8px;
}

.form-check-inline {
  padding: 8px;
  border: 2px solid rgb(136, 136, 179);
}

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

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