Flexbox行不显示DIV

发布于 2025-01-31 11:40:44 字数 1238 浏览 2 评论 0原文

我的Flexbox不是将两个Divs显示为列,而是在另一列下方显示。不确定为什么我有显示:flexflex方向:行

app.js文件:

import logo from "./logo.svg";
import "./App.css";

function App() {
  return (
    <div className="App">
      <div className="innerBox">
        <div className="innerBoxContent">
          <div className="menu">
            <h1>Menu</h1>
          </div>
          <div className="content">
            <h1>content</h1>
          </div>
        </div>
      </div>
    </div>
  );
}

export default App;

CSS文件:

.App {
  background-color: rgb(24, 24, 35);
  height: 100vh;
  width: 100vw;
  display: flex;
}

.innerBox{
  width: 600px;
  height: 600px;
  background-color: red;
  margin: auto;

  display: flex; 
  flex-direction: row;
}

.menu{
  background-color: blue;
  height: 600px;
  width: 300px;
}

.content
{
  background-color: orange;
  height: 600px;
  width: 300px;
}

图片:

有人可以解释为什么它不按预期工作。谢谢。

My Flexbox is not displaying two divs as columns but one underneth the other. Not sure why as I have display: flex and flex-direction: row.

App.js file:

import logo from "./logo.svg";
import "./App.css";

function App() {
  return (
    <div className="App">
      <div className="innerBox">
        <div className="innerBoxContent">
          <div className="menu">
            <h1>Menu</h1>
          </div>
          <div className="content">
            <h1>content</h1>
          </div>
        </div>
      </div>
    </div>
  );
}

export default App;

CSS file:

.App {
  background-color: rgb(24, 24, 35);
  height: 100vh;
  width: 100vw;
  display: flex;
}

.innerBox{
  width: 600px;
  height: 600px;
  background-color: red;
  margin: auto;

  display: flex; 
  flex-direction: row;
}

.menu{
  background-color: blue;
  height: 600px;
  width: 300px;
}

.content
{
  background-color: orange;
  height: 600px;
  width: 300px;
}

Picture:
Flex-box Displaying rows as columns

Can someone explain why its not working as intended. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

滥情空心 2025-02-07 11:40:44

“”
应在将flex-box应用于它时删除,而不是其内容

修复的HTML文件应该看起来像这样

import logo from "./logo.svg";
import "./App.css";

function App() {
  return (
    <div className="App">
      <div className="innerBox">       
          <div className="menu">
            <h1>Menu</h1>
          </div>
          <div className="content">
            <h1>content</h1>
          </div>
        
      </div>
    </div>
  );
}

export default App;

""
Should be removed as the flex-box is being applied to it and not its contents

Fix for HTML file should look like this

import logo from "./logo.svg";
import "./App.css";

function App() {
  return (
    <div className="App">
      <div className="innerBox">       
          <div className="menu">
            <h1>Menu</h1>
          </div>
          <div className="content">
            <h1>content</h1>
          </div>
        
      </div>
    </div>
  );
}

export default App;
留蓝 2025-02-07 11:40:44
.App {
  background-color: rgb(24, 24, 35);
  height: 100vh;
  width: 100vw;
  display: flex;
}

.innerBox{
  width: 600px;
  height: 300px;
  background-color: red;
  margin: auto;

  display: flex; 
  flex-direction: row;
}

.menu{
  background-color: blue;
  height: 60px;
  width: 300px;
    text-align: center;

}

.content
{
  background-color: orange;
  height: 60px;
    text-align: center;
  width: 300px;
}


/* add This Class*/
.innerBoxContent{
    display:flex;
    aling-item:center;
    justify-content:center;
    
}




import logo from "./logo.svg";
import "./App.css";

function App() {
  return (
    <div className="App">
      <div className="innerBox">
        <div className="innerBoxContent">
          <div className="menu">
            <h1>Menu</h1>
          </div>
          <div className="content">
            <h1>content</h1>
          </div>
        </div>
      </div>
    </div>
  );
}

export default App;
.App {
  background-color: rgb(24, 24, 35);
  height: 100vh;
  width: 100vw;
  display: flex;
}

.innerBox{
  width: 600px;
  height: 300px;
  background-color: red;
  margin: auto;

  display: flex; 
  flex-direction: row;
}

.menu{
  background-color: blue;
  height: 60px;
  width: 300px;
    text-align: center;

}

.content
{
  background-color: orange;
  height: 60px;
    text-align: center;
  width: 300px;
}


/* add This Class*/
.innerBoxContent{
    display:flex;
    aling-item:center;
    justify-content:center;
    
}




import logo from "./logo.svg";
import "./App.css";

function App() {
  return (
    <div className="App">
      <div className="innerBox">
        <div className="innerBoxContent">
          <div className="menu">
            <h1>Menu</h1>
          </div>
          <div className="content">
            <h1>content</h1>
          </div>
        </div>
      </div>
    </div>
  );
}

export default App;
守不住的情 2025-02-07 11:40:44

CSS属性Flex-wrap:Nowrap;应添加到具有类名称.innerbox的容器中。

.innerBox{
  width: 600px;
  height: 600px;
  background-color: red;
  margin: auto;

  display: flex; 
  flex-direction: row;
  flex-wrap: nowrap;
}

CSS property flex-wrap: nowrap; should be added to container with class name .innerBox.

.innerBox{
  width: 600px;
  height: 600px;
  background-color: red;
  margin: auto;

  display: flex; 
  flex-direction: row;
  flex-wrap: nowrap;
}
给妤﹃绝世温柔 2025-02-07 11:40:44

您拥有菜单content组件在内部。InnerContent block。
因此,.innerboxContent应该是flex。

.innerBoxContent {
   display: flex;
   flex-direction: row;
}

You have menu and content components are inside of .innerContent block.
So .innerBoxContent should be flex.

.innerBoxContent {
   display: flex;
   flex-direction: row;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文