1

My goal is like this:

Goal

Rules:

  • the horizontal gap between items is fixed, called x
  • the vertical gap between items is fixed, called y
  • the gap between borders of the leftmost item and the flexbox is the same as that between the rightmost item and the flexbox, called z
  • x, y, z are set individually. They may be different.
  • List items from left to right, and then top to bottom
  • keep the bottom padding >= the top padding. If exceeded, hide the overflow part and make it scrollable (not system scrollbar).

I tried some ways, and this is my current code

content #ItemPane {
    height:100%;
    background:#a0d4e5;
    padding:1vh;
    border:1px solid blue;
}

    content #ItemPane .PanelContentWrapper {
        width:100%;
        display:flex;
        flex-direction:row;
        flex-wrap:wrap;
    }

        content #ItemPane .Slot {
            width:6vh;
            height:6vh;
            margin:1vh;
            background:black;
        }

and as a result:

https://jsfiddle.net/h4ww9erj/

The biggest problem is that I can't make the left and right padding the same while the items are listed left-aligned.

My solutions/workarounds:

  • Dynamically set the gap between items in js
  • Table for this layout

Any better ideas?

As for scroll and bottom padding issue, the only way I think of is that I must have a middle wrapper as I already I wrote, and customize my own scroll system (e.g. capture the mouse/touch offset and convert it to scroll offset and move the wrapper to the corresponding position).

Any other advises?

Paulie_D
  • 107,962
  • 13
  • 142
  • 161
Eric
  • 534
  • 5
  • 13
  • like this? https://jsfiddle.net/h4ww9erj/8/ – Pete Mar 23 '18 at 10:28
  • `The biggest problem is that I can't make the left and right padding the same while the items are listed left-aligned.` --> this is the only problem and it's not possible with CSS ... i will share few links so you get some workaround – Temani Afif Mar 23 '18 at 10:37
  • https://stackoverflow.com/questions/32802202/how-to-center-a-flex-container-but-left-align-flex-items – Temani Afif Mar 23 '18 at 10:40
  • @TemaniAfif Thanks, after reading the link and the links in the link and googled some more, I guess display:grid is right for this purpose, not flex, not table. https://developer.mozilla.org/en-US/docs/Web/CSS/grid & https://stackoverflow.com/a/46099319/1992731 – Eric Mar 26 '18 at 09:55

0 Answers0