Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aligning few components horizontally in React

Tags:

css

reactjs

I have three big component. Two of thes takes something like 1/3 of the screen and my goal is to present them at the horizontally from left to right.

When just putting them like in the code I added, they presented one after another Vertically which causing the uder to scroll down to find them. How can I present them in horizontally on the screen ? (I tried a couple of things with css with no success).

This is the return method, the Tables component contains two different tables inside of it:

 return (
      <div>
        {title} <Chat />
        <Tables/>}

      </div>
    );
like image 569
Ben Zoker Avatar asked Apr 02 '19 14:04

Ben Zoker


People also ask

How do you horizontally align divisions?

To align div horizontally, one solution is to use css float property. But a better solution is to to use CSS display:inline-block on all divs which needs to be aligned horizontally and place them in some container div.

How do you align two components in the same line in React?

Just use flexbox, set the container CSS to have display: flex this will put everything on the same line.

How do you arrange components in React?

Open the component's file and start editing away. Then you need to edit your styles, so you also navigate to your styles folder, find the button and open that. Now the component is updated, the tests are broken and some stories need to be updated. You navigate to those respective folders and open tests/button.


1 Answers

You should take a look at flexboxes !

As you probably know, React lets you create component, so you can style them just like html elements with flexboxes.

Definitely give this article a read!

Edit: EXAMPLE

HTML:

<div class="flexbox-container">
    <div>Element1</div>
    <div>Element2</div>
    <div>Element3</div>
</div>

CSS:

.flexbox-container {
    display: flex;
    flex-direction: row;
}

This will align your elements horizontally with even spacing! Try playing with the container's margins and justify-elements to align elements.

like image 92
Nasta Avatar answered Sep 23 '22 07:09

Nasta