How can I align two inline-blocks so that one is left and the other is right on the same line? Why is this so hard? Is there something like LaTeX\'s \\hfill that can consume
If you don't want to use floats, you're going to have to wrap your nav:
<header>
<h1>Title</h1>
<div id="navWrap">
<nav>
<a>A Link</a>
<a>Another Link</a>
<a>A Third Link</a>
</nav>
</div>
</header>
...and add some more specific css:
header {
//text-align: center; // will set in js when the nav overflows (i think)
width:960px;/*Change as needed*/
height:75px;/*Change as needed*/
}
h1 {
display: inline-block;
margin-top: 0.321em;
}
#navWrap{
position:absolute;
top:50px; /*Change as needed*/
right:0;
}
nav {
display: inline-block;
vertical-align: baseline;
}
You may need to do a little more, but that's a start.
I think one possible solution to this is to use display: table
:
.header {
display: table;
width: 100%;
box-sizing: border-box;
}
.header > * {
display: table-cell;
}
.header > *:last-child {
text-align: right;
}
h1 {
font-size: 32px;
}
nav {
vertical-align: baseline;
}
JSFiddle: http://jsfiddle.net/yxxrnn7j/1/
give it float: right and the h1 float:left and put an element with clear:both after them.
For both elements use
display: inline-block;
the for the 'nav' element use
float: right;
Taking advantage of @skip405's answer, I've made a Sass mixin for it:
@mixin inline-block-lr($container,$left,$right){
#{$container}{
text-align: justify;
&:after{
content: '';
display: inline-block;
width: 100%;
height: 0;
font-size:0;
line-height:0;
}
}
#{$left} {
display: inline-block;
vertical-align: middle;
}
#{$right} {
display: inline-block;
vertical-align: middle;
}
}
It accepts 3 parameters. The container, the left and the right element. For example, to fit the question, you could use it like this:
@include inline-block-lr('header', 'h1', 'nav');
New ways to align items right:
Grid:
.header {
display:grid;
grid-template-columns: 1fr auto;
}
Demo
Bootstrap 4. Align right:
<div class="row">
<div class="col">left</div>
<div class="col">
<div class="float-right">element needs to be right aligned</div>
</div>
</div>
Demo