Is there a more flexbox-ish way to right-align "Contact" than to use position: absolute?

.main {
  display: flex;
}

.a,
.b,
.c {
  background: #efefef;
  border: 1px solid #999;
}

.b {
  flex: 1;
  text-align: center;
}

.c {
  position: absolute;
  right: 0;
}
<h2>With title</h2>
<div class="main">
  <div class="a"><a href="#">Home</a></div>
  <div class="b"><a href="#">Some title centered</a></div>
  <div class="c"><a href="#">Contact</a></div>
</div>

<h2>Without title</h2>
<div class="main">
  <div class="a"><a href="#">Home</a></div>
  <!--<div class="b"><a href="#">Some title centered</a></div>-->
  <div class="c"><a href="#">Contact</a></div>
</div>

http://jsfiddle.net/vqDK9/

推荐答案

A more flex approach would be to use an auto left margin (flex items treat auto margins a bit differently than when used in a block formatting context).

.c {
    margin-left: auto;
}

Updated fiddle:

.main { display: flex; }
.a, .b, .c { background: #efefef; border: 1px solid #999; }
.b { flex: 1; text-align: center; }
.c {margin-left: auto;}
<h2>With title</h2>
<div class="main">
    <div class="a"><a href="#">Home</a></div>
    <div class="b"><a href="#">Some title centered</a></div>
    <div class="c"><a href="#">Contact</a></div>
</div>
<h2>Without title</h2>
<div class="main">
    <div class="a"><a href="#">Home</a></div>
    <!--<div class="b"><a href="#">Some title centered</a></div>-->
    <div class="c"><a href="#">Contact</a></div>
</div>
<h1>Problem</h1>
<p>Is there a more flexbox-ish way to right align "Contact" than to use position absolute?</p>

Html相关问答推荐

如何删除html原生对话框的宽度

通过POST方法提交html表单时CSV文件无法通过(在使用Django的上下文中)

如何在将文本垂直居中的同时将文本右对齐?

未知高度正在应用于前标记

如何将内容元素放在侧边栏旁边?

SCSS动画错误:心脏在页面刷新时启动动画,原因是:Checked和:Not(:Checked) Select 器

CSS:双面元素未正确显示边框

静态DIV的标签,显示从窗体输入的值

30000ms后超时重试:期望找到元素:someElement,但从未找到它

网格项未在同一行上对齐

在Angular中,类型"HTMLDivElement"不能分配给类型"Node"

模拟另一个输入值设置表单输入的数值

在锥形渐变进度条内创建空白的问题

CSS:第一个类型的伪类没有按预期工作

如何从另一个 ng-template 获取输入值

有没有办法让 textarea 在调整大小时不显示 CSS 转换?

CSS 网格自动高度不适用于特定网格区域

如何使用 :hover zoom 重叠图像?

是否有一种静态方式可以根据暗模式 Select 一张或另一张图像?

无法在 css 的 body 标签中正确呈现(内联显示)