how do I flexbox column and hover horizontal divs?

Viewed 195

I am trying to build a flexbox column with a column header similar to this image , but however on hover event, I want to place two extra divs horizontal as the layout image. I could code a proof of concept UI HTML CSS, but how do I build or place header title above div item , and on-hover horizontal extra divs?

note: similar to drop-down menu, but on a flexbox column once hover event is open add two extra divs as the image

layout

.container {
  display: flex;
  flex-direction: column;
}

.item {
  background: #ce8888;
  flex-basis: 100px;
  height: 100px;
  margin: 5px;
}
<div class="container">
  <div class="item">
  </div>
  <div class="item">
  </div>
</div>

2 Answers

You mentioned dropdown menus. I think you essentially emulate that behavior.

.container {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  width: 100%;
  background: #ddd;
  margin-bottom: 8px;
}

.heading {
  flex-basis: 100px;
  text-align: center;
  background: #bbb;
}

.detail {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  text-align: center;
  background: pink;
  max-width: 0;
  overflow: hidden;
  transition: all 0.3s;
}

.container:hover .detail {
  max-width: calc(100% - 100px);
}

.detail > div {
  white-space: nowrap;
  margin: 4px;
  background: #ccc;
}
<div class="container">
  <div class="heading">Heading A</div>

  <div class="detail">
    <div>Detail One</div>
    <div>Detail Two</div>
  </div>
</div>

<div class="container">
  <div class="heading">Heading B</div>

  <div class="detail">
    <div>Detail One</div>
    <div>Detail Two</div>
  </div>
</div>

Not exactly sure what you are asking for but here goes an example based on your image. Just a simple example, you can style it however you want later.

/*  This is important for the sizing. 
    Has to be wildcard selector because this property does not inherit */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 20px;
  font-size: 15px;
  line-height: 1.4em;
  background: slategray;
  font-family: sans-serif;
}

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

.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="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>

Related