css - 当元素自动换行而不填满行时如何使用 flexbox 并排放置元素

标签 css flexbox flexboxgrid

为了让这两个页脚元素在移动设备上并排显示,我已经尝试了我所知道的所有解决方案。我在 wordpress 网站 (www.med-tac.com) 上有三个页脚小部件,我正在尝试使用 @media 方法在移动设备上重新排序和对齐它们以适应我的屏幕尺寸。

我试图在同一行上获得 1 和 3 并尝试调整其他属性以使其工作,但现在我正在使用 flexbox 来尝试完成此操作,但很乐意恢复到任何解决方案有效。

我已经尝试过网格布局、左浮动和右浮动方法、flexbox 方法和显示内联 block 方法,这些方法都不会在同一行显示元素,即使宽度被手动减小到更小比移动页脚宽度。

@media (max-width: 480px){


.secondary {
display:flex;
flex-flow: row wrap;


  }

#footer-sidebar1 {

  margin-top:-5px;
  top:5px;
  order:2;
}

 #footer-sidebar2 {

  margin-right: 20px !important;
  right: 10px;
  width:325px !important;
  bottom:25px;
  order:1;

  }

#footer-sidebar3 {

  order:3;

  }

}

我试图让边栏 1 和 3 在同一行上并排显示,但它们相互重叠。

最佳答案

如果你想在第一行有第1项和第3项,你需要将第3项的顺序设置为小于第2项的顺序。

例如:

.secondary {
  display: flex;
  flex-flow: row wrap;
}

.secondary div {
  background-color: lightblue;
}

.secondary:after {
  content: "";
  order: 2;
  flex-basis: 110%;
}

#footer-sidebar1 {
  flex-basis: 48%;
  order: 3;
}

#footer-sidebar2 {
  order: 1;
  margin-right: 100px;
}

#footer-sidebar3 {
  flex-basis: 48%;
  order: 4;
  margin-left: 10px;
}
<div class="secondary">
  <div id="footer-sidebar1">sidebar 1 </div>
  <div id="footer-sidebar2">sidebar 2 </div>
  <div id="footer-sidebar3">sidebar 3 </div>
</div>

关于css - 当元素自动换行而不填满行时如何使用 flexbox 并排放置元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54175499/

相关文章:

html - CSS : Easiest way to Centering elements both horizontally and vertically using flex?

html - 如何使 resize 属性与 flexBox 一起使用?

css - 使 Angular Material Mat-Button-Toggle-Group 响应式

css - 如果不向 HTML 结构添加更多内容,是否可以实现这种 flexbox 布局?

html - 为什么图像边框设置为内联 block

javascript - 有没有办法根据当前窗口大小动态调整 html/cshtml 页面中组件的大小?

html - Flexbox 内容对齐

css - Flex 不是 Flex 任何解决方案 → justify-content :space-between and full nested item flexibility doesn't coexist

html - CSS Overlay 使文本变暗

javascript - 将 PDFObject 与 PDF.js 一起使用时隐藏打印按钮