css - Flexbox header : Align box right with two elements in rows

标签 css flexbox

刚开始使用 Flexbox。通过尝试创建一个非常简单的简历网站来练习。

Codepen 在这里: http://codepen.io/koentj/pen/jyLxGX

我正在尝试将 social-container 放在 picture-container 的左侧。这两个都在 profile-container 中,同时给 name-container 大部分空间(又名 profile-container 将使用它需要的空间, name-container 负责剩下的部分)。

无论我做什么(我已经尝试了很多),social-container 最终都在 picture-container 之上,我觉得我错过了什么非常简陋。

最佳答案

我不完全确定您的 HTML 是否反射(reflect)了您正在尝试做的事情。目前是这样的:

- header
-- .name-container  
-- .profile-container
--- .social-container
---- .picture-container

如果 .picture-container.social-container 的兄弟元素而不是子元素会更容易。

这样你就可以为 .profile-container 使用 display:flex 并且可以并排显示这两个元素。

body {
  display: flex;
  flex-direction: column;
  font-family: "Helvetica Neue, Helvetica, Liberation Sans, Arial, sans-serif";
}

header {
  background: #42A8C0;
  width: 100%;
  color: white;
  text-align: center;
}

img {
  max-width: 100%;
}

.profile-container {
  display: flex;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />

<header>
  <div class="name-container">
    <h1>My Name</h1>
    <h4>Small summary of current position</h4>
  </div>
  
  <div class="profile-container">
    <div class="social-container">
      <a href="http://www.google.com" target="_blank"><i class="fa fa-linkedin-square" aria-hidden="true"></i></a>
      <a href="http://www.google.com" target="_blank"><i class="fa fa-github-square" aria-hidden="true"></i></a>
    </div>

    <div class="picture-container">
      <img src="https://cdn.pixabay.com/photo/2016/02/22/18/57/puppy-1216269_960_720.jpg" class="portrait-pic">
    </div>
  </div>
</header>

关于css - Flexbox header : Align box right with two elements in rows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41852489/

相关文章:

css - 如何使菜单项填充顶部栏

jquery - 全尺寸按钮改变位置

html - 如何通过 CSS FLEX for RWD 将列跨度更改为行跨度

html - 伪元素破坏 justify-content : space-between in flexbox layout

css - 即使在使用 flex-wrap 后也无法垂直堆叠 flex 元素

asp.net - 在 IE 7 中调用 Ajax 后,CSS 样式消失了

html - 悬停结束时反转 svg 动画?

html - MVC 无法更改表单元格高度

html - 仅CSS的砌体布局

html - 如何正确回退到 css 网格