How can I build multi layout column with flex?

Viewed 54

I want to build a multi-layout column with flex-items where each column contains a dynamic list, however, each component or item will contain 2 or more extra items where it would be expanded on hover, but how can I build the following layout to achieve the desired UI? I have done some of the components where on hover expands to extra items, but it acts as a row instead of column.

Desired:

desired

Layout:

layout

.flex-container {
  padding: 0;
  margin: 0;
  list-style: none;
  max-height: 600px;
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-flow: column wrap;
  justify-content: space-around;
}

.flex-item {
  flex-direction: column;
}

.ex-col {
  width: 100%;
  max-width: 420px;
  background: white;
  padding: 20px;
  color: #555;
}

.ex-col h2 {
  font-size: 1.1em;
  line-height: 1.3em;
  text-align: center;
  font-weight: bold;
  margin: 0 0 10px;
  padding: 0 0 10px;
  border-bottom: 1px solid slategray;
  width: 100%;
  font-weight: bold;
}

.ex-col h2>small {
  display: block;
  font-size: .9rem;
  line-height: 1.3rem;
  font-weight: normal;
}

.ex-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-gap: 10px;
}


/* The list item element. Must be FLEX */

.ex-list>li {
  display: flex;
  align-items: center;
  min-height: 70px;
}


/* The list heading element */

.ex-list h3 {
  font-size: 1em;
  line-height: 1.4em;
  padding: 6px 8px;
  border: 1px solid slategray;
  display: flex;
  align-items: center;
  /*  Set flex size to 50% of the parent element width. 
          This is a good way to make sure it is always 50% */
  flex-basis: 100%;
  max-width: 50%;
  cursor: pointer;
  margin: 0;
}

.ex-list h3>small {
  font-size: .6em;
  line-height: 1em;
  color: lightgray;
  margin: 0 0 0 .5em;
}


/* The sub-menu element. Initial state is display:none */

.ex-list-sub {
  display: none;
  list-style: none;
  padding: 0 0 0 20px;
  margin: 0;
  position: relative;
  flex-basis: 100%;
  max-width: 50%;
  transition: opacity .4s ease-out;
  border: 1px solid gray;
  border-left: none;
}

.ex-list-sub:before {
  content: "";
  display: block;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 20px;
  background: gray;
}

.ex-list-sub>li:not(:first-child) {
  border-top: 1px solid gray;
}

.ex-list-sub>li>a {
  display: block;
  padding: 6px 8px;
  color: inherit;
  text-decoration: none;
  transition: background .2s;
}

.ex-list-sub>li>a:hover {
  background: #efefef;
}


/* THE HOVER ACTION */


/*  Set the hover on the parent element. 
        Has to be the parent because otherwise the pop-up would disappear when you hover over it */

.ex-list>li:hover .ex-list-sub {
  display: block;
}
<div class="flex-container">
  <div class="flex-item">
    <div class="ex-col">
      <h2>
        Reconnaissance
        <small>10 Techniques</small>
      </h2>
      <ul class="ex-list">
        <li>
          <h3>
            Active Scanning
            <small>(0/2)</small>
          </h3>
          <ul class="ex-list-sub">
            <li>
              <a href="#">
                    Scanning IP Blocks
                  </a>
            </li>
            <li>
              <a href="#">
                    Vulnerability Scanning
                  </a>
            </li>
          </ul>
        </li>
      </ul>
    </div>
    <div class="ex-col">
      <h2>
        Reconnaissance
        <small>10 Techniques</small>
      </h2>
      <ul class="ex-list">
        <li>
          <h3>
            Active Scanning
            <small>(0/2)</small>
          </h3>
          <ul class="ex-list-sub">
            <li>
              <a href="#">
                    Scanning IP Blocks
                  </a>
            </li>
            <li>
              <a href="#">
                    Vulnerability Scanning
                  </a>
            </li>
          </ul>
        </li>
      </ul>
    </div>
  </div>
</div>

2 Answers

Please try this code, To How can I build a multi-layout column with flex?

html {
    height: 100%;
}

body {
    height: 100%;
    display: flex;
    flex-flow: column nowrap;
}

h1 {
    padding: 1em;
}

#content {
    padding: 10px;
    background-color: #eee;
    display: flex;
    flex-grow: 1;
}

#content > .group {
    margin: 10px;
    padding: 10px;
    border: 1px solid #cfcfcf;
    background-color: #ddd;
    flex: 1 1 auto;
}

#content > .group:first-child {
    columns: 10em;
    flex-grow: 2;    
}

#content > .group .item {
    margin: 10px;
    padding: 10px;
    background-color: #aaa;
    break-inside: avoid;
}

#content > .group .item:first-child {
    margin-top: 0;
}
<h1>Page Title</h1>

<div id="content">
    <div class="group">
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
    </div>
    
    <div class="group">
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
    </div>
    
    <div class="group">
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
    </div>
</div>

I hope this code will be useful to you.

Thank you.

You need to add

display: flex;

to your flex-item class. And you should probably rename it as it will be out of sync with reality. Here is a codepen with the example

Related