css 如何在React中并排显示两个不同的容器?

hc2pp10m  于 2023-05-08  发布在  React
关注(0)|答案(1)|浏览(156)

我想把顺序面板和顺序菜单并排,他们是2个不同的组件(容器)。在我的css中,我尝试了display:inline-block和flex-direction:row。我在父组件(Order)上尝试了flex,但它减少了两个组件的宽度。很简单的事情,但是我做不到。有人能帮我找出错误吗?

import React from "react";
import Container from "@material-ui/core/Container";
import Stack from "@mui/joy/Stack";
import OrderPanel from "./OrderPanel";
import OrderMenu from "./OrderMenu";
import "./Order.css";

function Order()  {
  return (
    <>
      <div className="Order">
          <OrderPanel />
          <OrderMenu/>
      </div>
    </>
  );
  
};

export default Order;

import React from "react";
import Container from "@material-ui/core/Container";
import Stack from "@mui/joy/Stack";
import OrderPanel from "./OrderPanel";
import "./Order.css";

function OrderMenu() {
  return (
    <>
      <div className="Order-Menu">
        <Container>Order Menu</Container>
      </div>
    </>
  );
}

export default OrderMenu;

import React from "react";
import Container from "@material-ui/core/Container";
import Stack from "@mui/joy/Stack";
import "./Order.css";
import Order from "./Order";

function OrderPanel() {
  return (
    <>
      <div className="Order-Panel">
        <Container>Order Panel</Container>
      </div>
    </>
  );
}

export default OrderPanel;
.Order {
    background-color:darkkhaki;
    height: 50%;
    flex-direction: row;
}

.Order-Panel{
    background-color: beige;
    margin-left: 2vw;
    margin-right: 60vw;
    margin-top: 2vh;
    height: 60vh;
    width: 50vh;
    flex-direction: row;
    display: inline-block;
    
}

.Order-Menu{
    background-color: aquamarine;
    margin-top: 2vh;
    margin-left:2vw;
    height:10vw;
    width: 45vh;
    display: inline-block;
    flex-direction: row;
}
lnvxswe2

lnvxswe21#

关注多文档(一种方式)

如果使用mui,建议使用sxprop。Mui grid docs
另一方面,要并排放置两个容器,可以使用Grid mui组件。

<Grid container spacing={2}>
    <Grid item xs={6}>
      <Item>xs=6</Item>
    </Grid>
    <Grid item xs={6}>
      <Item>xs=6</Item>
    </Grid>
</Grid>

生成容器Resulting output
xs={6}设置Grid item可以采用的网格列(默认情况下Grid container有12列)

相关问题