html - 在一行中向左浮动两个 flex 元素,向右浮动一个元素

标签 html css flexbox

我正在尝试使用 flexbox 来设计我的布局。基本上我的目标是:将按钮“我是一个按钮”一直移动到 flex 容器的右端,并将其他两个社交按钮保留在容器的左侧。

<div class="quote-box quote">

  <h2>This is where the quote text is going to beThis is where the quote text is going to beThis is where the quote text is going to be</h2>
  <p class="quote-writter">Quote writer</p>

  <div class="buttons">
  <span class="my-button"><a href="#" class="get-quote-butt">I am a button</a></span>
  <a href="#" class="tweet-quote-butt"><i class="fa fa-2x fa-twitter"></i>
  <a href="#" class="tumblr-quote-butt"><i class="fa fa-2x fa-tumblr"></i>
  </a>
  </div>
</div>


</div>

这是CSS

.wrapper {
 max-width:750px;
 margin: 0 auto;
 display:flex; 
 align-items:center;
 order:1;
 }

 .quote-box {
  background:rgba(255,255,255,0.2);
  margin:20px;
  padding:20px;
  border-radius: 4px;
  text-align: center;
  flex:1;
  display:flex;
  flex-wrap:wrap;

  }
  .quote-box .quote-writter{
   display: flex;
  justify-content: flex-end;
 }
 .quote-box .buttons{
  display: flex;
  justify-content: flex-start;
 }
.quote-box > * {
 flex:1 1 100%;
}
.quote-box .my-button{
 display: flex;
 justify-content: flex-end;
 width: 100vh;
 order:3;
}
.quote-box .my-button .get-quote-butt{
 display: flex;
 flex-basis: 300px;
 align-items: center;

}

PLEASE LOOK AT THIS IMAGE

最佳答案

您可以使用margin-left:auto,然后调整您的按钮。

.wrapper {
  max-width: 750px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  order: 1;
}

.quote-box {
  background: rgba(255, 255, 255, 0.2);
  margin: 20px;
  padding: 20px;
  border-radius: 4px;
  text-align: center;
  flex: 1;
  display: flex;
  flex-wrap: wrap;
}

.quote-box .quote-writter {
  display: flex;
  justify-content: flex-end;
}

.quote-box .buttons {
  display: flex;
  justify-content: flex-start;
}

.quote-box>* {
  flex: 1 1 100%;
}

.quote-box .my-button {
  display: flex;
  justify-content: flex-end;
  width: 100vh;
  order: 3;
  margin-left: auto;
}

.quote-box .my-button .get-quote-butt {
  display: flex;
  flex-basis: 300px;
  align-items: center;
  background: #f1f1f1;
  justify-content: center;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet" />
<div class="quote-box quote">

  <h2>This is where the quote text is going to beThis is where the quote text is going to beThis is where the quote text is going to be</h2>
  <p class="quote-writter">Quote writer</p>

  <div class="buttons">
    <span class="my-button"><a href="#" class="get-quote-butt">I am a button</a></span>
    <a href="#" class="tweet-quote-butt"><i class="fa fa-2x fa-twitter"></i></a>
    <a href="#" class="tumblr-quote-butt"><i class="fa fa-2x fa-tumblr"></i>
  </a>
  </div>

</div>

DEMO HERE

关于html - 在一行中向左浮动两个 flex 元素,向右浮动一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37140751/

相关文章:

javascript - 响应表不显示列值

html - 在悬停时缩放图像并且不超过父 div 边界

html - CSS垂直对齐-我不明白什么?

javascript - 插入新元素时如何平滑移动?

html - A4 论文样 CSS : taking citations from the main column and placing them into the other

css - 如何在显示 :flex element 内设置 div 溢出属性

javascript - 同位素不居中

css - 如何调整 div 容器的大小以适应子 div 的溢出

css - glyphicon- 图标不起作用

html - 为什么我不能将 div 直接放在正文中?