css - Inline block challenges and suggestions for the layout -
i keep reading articles floats outdated , using inline-block solves problems such having use clearfix , few more. these articles go on justify inline-block showing same example: 3 squares aligned middle. in trying use inline-block create navbar, come across many problems. navbar layout looks such:
<nav id="main-nav" class="navbar"> <div class="logo"> <!-- image --> </div><!-- --><div class="navbar-header"><!-- --><button type="button" class="navbar-toggle closed"> <span class="sr-only">toggle navigation</span> <i class="fa fa-bars"></i> </button> </div> <div class="navbar-collapse navbar-sidebar"> <ul class="navbar-nav"> <!-- list-items --> </ul> </div> </nav>
in order align logo left , navbar-toggle button right, had use text-align justify , special markup, find obtrusive clearfix (align 2 inline-blocks left , right on same line):
.header { text-align: justify; /* ie 7*/ *width: 100%; *-ms-text-justify: distribute-all-lines; *text-justify: distribute-all-lines; } .header:after{ content: ''; display: inline-block; width: 100%; height: 0; font-size:0; line-height:0; } .logo { display: inline-block; vertical-align: top; } .navbar-header { display: inline-block; vertical-align: middle; }
my navbar similar bootstrap's. @ small screen sizes, want navbar-toggle button centered in navbar area. vertical align: middle, however, align button middle logo, shorter or taller navbar, , want aligned top of navbar. inline-block doesn't allow me vertically align content parent container, seems make non-viable option in many layouts. there sort of solution can align content container, rather sibling elements? i've been experimenting setting different line heights , vertical-aligns.
if have followed comments above, there many question being asked. i'll try summaries of it.
for display:inline-block
, vertical-algin
property affects position of element itself, , relative position of siblings (the tallest sibling especially).
percentage height height:100%
, works fixed height of parent container, or percentage height set way <html>
tag. excluding positioned (relative
, absolute
etc.) elements, , viewport units vh
, , maybe other cases.
for display:table-cell
, vertical-algin
property affects child elements, again excluding positioned ones.
i think css table easiest way desired layout done in case. since can have both vertical , horizontal alignments set on it. here simplified workaround.
.nav { border: 1px solid red; display: table; width: 100%; } .nav > div { display: table-cell; vertical-align: middle; } .logo img { display: block; } .menu { text-align: right; } .menu span { border: 1px solid blue; }
<div class="nav"> <div class="logo"> <img src="//dummyimage.com/50"/> </div> <div class="menu"> <span>menu</span> </div> </div>
Comments
Post a Comment