html - How to make flex child height to wrap content -


this question has answer here:

what want make each child element's height wrap content.

here code:

<style>  .parent{         display: flex;     }  .child{      padding: 5px;     margin: 10px;     background: green;     height: auto; }     </style>  <div class="parent">      <div class="child">child1</div>     <div class="child">child2</div>     <div class="child">child3</div>     <div class="child" style="height:50px">child1</div>  </div> 

output:
enter image description here

expected output:
enter image description here

you need set align-items: flex-start on parent element because default value stretch.

.parent {    display: flex;    align-items: flex-start;  }    .child {    padding: 5px;    margin: 10px;    background: green;    height: auto;  }
<div class="parent">    <div class="child">child1</div>    <div class="child">child2</div>    <div class="child">child3</div>    <div class="child" style="height:50px">child1</div>  </div>


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -