JSFiddle - React, Tailwind, and code Playground

by jsm11482

HTML

<p>Dropdown shows correctly here, but look what happens when you resize the preview area.</p>
<div class="header">
  <div class="logo">
    LOGO
  </div>
  <div class="menu">
    <a>Item 1</a>
    <a>Item 2</a>
    <a>Item 3</a>
    <div class="dropdown active">
      <div>Item 4 Dropdown</div>
      <div class="dropdown-menu">
        <a>Item A</a>
        <a>Item B</a>
        <a>Item C</a>
        <a>Item D</a>
      </div>
    </div>
    <a>Item 5</a>
  </div>
  
  <div class="other-thing">
    This is some other thing.
  </div>
</div>

<p class="with-some-space">Note how the "other thing" falls out to the right.</p>
<p>Adding <code>overflow: hidden</code> to the menu container element makes it so the "other thing" doesn't get pushed. However, this also prevents the drop-down menu from showing, of course. I tried to work around it by setting <code>overflow-x: hidden; overflow-y: visible</code> but this is apparently not a valid setting.</p>
<div class="header">
  <div class="logo">
    LOGO
  </div>
  <div class="menu overflow-hidden">
    <a>Item 1</a>
    <a>Item 2</a>
    <a>Item 3</a>
    <div class="dropdown active">
      <div>Item 4 Dropdown</div>
      <div class="dropdown-menu">
        <a>Item A</a>
        <a>Item B</a>
        <a>Item C</a>
        <a>Item D</a>
      </div>
    </div>
    <a>Item 5</a>
  </div>
  
  <div class="other-thing">
    This is some other thing.
  </div>
</div>

<p><strong>Question:</strong> How can I make it work like the bottom example, but without adding <code>overflow: hidden</code> to the menu? That is, how can I stop flex-box from pushing the "other thing" out to the right?</p>

SCSS

.header {
  display: flex;
  align-items: center;
  height: 70px;
  padding: 0 10px;
  background-color: #333;

  .logo {
    flex: 0 0 50px;
    color: orange;
    font-size: 30px;
  }

  .menu {
    display: flex;
    flex-grow: 1;
    flex-shrink: 1;
    justify-content: center;
    align-items: center;
    margin: 0 10px;
    padding: 0 10px;
    color: #999;

    > a,
    > .dropdown {
      margin: 0 5px;
      padding: 5px 10px;
      cursor: pointer;
      white-space: nowrap;

      &:hover {
        color: white;
      }
    }

    .dropdown {
      position: relative;

      > .dropdown-menu {
        position: absolute;
        top: 28px;
        left: 0;
        width: calc(100% + 20px);
        padding: 10px 0;
        color: #ccc;
        background-color: #555;

        > a {
          display: block;
          padding: 5px 10px;
        }
      }
    }

    .active {
      background-color: #555;
      color: white;
    }
  }

  .overflow-hidden {
    overflow: hidden;
  }

  .other-thing {
    flex: 0 0 200px;
    padding: 10px;
    background-color: #555;
  }
}

.with-some-space {
  margin-top: 150px;
}