Is there a way to use both or either display: grid/-ms-grid
into one style sheet or do I have to use an HTML hack or JavaScript to query what type of browser a
This is what I used for IE:
I added an @supports() for all current browser support. If you use @supports() pass in a new grid property such as @supports(grid-area: auto) to be sure a modern browser will pick it up. Do not use @suppports(display: grid) because IE will recognize display:grid and will then use the modern grid properties that it does not have. I had to use a 1px margin to mimic the grid-gap in IE though
* {
box-sizing: border-box;
}
.item-bg {
background-color: rgb(92, 182, 205);
border-radius: 6px;
margin: 1px;
}
.container {
display: -ms-grid;
width: 800px;
height: 600px;
-ms-grid-columns: 200px 1fr 1fr;
-ms-grid-rows: 80px 1fr 1fr 100px;
}
.header {
-ms-grid-row: 1;
-ms-grid-row-span: 1;
grid-row: 1/2;
-ms-grid-column: 1;
-ms-grid-column-span: 3;
grid-column: 1/4;
}
.sidebar {
-ms-grid-row: 2;
-ms-grid-row-span: 2;
grid-row: 2/4;
-ms-grid-column: 1;
-ms-grid-column-span: 1;
grid-column: 1/2;
}
.content-1 {
-ms-grid-row: 2;
-ms-grid-row-span: 1;
grid-row: 2/3;
-ms-grid-column: 2;
-ms-grid-column-span: 2;
grid-column: 2/4;
}
.content-2 {
-ms-grid-row: 3;
-ms-grid-row-span: 1;
grid-row: 3/4;
-ms-grid-column: 2;
-ms-grid-column-span: 1;
grid-column: 2/3;
}
.content-3 {
-ms-grid-row: 3;
-ms-grid-row-span: 1;
grid-row: 3/4;
-ms-grid-column: 3;
-ms-grid-column-span: 1;
grid-column: 3/4;
}
.footer {
-ms-grid-row: 4;
-ms-grid-row-span: 1;
grid-row: 4/5;
-ms-grid-column: 1;
-ms-grid-column-span: 3;
grid-column: 1/4;
}
@supports(grid-area: auto){
.item-bg {
background-color: indianred;
border-radius: 6px;
margin: 0;
}
.container {
display: grid;
width: 750px;
height: 600px;
grid-template-columns: 200px 1fr 1fr;
grid-template-rows: 80px 1fr 1fr 100px;
grid-gap: 2px;
}
.header {
grid-row: 1/2;
grid-column: 1/4;
}
.sidebar {
grid-row: 2/4;
grid-column: 1/2;
}
.content-1 {
grid-row: 2/3;
grid-column: 2/4;
}
.content-2 {
grid-row: 3/4;
grid-column: 2/3;
}
.content-3 {
grid-row: 3/4;
grid-column: 3/4;
}
.footer {
grid-row: 4/5;
grid-column: 1/4;
}
}
The html is
Basic Layout
header
Content-1
Content-2
Content-3