简体   繁体   English

React:以不同的方式渲染组件

[英]React: Rendering the component in different way

I have two components which should appear in the following way:- 我有两个组件应以以下方式显示: 在此处输入图片说明

Now the problem statement is, i have to render component B first & then component A. But component A should be displayed on left while B on right. 现在问题陈述是,我必须先渲染组件B,然后渲染组件A。但是组件A应该显示在左侧,而组件B应该显示在右侧。 One can use any CSS or bootstrap to display/arrange the component. 可以使用任何CSS或引导程序来显示/排列组件。

Note: component A returns rectangle and component B returns circle / ellipse. 注意:组件A返回矩形,而组件B返回圆形/椭圆。

A pure css solution: you can use display: grid; 一个纯CSS解决方案:您可以使用display: grid; and order: 1; order: 1; and order: 2; order: 2; to rearrange order. 重新排列顺序。
I made a quick codepen to demonstrate. 我做了一个快速的Codepen演示。

Or if you are not allowed to use container - something as simple as this might work: just give component B negative margin-left and component A positive margin-left. 或者,如果您不被允许使用容器-可能会如此简单:只需将B组件的负边距设为左边,将A组件的正边距设为左边即可。 https://codepen.io/anon/pen/LddwYa https://codepen.io/anon/pen/LddwYa

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

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