I have bumped into this, while solving another issue.
I have the following, basic, layout:
+-----+-----------------+
| | |
| c |c +------+ |
| o |o | item | |
| l |l | | |
| | +------+ |
| 1 |2 |
+-----------------------+
col 1
and col 2
are created via CSS Grid. Now, I am striving to center item
(both horizontally and vertically) inside the col 2
.
#content {
display: grid;
grid-template-columns: minmax(13rem, 15%) minmax(85%, 100%);
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
}
#circle {
background: #7FFF00;
width: 9%;
padding-top: 9%;
border-radius: 50%;
margin: auto;
}
.menu {
background: #D2691E;
grid-row-start: 1;
grid-row-end: 1;
}
.circle-area {
background: #191970;
grid-row-start: 1;
grid-row-end: 1;
grid-column-start: auto;
grid-column-end: span 2;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
}
<body>
<div id='content'>
<div class='menu'></div>
<div class='circle-area'>
<div id='circle'></div>
</div>
</div>
</body>
Code above on JSFiddle
My code is working as I expect it to (item
saves it's aspect ratio and being centered vertically and horizontally), when tested in Chrome 62.0 and Safari 11.0. Though when I've got to Firefox (56.0) - the aspect ratio is changed on window resizing. I have tried another centering technique - using grid (JSFiddle) (the result is the same Firefox won't preserve aspect ratio).
Now, commenting out (JSFiddle) the flex part from css, will make Firefox preserve aspect ratio, though item is not centered vertically anymore.
My questions are:
- Is this a known issue (bug) in Firefox, or something wrong with my code?
- What is the proper fix/workaround to center
item
vertically and horizontally, insidecol 2
, while preserving aspect ratio (preferably using flex)?