css - absolute vertical centering elements -



css - absolute vertical centering elements -

i've tried lot of methods center children elements absolute vertical center couldn't success techniques.

here's 1 illustration i've tried:

html (cannot change) :

<div class="foo"> <h1>blah blah</h1> <p>foo</p> <p>bar</p> </div>

css:

.foo{ position: absolute; top: 0; bottom: 0; background: yellow; } .foo:before{ content: ""; display: inline-block; vertical-align: middle; height: 100%; }

please note: cannot alter markup i.e cannot wrap .foo parent div , cannot wrap childrens within .foo div.

so, how can vertically center them on total window ?

you accomplish using css flexbox layout this:

jsfiddle - demo

class="snippet-code-css lang-css prettyprint-override">.foo { position: absolute; top: 0; bottom: 0; background: yellow; height: 100%; display: flex; flex-direction: column; justify-content: center; flex-wrap: wrap; /* align-items: center; */ } h1, p { margin:0; } class="snippet-code-html lang-html prettyprint-override"><div class="foo"> <h1>blah blah</h1> <p>foo</p> <p>bar</p> </div>

css vertical-alignment

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -