r/csshelp • • Oct 27 '21

Flex question

Trying to divide up a div horizontally that creates equal divs using flex.

Stack has only floats. I tried flex but it doesn't work.

9 Upvotes

8 comments sorted by

1

u/Helpful-Sea-9815 Oct 27 '21

Is this what you are trying to achieve?

1

u/OneBeautifulDog Oct 27 '21

No, side by side horizontally. I am using flex. The problem seems to be the content or the measurements I am using? & versus em versus whatever. I can't make them a fixed percent that adds to 100% which you are not supposed to add to 100% and still have it responsive without content inside the div. It either expands or contracts too much or too little.

Edit:

can't use px. Can't use a total of 100%. vW has issues with it. What the hell do you use?

2

u/Helpful-Sea-9815 Oct 27 '21

Try adding flex-basis to the children of the div that has a flex display. You can read more about flex basis on mdn. Also you might achieve what you want with display grid. I hope this helps

1

u/mhennessie Nov 06 '21

Try adding flex:1 to the children of the flex container

1

u/OneBeautifulDog Nov 06 '21

That's what I have. Since flex is collapsible, if you don't have anything in the box, then it collapses all the way and you have nothing. I wanted blank boxes, responsive, but with some width. I can't use px.

1

u/mhennessie Nov 06 '21

Is there a fixed number of boxes? If so width: calc(100% / # ) where # is the number of boxes.

1

u/OneBeautifulDog Nov 06 '21

I will try that.

1

u/OneBeautifulDog Nov 06 '21

I tried it and I see how it worked.

How would you do it if you didn't want even spacing between columns but you still wanted it responsive fr?