css - Centering Elements Vertically with FlexBox -
attempting use flexbox (for demo purposes only). i'm having trouble vertically centering text within parent .top-nav-bar
. using justify-content: space-between
i'm able 2 elements need them horizontally, i'm having no luck centering .contact
, .help
vertically within .top-nav-bar
. attempts seem butt text against top edge of page.
html:
header.section1.box .top-nav-bar .contact p lorem ipsum dolor sit amet .help p lorem ipsum dolor sit amet
css:
.section1 background: image: url(url/of/image.jpg) size: cover position: top center repeat: no-repeat attachment: fixed .box overflow: hidden width: 100% height: 100vh background: color: #90281f .top-nav-bar max-width: 1200px width: 100% height: 40px margin: 0 auto font-size: 0.813em background: pink display: flex flex-direction: row align-items: center justify-content: space-between .contact background: red .help background: green
all attempts seem butt text against top edge of page.
but that's .top-nav-bar
- it's div height 40px
(as defined in css) , has no content before in html, on top of page.
if set .top-nav-bar { height: 100%; }
.top-nav-bar
height of it's parent (100vh
) , it's contents can vertically centered (which have correctly instructed using align-items: center
)
.section1 { background: url(url/of/image.jpg) top center no-repeat; background-size: cover; background-attachment: fixed; } .box { overflow: hidden; width: 100%; height: 100vh; background:#90281f; } .top-nav-bar { max-width: 1200px; width: 100%; height: 100%; margin: 0 auto; font-size: 0.813em; background: pink; display: flex; flex-direction: row; align-items: center; justify-content: space-between; } .contact { background: red } .help { background: green }
<header class="section1 box"> <div class="top-nav-bar"> <div class="contact"> <p> lorem ipsum dolor sit amet</p> </div> <div class="help"> <p> lorem ipsum dolor sit amet</p> </div> </div> </header>
Comments
Post a Comment