css - Trouble Vertically Aligning Text to Middle of Window/Viewport -
i'm trying align text bottom of loading sequence & think best way part way there use vertical-align. trouble is not working. have replica of code here. html:
<div id="bg_loader" style="background-image:url(http://www.myhhf.com/images/loading/myhhub_loading_4.gif);"></div>
css:
#bg_loader { width: 100%; height: 100%; z-index: 100000000; background-image: url(../images/loading/myhhub_loading.gif); background-repeat: no-repeat; background-position: center; } #bg_loader:before { content: "thank waiting"; display: inline-block; width: 100%; height: 100%; vertical-align: middle; text-align: center; font-size: 140%; font-weight: bold; color: #080; }
i have done extensive research on matter. can tell should working. however, using pseudo element insert text & haven't been able find documentation on vertical-align & pseudo in these particular types of cases.
i found article useful: vertical-align: need know
i know why vertical-align not working. open better methods of how place text below loading sequence responsively. aware of calc(), using.
css:
#bg_loader:before { content: "thank waiting"; display: inline-block; position: absolute; bottom: calc(60% - 14em); width: 100%; text-align: center; font-size: 140%; font-weight: bold; color: #080; }
update:
i made edits pangloss's code (marked answer below) make coded little more dynamic: jsfiddle
#bg_loader:after { content: "thank waiting"; display: inline-block; vertical-align: middle; width: 100%; height: 13.86em; line-height: calc(100% + (13.86em * 2) + 1.575em); text-align: center; font-size: 140%; font-weight: bold; color: #080; }
basically, instead of giving :after element fixed padding of icky pixels, gave same height image (in beautiful flowy em values) & line-height calculated bring text bottom bit of padding.
now, obviously, still going need work won't compatible firefox (firefox not support calc() inside line-height.... have noticed issues in ipad. working diagnose issue.
i shall try keep post updated. (my progress tracked here.)
if set vertical-align
on inline block element, valign element itself, rather content inside, , element 100% height, nothing happens, main issue there.
secondly, valign position relative sibling elements' heights (usually tallest one). , there isn't siblings in example. guide have followed good, can read again, more carefully.
updated code snippet:
#bg_loader:before { content: ""; display: inline-block; height: 100%; vertical-align: middle; } #bg_loader:after { content: "thank waiting"; display: inline-block; vertical-align: middle; width: 100%; padding-top: 270px; /*spacing*/ text-align: center; font-size: 140%; font-weight: bold; color: #080; }
full working example:
html{ height: 100%; min-height: 100%; overflow-y: scroll; } body{ width: 100%; height: 100%; min-height: 100%; overflow: hidden; background-color: #f1fafc; background-attachment: fixed; font-size: 80%; margin: 0; } #bg_loader { width: 100%; height: 100%; z-index: 100000000; background-image: url(../images/loading/myhhub_loading.gif); background-repeat: no-repeat; background-position: center; } #bg_loader:before { content: ""; display: inline-block; height: 100%; vertical-align: middle; } #bg_loader:after { content: "thank waiting"; display: inline-block; vertical-align: middle; width: 100%; padding-top: 270px; text-align: center; font-size: 140%; font-weight: bold; color: #080; }
<div id="bg_loader" style="background-image:url(http://www.myhhf.com/images/loading/myhhub_loading_4.gif);"></div>
Comments
Post a Comment