html - Height calculation ambiguity of fixed-positioned table container -
let's assume have following document structure:
<div class='container-table'> <div class='container-cell'> <div class='content'> <!-- lot of text, images, ... --> </div> </div> </div> here css:
.container-table { position:fixed; height:100%; width:100%; top:0; left:0; display:table; } .container-cell { display:table-cell; vertical-align: middle; } .content { position: relative; height:90%; width:90%; left:50%; margin-left:-45%; overflow:scroll; } the idea have vertically- , horizontally-centered box takes 90% of viewport's height , width. if content div overflows, should scroll.
this solution works fine in chrome , safari not in firefox. inspector shows problem: firefox ignores position:fixed when display:table present , calculates height of container-table summing height of children while safari/chrome calculate height looking @ browser's viewport (as should according position:fixed).
here's complete demo: https://jsfiddle.net/76pg43tx/
who right: firefox or safari/chrome or both? there workaround?
one solution can use using css following:
.container-table { position:fixed; height:100%; width:100%; top:0; left:0; display:table; } .container-cell { display:table-cell; vertical-align: middle; } .content { position: fixed; height:90%; width:90%; left:50%; margin-left:-45%; top: 50%; transform: translate(0, -50%); overflow:scroll; } check fiddle here.
Comments
Post a Comment