html - Flexbox 图像布局列

标签 html css flexbox

我正在使用 flex box 创建一个图像布局,并试图做到这一点,以便在调整页面大小时,掉落的图像将与列对齐,而不是在列下方居中。我虽然可能在图像上放置一个 float:left; 会起作用,但什么也没发生。我在这里做错了什么?任何帮助,谢谢!

/*Fonts*/
@import url(https://fonts.googleapis.com/css?family=Open+Sans:300,400,600);
@import url(https://use.fontawesome.com/releases/v5.0.8/css/all.css);

/*Body*/
body {
	font-family: "Open Sans", Arial, sans-serif;
	background-color: #fefefe;
	padding-bottom: 3rem;}

/*Profile Picture*/
.profile-picture {
  display: flex;
  margin-top: 55px;
  margin-bottom: 35px;
  display: inline-block;
  width: 125px;
  height: 125px;
  border-radius: 50%;
  background-repeat: no-repeat;
  background-position: center center;
  background-size: cover;
  background-color: #f1f1f1;}
.image {
  background-image: url('https://www.dropbox.com/s/8dtg60sbha99x2o/Photo%202018-02-05%2C%209%2026%2043%20AM.jpg?raw=1');}

/*Profile Name*/
.profile-name {
  text-align:center; 
  margin-top:-20px; 
  margin-bottom:35px; 
  font-weight:bold;}

/*User Name*/
.user-name {
  text-align:center; 
  margin-top:-30px; 
  margin-bottom:35px; 
  color:rgba(1,1,1,0.35);}

/*Follow Button*/
.follow-button-position {
  text-align:center;
  margin-bottom:55px;
  margin-top:-10px;}
.follow-button {
  text-align:center;
  padding-top:7.5px;
  padding-bottom:7.5px; 
  padding-left:25px; 
  padding-right:25px;
  border-radius:2px;
  background-color:rgba(1,1,1,0); 
  border-style:solid; 
  border-color:#af985a; 
  border-width:1px;
  color:#af985a;}
.follow-button:hover {
  cursor:pointer;}

/*Posts*/
.flex-container {
  display: flex;
  justify-content: center;
flex-wrap: wrap;}

img {
    max-width:270px;
  height:auto;
padding:15px;}
<div class="flex-container">
  <div class="profile-picture image">
  </div>
</div>

<div class="profile-name">
  <p>cole gwoz</p> 
</div>

<div class="user-name">
  <p>colegwoz</p>
</div>

<div class="follow-button-position">
  <button class="follow-button">Follow</button>
</div>

<div class="flex-container">
  <div>
<img src="https://www.dropbox.com/s/4c05cegbonfqo5k/Photo%202018-03-03%2C%202%2020%2022%20PM.jpg?raw=1"></div>
  
  <div><img src="https://www.dropbox.com/s/qzuhelo4lf7eyu0/Photo%202018-01-01%2C%204%2038%2037%20PM.jpg?raw=1"></div>
  
  <div><img src="https://www.dropbox.com/s/8dtg60sbha99x2o/Photo%202018-02-05%2C%209%2026%2043%20AM.jpg?raw=1"></div>
  
  <div><img src="https://www.dropbox.com/s/qzuhelo4lf7eyu0/Photo%202018-01-01%2C%204%2038%2037%20PM.jpg?raw=1"></div>
  
  <div><img src="https://www.dropbox.com/s/qzuhelo4lf7eyu0/Photo%202018-01-01%2C%204%2038%2037%20PM.jpg?raw=1"></div>
  
</div>

最佳答案

justify-content: center; 更改为 justify-content: flex-start; 并从那里使用 margin-left。

通常容器会有一些填充

关于html - Flexbox 图像布局列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49560093/

相关文章:

javascript - 如何使用 jquery 更新 HTML 表格单元格

html - 如何避免 Firefox 从表中复制时出现额外的换行符?

javascript - 为什么此 HTML 无法打印?

javascript - 使用 CSS 悬停在父 JSX 上更改子 div 的样式

css3,flex,元素而不是换行到下一行,最小化并在单行中对齐

html - 右对齐 flex 元素并垂直居中其内容

html - div 旁边的垂直对齐标题

javascript - 如何使用 JavaScript 更改第三方选择标签值

css - 如何添加媒体查询以使图像的填充更小?

jquery - CSS - 选择框,如何使用所选选项更改文本颜色