代码之家  ›  专栏  ›  技术社区  ›  Muhammad Umar

水平对齐并水平添加div项

  •  0
  • Muhammad Umar  · 技术社区  · 6 年前

    我正在使用以下代码

    <div style="display: table; width: 50%; clear: both; ">
        <div style="width: 50%; float: left;">
            <h1 style="font-size: 30px; font-weight: 600; color: #000;">
                <span><?php echo $genericItem;?></span>
                <img style="margin-left: 20px; height: 50px; width: 50px;" src="<?php echo $genericItemPath;?>" alt=""> 
            </h1>
        </div>
        <div style="width: 50%; float: right; margin-left: 25px;">
                <span style="font-size: 20px; color: #000"><b>Reorder</b> in <?php echo $reorderDays;?> days</span>
                <span style="display: block;  font-size: 12px; color: #d3d3d3; max-width: 90%;"><?php echo $reorderDate;?></span>
        </div>
    </div>
    

    创造这样的东西 enter image description here

    然而,第二个重新排序div显示在下面,但在右侧。如何修改div。

    1 回复  |  直到 6 年前
        1
  •  1
  •   Zonaxor    6 年前

    我希望这能有帮助。我认为使用 flex 弯曲 是现代网站开始使用的属性。

    .table {
      display: flex;
      flex-direction: row;
      flex-wrap: wrap;
      width: 100%;
    }
    
    .column {
      display: flex;
      flex-direction: column;
      flex-basis: 100%;
      flex: 1;
      justify-content: center;
      text-align: center;
    }
    
    /* extra */
    .column2 {background-color: #f8f8f8;}
    <div class="table">
      <div class="column">Apple</div>
      <div class="column column2">
        <p><b>Re-order:</b> in 3 days</p>
        <p>Tuesday 19-9-2018</p>
      </div>
    </div>

    更新:您可以删除 justify-content text-align 以及 .column2 . 我只有这样你才能欣赏这些专栏的样子。

        2
  •  0
  •   glneto    6 年前

    你有 width: 50% margin-left: 25px 这使得你的第二个div超过了你的屏幕宽度。

    尝试删除 margin-left 在这种情况下,第二个div应该向右浮动。 如果要在它们之间添加间距,请增大父宽度或减小每个div宽度。