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

216
Visualizações
Text align isn't working when getting text from data attribute on object tag

So my html code is structure like this.

<div className="App">
  <header className="App-header">
    <Container fileType={this.state.currentFileType} file= this.state.currentFile} />
    <Board handleClick={() => this.handleClick()} />
  </header>
</div>

and this is my Container div which contains the text. Data just calls a basic .txt file two sentences long.

<div className="NoteContainer">
   <object data={"/Notes/" + props.file} />
</div>

My css looks like this

.App{
  text-align: center;
  background-color: #a461f2;
}

.App-header {
  height: 100vh;
  width: 100vw;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: calc(10px + 2vmin);
  color: white;
}

.NoteContainer {
  padding:40px;
  display: flex;
  text-align: center;
}

For some reason I can't get the text coming from note1.txt to center. Any help would be greatly appreciated.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

text-align is for Text. you can try:

align-items: center;
justify-content: center;
align-content: center;
about 4 years ago · Juan Pablo Isaza Relatório

0

So after a lot of digging I didn't seem to find any easy way of centering text this so What I ended up doing is this >>>

I made a script to turn the simple note.txt into a json file with one attribute. Make sure to use single qoutes around the outside and double inside the jsonString because for me it didn't allow the json headers to be wrapped by single qoutes.

jsonString = '{\n   "text" : "' + text[i] + '" \n}';
filename = "note" + (i + 1) + ".json"
await writeFile(dirToWrite + filename, jsonString);

Then I passed the filePath to the child component and used fetch to get the text

try {
  const text = await fetch(filePath)
  .then((r) => r.json())
  return text;
} catch (err) 
  console.log(err);
  return "Error";
}

This way I can pass text as the file value and regular css attributes will apply. Hope this helps anyone who ran into the same problem as me.

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