Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

407
Visualizações
In reactjs, how do I distribute components horizontally across an encompassing div?

So I'm new to react and for the life of me I can't figure out how to make something like this: tic-tac-toe grid

I'm having trouble making a row component that renders a div with three different square components, distributed horizontally across the div. When I compile my code all the squares in a row are fixed to the same spot. How do I fix this, please?

my current code:

App.css


.Row {
  text-align: center;
  position: absolute;
  left: 35%;
  right: 50%;
  top: 25%;
  
  width: 25%;
  height: 25%;

  display: flex;

  
}
.Square {
  position: absolute;
  
  width: 70px;
  height: 70px;
  border-color: #99ccff;
  text-align: center;
  font-size: xx-large;
  font-family: 'Courier New', Courier, monospace;
}
/* .Row {

} */

Square.js

import React from 'react';
import ReactDOM from 'react-dom';

export function Square(props){
    // Square is rendered by App

    return(
        <div >
            <button className='Square'> X </button>
        
        </div>
               
    );
}

App.js

import logo from './logo.svg';
import './App.css';
import { Row } from './components/Row';

function App() {
  // App renders Row
  return (
    <Row />
  );
}

export default App;

Row.js

import React from 'react';
import ReactDOM from 'react-dom';
import { Square } from './Square';

export function Row() {

    return(
        <div className='Row'>
            <Square />
            <Square />
            <Square />
        </div>
    )
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

import "./styles.css";

export default function App() {
  return (
    <div className={"row"}>
      <Square />
      <Square />
      <Square />
    </div>
  );
}

export function Square(props) {
  // Square is rendered by App

  return (
    <div className={"column"}>
      <button className="Square"> X </button>
      <button className="Square"> X </button>
      <button className="Square"> X </button>
    </div>
  );
}

Styles.css file

.App {
  font-family: sans-serif;
  text-align: center;
}

.row {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}

.column {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

Read this article to get more understanding about flex: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

about 4 years ago · Juan Pablo Isaza Relatório

0

You can try to remove position: absolute in Square class:

.Square {
  width: 70px;
  height: 70px;
  border-color: #99ccff;
  text-align: center;
  font-size: xx-large;
  font-family: 'Courier New', Courier, monospace;
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda