I know this question: Height equal to dynamic width (CSS fluid layout)
But I want more !! I want a flexible container that always has an aspect ratio of the square, but with a maximum height and a maximum width of 100% of the page (window element), and on top it is always vertically and horizontally centered.
Like this:
// Container matches height of the window
// container-height = 100%; container-width = absolute-container-height
-page/browser-window-
-
-
-
-
---------------------
// container matches width of the window
// container-width = 100%; container-height = absolute-container-width
--page---
- -
- -
-
-
-
-
- -
- -
---------
Is it possible to achieve this with pure css (and even a better cross browser)?
Edit:
I know there is calc () for css3, but due to poor support for mobile browsers , I do not want to use it.
Edit2:
, . , , . / .
jQuery:
// container/
$(window).resize(function () {
var $ww = $(window).width();
var $wh = $(window).height();
if ($ww > $wh) {
$('#main-wrapper').css({
height: $wh,
width: $wh,
marginTop : ($wh / 2) * -1,
marginLeft : ($wh / 2) * -1
});
} else {
$('#main-wrapper').css({
height: $ww,
width: $ww,
marginTop : ($ww / 2) * -1,
marginLeft : ($ww / 2) * -1
});
}
});