Skip to content Skip to sidebar Skip to footer

Centering Content In Css Both Supporting Ie And Chrome

I have this Css grid, with grid items, which with chrome can i easilty be centered by applying justify-items:center or that kind of magic. But this solution does not seem to work

Solution 1:

You can use flexbox instead of grid that has good support on the browsers.

.grid-container {
    display: flex;
    justify-items: center;
    align-items: center;
    flex-wrap: wrap;
}

.item-1 {
    flex: 1133.33%;
    background-color: rgba(200,520,266,.75);
    border-color: #b4b4b4;
}

.item-2 {
    flex: 1133.33%;
    background-color: rgba(145,520,0,.75);
}

.item-3 {
    flex: 1133.33%;
    background-color: rgba(145,520,0,.75);
}

.item-4 {
   flex-basis: 33.33%;
   /* important */margin: auto;
   background-color: rgba(0,0,0,.25);
   border-color: transparent;
}

Solution 2:

justify-items isn't supported in IE for display: grid. https://developer.mozilla.org/en-US/docs/Web/CSS/justify-items#Support_in_Grid_layout

A tag soup workaround is to have the sub containers with display:flex, as justify-items is supported for that: or just use flexbox exclusively.

Post a Comment for "Centering Content In Css Both Supporting Ie And Chrome"