Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

72
Views
How to get the background to extend past a parent, overflow container of a certain width

Please see the below code snippet. I have a container with a set width, and in that container, a series of rows who's width is greater than the parent container. I have a background for some of those rows, however, when I scroll to the right to the remaining portion of the rows, the background stops (the background only fills the width of the container). How can I get the background for these rows to persist to the overflow? Thanks.

const Example = () => {
  const row = ['John Smith', '2020-10-01', 'jsmith@gmail.com', 'Phoenix', 'Arizona'];

  const rows = [row, row, row, row, row];

  return (
    <div
        style={{
          background: 'white',
          border: '1px solid black',
          height: '100%',
          margin: '1rem',
          overflow: 'auto',
          width: '40rem',
        }}
      >
        {rows.map((row: any, index) => (
          <div style={{ background: index % 2 === 0 ? 'orange' : 'white', display: 'flex' }}>
            {row.map((label: string) => (
              <div style={{ margin: '0 5rem', width: '15rem' }}>{label}</div>
            ))}
          </div>
        ))}
      </div>
  );
};

ReactDOM.render(<Example />, document.getElementById("react"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.1/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.1/umd/react-dom.production.min.js"></script>
<div id="react"></div>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have to use two containers if you only want horizontal scroll in table only and apply fit-content to inner container and width(here 40rem) according to wish on outer container

const Example = () => {
  const row = ['John Smith', '2020-10-01', 'jsmith@gmail.com', 'Phoenix', 'Arizona'];

  const rows = [row, row, row, row, row];

  return (
    <div
        style={{
          background: 'white',
          border: '1px solid black',
          height: '100%',
          margin: '1rem',
          overflow: 'auto',
          width: '40rem',
        }}
      >
        {rows.map((row: any, index) => (
          <div style={{ background: index % 2 === 0 ? 'orange' : 'white', display: 'flex',width:'fit-content' }}>
            {row.map((label: string) => (
              <div style={{ margin: '0 5rem', width: '15rem' }}>{label}</div>
            ))}
          </div>
        ))}
      </div>
  );
};

ReactDOM.render(<Example />, document.getElementById("react"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.1/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.1/umd/react-dom.production.min.js"></script>
<div id="react"></div>

If you say table cells are wider than before than you can solve that out by reducing innermost width(15rem) or some margins (0 5rem)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!