gpt4 book ai didi

css - 使用 CSS 和 React 并排排列两个 div

转载 作者:技术小花猫 更新时间:2023-10-29 10:31:23 27 4
gpt4 key购买 nike

如图所示,我有两个组件并排排列:Dashboard

我正在使用 React,带有 Negotiationfrontendfood 的组件具有从另一个组件传递的元素。

我如何设计它以便每个元素(NegotiationFrontendfood)彼此分开但仍在同一列中旁边排着新闻?

我的 JavaScript:

class Course extends React.Component {
render() {
return (
<div>
<div className="coursecontent">
<h3>{this.props.coursename}</h3>
<h4> {this.props.status} {this.props.progress}</h4>
</div>
<button className="coursecontent">Start exercise</button>
</div>
);
}
}

class Welcomebox extends React.Component {
render() {
return <h1>Welcome Naomi</h1>;
}
}

ReactDOM.render(<Welcomebox />, document.getElementById('welcomebox'));

class Coursebox extends React.Component {
render() {
return (
<div className="box-field">
<Course coursename="Negotiation" progress= "20%" status="Progress"/>
<Course coursename="Frontend" progress="56%" status="Progress"/>
<Course coursename="Food" status="Progress" progress="43%"/>
</div>
);
}
}

class Newsbox extends React.Component {
render() {
return (
<div className="box-field" className="newsbox">
<h3>News</h3>
</div>
);
}
}

class Dashboardbox extends React.Component {
render() {
return (
<div className="dashboardbox">
<Coursebox />
<Newsbox />
</div>
);
}
}

ReactDOM.render(<Dashboardbox />, document.getElementById('dashboardbox'));

我的 CSS:

.box-field,
.newsbox {
width: 45%;
background-color: lightgrey;
font-family: arial;
margin-left: 30px;
height: 80%;
padding: 5px 10px 10px 10px;
border-radius: 10px;
display: inline-block;
}

所以基本上,在每个 Course 元素之间我想要空间(最好用 Margin 设置),并且我想要 Newsbox 组件与 Coursebox 组件对齐。

最佳答案

Coursebox 旁边添加新的 Newsbox 组件的解决方案

import Coursebox from './Coursebox';
import Newsbox from './Newsbox'
class ContainerRow extends React.Component {
render(){
return (
<div className='rowC'>
<Coursebox />
<Newsbox />
</div>
);
}
}

CSS

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

关于css - 使用 CSS 和 React 并排排列两个 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39702130/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com