Box-shadow trimmed in CSS columns in Chrome

后端 未结 9 2256
难免孤独
难免孤独 2020-12-15 17:38

I want the block elements inside CSS columns to have box shadow. The following, simplified code renders as expected in IE10 and Firefox 21, but in current C

9条回答
  •  执笔经年
    2020-12-15 18:04

    You could use flexbox for this instead of css columns.

    FIDDLE

    NB: This currently doesn't work in Firefox because it still doesn't support the flex-wrap property, however according to caniuse - this will be supported in version 28

    CSS

    div#column-container {   
        height: 270px; /* NB: IE requires the height property. max-height won't work on IE)*/
        display: flex;
        flex-direction: column;
        flex-wrap: wrap;
        align-content: flex-start;
    }
    

    EDIT: (Updated FIDDLE which includes support for Firefox)

    As per @buli's suggestion to temporarily use the -moz-colums-count for Firefox as long as flex-wrap is not supported:

    Well, you could do this with the @supports which allows us to perform feature queries - sort of like Modernizr, but with CSS.

    The good thing here, is that Firefox supports them.

    So if I add the following code: (updated as per Pavlo's suggestion)

    @supports (not (flex-wrap: wrap)) and (-moz-columns: 2) {
        div#column-container { 
            -moz-column-count: 2;
            column-count: 2;
            display: block;
            width: 50%;
        }
    }
    

    Now, Firefox will use CSS columns, whereas other browsers will use flexbox.

提交回复
热议问题