Отрегулируйте все div одинаково с условием, что один div может иметь до 8 вложенных div, а другой - только один - PullRequest
0 голосов
/ 24 марта 2020

Это базовый c html с bootstrap flexbox. Второй div может содержать вложенный div до 8. И результат должен быть похож на прикрепленные скриншоты. Это может быть сделано с данной структурой. Я прилагаю большинство сценариев вместе с этим.

enter image description here

enter image description here

enter image description here

enter image description here

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Chat Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
  <style>
  .chat{

  }
  .chat .chat-part{
      height: 100px;
  }
  </style>
</head>
<body>

<div class="container-fluid">
  <h1>Grid Structure</h1>
  <p>Condition is one div always one or more than div inside it.</p>

  <div class="container-fluid">
    <!-- Control the column width, and how they should appear on different devices -->
    <div class="row chat">
      <!-- This is first div -->
      <div class="col" style="background-color:yellow;">owner</div>
      <!-- This is second div -->
      <div class="col d-flex px-0 chat-part">
       <!-- This div may have upto 8 nested div's -->
            <div class="col" style="background-color:orange;">chat1</div>
            <div class="col" style="background-color:yellow;">chat2</div>
            <div class="col" style="background-color:orange;">chat3</div>
            <div class="col" style="background-color:yellow;">chat4</div>
      </div>
    </div>


  </div>
</div>

</body>
</html>

1 Ответ

0 голосов
/ 24 марта 2020

В вашем случае вы можете добиться этого с помощью flexbox. Используйте .flex-column, чтобы установить вертикальное направление

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Chat Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
  <style>
  .chat{

  }
  .chat .chat-part{
      min-height: 100px;
  }
  </style>
</head>
<body>

<div class="container-fluid">
  <h1>Grid Structure</h1>
  <p>Condition is one div always one or more than div inside it.</p>

  <div class="container-fluid">
    <!-- Control the column width, and how they should appear on different devices -->
    <div class="row  chat flex-column">
      <!-- This is first div -->
      <div class="col chat-part" style="background-color:red;">Owner</div>

      <!-- This is second div -->
      <div class="col d-flex px-0 chat-part">
       <!-- This div may have upto 8 nested div's -->
            <div class="col" style="background-color:orange;">chat1</div>
            <div class="col" style="background-color:yellow;">chat2</div>
            <div class="col" style="background-color:orange;">chat3</div>
            <div class="col" style="background-color:yellow;">chat4</div>

      </div>
    </div>


  </div>
</div>

</body>
</html>
...