2

I want to create news horizontal scrolling tiles slider with pure css without JS
Horizontal scrolling tiles slider

I tried using FlexBox,

.spotlight-wrapper {
  width: 100%;
  overflow-x: auto;
}
.spotlight-wrapper .spotlight {
  list-style: none;
  height: 230px;
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  justify-content: bottom;
  padding: 0;
}
.spotlight-wrapper .spotlight li {
  width: 220px;
  height: 220px;
  background: #ccc;
  margin: 5px;
}
.spotlight-wrapper .spotlight li.small {
  width: 105px;
  height: 105px;
}
.spotlight-wrapper .spotlight li.medium {
  width: 220px;
  height: 105px;
  /*
     * Idea to fix it, but will cause
     * issue if the medium tile in the
     * bottom level, and there are 2 small
     * tiles next to it in the top level
    */
  /* & + .small + .small{
     display: block;
     clear: both;
     justify-content: bottom;
     margin-top: 120px;
     margin-left: -110px;
    } */
}
.spotlight-wrapper .spotlight li.red {
  background: red;
}
<div class="spotlight-wrapper">
 <ul class="spotlight">
  <li>Tile #1</li>
  <li class="small">Tile #2</li>
  <li class="small">Tile #3</li>
  <li class="medium">Tile #9</li>
  <li class="medium">Tile #10</li>
  <li>Tile #2</li>
  <li class="medium red">Tile #1</li>
  <li class="small red">Tile #2</li>
  <li class="small red">Tile #3</li>
  <li>Tile #5</li>
  <li>Tile #7</li>
  <li>Tile #8</li>
  <li class="medium">Tile #9</li>
  <li class="medium">Tile #10</li>
  <li>Tile #11</li>
  <li>Tile #12</li>
  <li class="small">Tile #13</li>
  <li>Tile #14</li>
  <li>Tile #15</li>
  <li>Tile #16</li>
  <li>Tile #17</li>
  <li>Tile #18</li>
  <li>Tile #19</li>
  <li>Tile #20</li>
 </ul>

But if you check the red tiles, its not aligned the correct way, i can fix it using margins (check the commented block) but will cause other issue if the wide tile is in the bottom row, and there are 2 small tiles in the next block,

Also if there are only one small tile, empty space will be created.

Anas Tawfeek
  • 109
  • 8
  • You may want to start your troubleshooting here: **`justify-content: bottom`** (there is no such value). For valid values and other alignment options that may help you see here: [Methods for Aligning Flex Items](http://stackoverflow.com/a/33856609/3597276) – Michael Benjamin Dec 27 '15 at 14:41
  • Very nice one, thanks for sharing, hope the answer light up there – Anas Tawfeek Dec 27 '15 at 15:12
  • maybe column CSS is more accurate ? http://codepen.io/anon/pen/pgEGvG – G-Cyrillus Dec 27 '15 at 15:35

1 Answers1

1

For starters, I work a lot with flexbox and I very much like what you are trying to achieve and will modify a few things of my own to work like that.

Secondly, you have failed to tell flexbox how to flex the li elements. Defining only width and height on flexed elements forces flexbox to use only those values and is not flexible at all.

UPDATE

A flexbox row cannot put different sized boxes on top of each other on the same row (the same is true for flexbox columns with rows). This actually means that if you want your solution you will need a main column with 2 rows (ul) each height: 105px and put li in either row where appropriate.

Another option would be a single flexbox row (ul) with child li's that are wrapping flexbox rows, actually nesting small and medium classes.

I think I would opt for the second solution.

As you can see from the code, your main 'lightstrip' has become a row of boxes with each box containing 3 elements: 2 spot's and a 'strip'.

I removed the reference to ul and li elements, making it more flexible. This way you can use any kind of container as a lightbox.

ul,ol,li { list-style: none; padding: 0; margin: 0 }

.armature {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}
.lightstrip {
  height: 210px;
  display: flex;
  flex-flow: column wrap;
  padding: 0;
}

.lightbox {
  width:  210px;
  height: 210px;
  
  display: flex;
  flex-flow: row wrap;
}

.spot {
    flex: 1 1 100px;
    height: 100px;
    margin: 2px;
    background-color: rgba(0,255,0,.3);
}
.strip {
    flex: 1 1 200px;
    height: 100px;
    margin: 2px;
    background-color: rgba(255,0,0,.3);
}
<div class="armature">
    <div class="lightstrip">
        <div class="lightbox"><div class="spot" ></div><div class="spot"></div><div class="strip"></div></div>
        <div class="lightbox"><div class="spot" ></div><div class="spot"></div><div class="strip"></div></div>
        <div class="lightbox"><div class="strip"></div><div class="spot"></div><div class="spot" ></div></div>

        <ul class="lightbox"><li class="spot" ></li><li class="spot"></li><li class="strip"></li></ul>
        <ul class="lightbox"><li class="strip"></li><li class="spot"></li><li class="spot" ></li></ul>
        <ul class="lightbox"><li class="spot" ></li><li class="spot"></li><li class="strip"></li></ul>

        <div class="lightbox"><div class="spot" ></div><div class="spot"></div><div class="strip"></div></div>
        <div class="lightbox"><div class="spot" ></div><div class="spot"></div><div class="strip"></div></div>
        <div class="lightbox"><div class="strip"></div><div class="spot"></div><div class="spot" ></div></div>

        <ul class="lightbox"><li class="spot" ></li><li class="spot"></li><li class="strip"></li></ul>
        <ul class="lightbox"><li class="strip"></li><li class="spot"></li><li class="spot" ></li></ul>
        <ul class="lightbox"><li class="spot" ></li><li class="spot"></li><li class="strip"></li></ul>
    </div>
</div>
Rene van der Lende
  • 4,992
  • 2
  • 14
  • 25
  • Thanks a lot, still gonna need to update it a little so it's working with loop rendering (i'm going to use with O365's SharePoint display template) – Anas Tawfeek Dec 28 '15 at 08:14
  • No mention! Obviously, this approach can be implemented in various ways. But, while you're at it, make **lightbox, spot** and **strip** `position: relative` and their **:before** and **:after** `position: absolute` and you can easily overlay text or badges (needs a bit of `z-index: ...` tinkering). – Rene van der Lende Dec 28 '15 at 15:29
  • Here's a pen of mine on Codepen [Responsive filmstrip and thumblist](http://codepen.io/renevanderlende/pen/ZbrpQO) which might give you further ideas on overlaying text and showing content in your strip. – Rene van der Lende Dec 28 '15 at 15:37