0

I have 1 div with exact width 300px and if the window size is less than that I want to be a scrollable herizontally , I've use overflow-x-auto but It still not working and that div is getting smaller as window size here's my code

  <div>
        <div className="flex h-screen  overflow-scroll">
          <div className="bg-red-400 w-[200px] ">
            <input type="number" className="p-1 rounded m-2" />
          </div>
          <div className="bg-blue-300 w-[100px] sm:w-full sm:bg-red-500">
          <Select
              className=" m-2 "
              defaultValue={selectedOption}
              onChange={setSelectedOption}
              options={options}
            />
          </div>
          <div className="bg-gray-200 w-[300px] overflow-y-scroll ">
            {result}
          </div>
        </div>
    </div>

1 Answer 1

2

You're setting fixed widths on elements that are within a flex container. When the parent container shrinks, child elements will scale accordingly.

Set flex-none on elements that should remain at a fixed size, regardless of the space available.

<div className="bg-gray-200 flex-none overflow-y-scroll w-[300px]">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.