html - 将 div 内容显示为行,而父级显示为列

标签 html css flexbox

我现在正在研究一个问题几个小时(不是那么有经验 :D),现在我已经很接近了,但还有最后一件事不起作用:

我有多个 div,它们的方向各不相同。内部 parent div 有 flex-direction: column;child 有 flex-direction: row; 但它没有内联显示。

JSFiddle 链接:Live Demo


HTML

<div class="flexcon_game">
  <div class="flexcon_game_left">
    Left
  </div>
  <div class="flexcon_game_center">
    <div class="flexcon_game_center_top">
       center_top
    </div>
  <div class="flexcon_game_center_mid">
    <p> (-- </p>
    <p> -:- </p>
    <p> --) </p>
  </div>
  <div class="flexcon_game_center_bottom">
    center_bottom
  </div>
</div>
<div class="flexcon_game_right">
   right
</div>

CSS

.flexcon_game{
   width: 80%;
   margin: auto;
   display: flex;
   flex-wrap: nowrap;
   justify-content: space-around;
   align-items: center;
 }
.flexcon_game_left{
   background-color: red;
 }
.flexcon_game_right{
    background-color: green;
 }
.flexcon_game_center{
    flex-direction: column;
    justify-content: space-around;
    background-color: orange;
 }
 .flexcon_game_center_mid{
     flex-flow: row nowrap;
 }

最佳答案

段落是 block 级元素。将 flex 方向设置为 row 不会改变这一点。您必须在您的 CSS 中明确地使它们内联:

.flexcon_game{
   width: 80%;
   margin: auto;
   display: flex;
   flex-wrap: nowrap;
   justify-content: space-around;
   align-items: center;
 }
.flexcon_game_left{
   background-color: red;
 }
.flexcon_game_right{
    background-color: green;
 }
.flexcon_game_center{
    flex-direction: column;
    justify-content: space-around;
    background-color: orange;
 }
 .flexcon_game_center_mid{
     flex-flow: row nowrap;
 }
 
 .flexcon_game_center_mid p{
 	display: inline;
}
<div class="flexcon_game">
  <div class="flexcon_game_left">
    Left
  </div>
  <div class="flexcon_game_center">
    <div class="flexcon_game_center_top">
       center_top
    </div>
  <div class="flexcon_game_center_mid">
    <p> (-- </p>
    <p> -:- </p>
    <p> --) </p>
  </div>
  <div class="flexcon_game_center_bottom">
    center_bottom
  </div>
</div>
<div class="flexcon_game_right">
   right
</div>

关于html - 将 div 内容显示为行,而父级显示为列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37124281/

相关文章:

javascript - Electron 中的jQuery集成

javascript - 无法通过 JavaScript 从输入中获取值

css - p标签和输入标签之间有一个像素的差距

css - Flexbox 网格 : How to display 3 items side-by-side but varying vertical positions

css - 垂直居中和拉伸(stretch)行导向的 Flexbox

html - 如何使用css将div中的内容居中

html - 如何删除 eBay 上的导航栏?

jquery - 仅在 chrome 和 safari 上损坏响应式布局,但 firefox 有效

css - 设置 Ionic 警报弹出元素的默认样式

html - 在 Flexbox 中居中不起作用。什么是高度、宽度、显示和位置要求?我错过了什么?