Skip to content

Instantly share code, notes, and snippets.

@madr
Created February 12, 2012 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madr/1808914 to your computer and use it in GitHub Desktop.
Save madr/1808914 to your computer and use it in GitHub Desktop.
Valign=middle without tables, IE6+ compatible
/* @group valignfix */
/* ***************************************
valignfix, by Anders Ytterström @ madr.se
**************************************** */
/*
HTML fixture:
.valign
%div
%div
%h1
%h2
%img
*/
/* @group ie8, ff, opera, safari
===================================== */
body > div {
display:table;
}
*.valign {
display:table-row;
}
*.valign > * {
width:50%;
display:table-cell;
vertical-align:middle;
}
/* @end ie8, ff, opera, safari
===================================== */
/* @group ie6,ie7
===================================== */
/*
use this in CC file.
Works only in standards mode.
*/
* html *.valign,
*+html *.valign {
position:relative;
overflow:auto;
}
* html *.valign div,
*+html *.valign div {
position:absolute;
top:50%;
}
* html *.valign div div,
*+html *.valign div div {
position:relative;
top:-50%;
}
* html *.valign div div *,
*+html *.valign div div * {
position:static;
top:0;
}
* html *.valign img,
*+html *.valign img {
float:right;
}
/* @end ie6, ie7
===================================== */
/* ****************************************
/valignfix, by Anders Ytterström @ madr.se
**************************************** */
/* @end valignfix */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment