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

237
Visualizações
CSS padding is not applied to the div in react js

I have a div like this in react js which renders multiple divs and overflows :

 <div
      style={{
        display: "flex",
        padding: "1em 0.7em",
        overflowX: "auto",
        width: "100%",
        direction: "rtl",
        background: "#ef394e"
      }}
    >
      {Array.from(Array(10).keys()).map((each, index) => (
        <div
          key={index}
          className="swiper-slide"
          style={{
            background: "white",
            borderRadius: "10px",
            width: "270px",
            margin: "0 .4em"
          }}
        >
          <div style={{ padding: "2em 6em" }}>Hello</div>
        </div>
      ))}
    </div>

But for some reason the padding is applied to the containers right side but not the left side here are some pictures : image-one

image-two

How can I apply padding to the array item's container div for both the left and right sides ?

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

0

It's the padding on the div. It's to little and the margin too.

import React from "react";

const App = () => {
  return (
    <div
      style={{
        display: "flex",
        padding: "1em 0em",
        overflowX: "auto",
        width: "100%",
        direction: "rtl",
        background: "#ef394e"
      }}
    >
      {Array.from(Array(10).keys()).map((each, index) => (
        <div
          key={index}
          className="swiper-slide"
          style={{
            background: "white",
            borderRadius: "10px",
            width: "270px",
            margin: "0 .4em"
          }}
        >
          <div style={{ padding: "2em 6em" }}>Hello</div>
        </div>
      ))}
    </div>
  );
};

export default App;
about 4 years ago · Juan Pablo Isaza Relatório

0

It's because your div width bigger then the body, and as result your body also have scroll. Try add boxSizing: border-box to your parent component, and the body scroll will disappear.

const App = () => {
 return (
   <div
     style={{
       display: "flex",
       padding: "1em 0em",
       overflowX: "auto",
       width: "100%",
       direction: "rtl",
       background: "#ef394e",
       boxSizing: "border-box" // <--- this line
     }}
   >
   ...
   </div>
 );
};
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