AnswerBun.com

CSS flex, full height sidebar inside a modal?

Stack Overflow Asked by DDulla on December 25, 2020

I’m trying to create a modal that contains the following properties:

  • 2 column layout
  • Column 1 is one container (left) that fills the entire height of the modal.
  • Column 2 (right) is a container with a sticky header and footer, such that the content section is scrollable.
  • Responsive – hide the left column on mobile and fill the entire viewport if the modal is on mobile.
  • I’m comfortable in bootstrap, originally i was going to use that framework, but it seemed there was little that i could use in the framework.

Issues:

  • I can’t get the sidebar to fill the entire container. align-items:stretch should work, no?

Picture of desktop/mobile (Scrollable section in red for clarity):

Desktop Version
Mobile Version

Code:

$(document).ready(function(){
    // the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered
    $('.modal-trigger').leanModal();
  });
.modal {
  overflow: hidden;
}
.modal-wrapper{
  display:flex;
  flex-direction:row;
  align-items:stretch;
}
.modal-main{
/*   display:flex;
  flex:25%; */
}

.modal-sidebar{
  display:flex;
  background-color:red;
  height:100%;
}

.modal-header {
  padding: 15px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  width:100%
}

.modal-header h4 {
  margin: 0;
}

.modal-content {
  height: auto !important;
  max-height: calc(100vh - 340px) !important; 
}

.content-row {
  display: flex;
  align-items: center;
  padding: 10px;
  border-bottom: 1px solid #ddd; 
}

.content-row:last-child {
  border-bottom: none;
}

.icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #33b5e5;
  color: #fff;
}

.name {
  padding: 0 10px;
}

.role {
  padding: 0 10px;
  flex: 1;
  text-align: right;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/css/materialize.css" rel="stylesheet"/>

  <!-- Modal Trigger -->
  <a class="modal-trigger waves-effect waves-light btn" href="#modal1">Modal</a>

  <!-- Modal Structure -->
  <div id="modal1" class="modal modal-fixed-footer">
    <div class="modal-wrapper"> 
    <div class="modal-sidebar">
      <h4>Modal Sidebar</h4>
    </div>
    <div class="modal-main">
    <div class="modal-header">
      <h4>Modal Header</h4>
    </div>
    <div class="modal-content">
      <div class="content-row">
        <div class="icon">1</div>
        <div class="name">Name</div>
        <div class="role">Role</div>
      </div>
      <div class="content-row">
        <div class="icon">1</div>
        <div class="name">Name</div>
        <div class="role">Role</div>
      </div>
      <div class="content-row">
        <div class="icon">1</div>
        <div class="name">Name</div>
        <div class="role">Role</div>
      </div>
      <div class="content-row">
        <div class="icon">1</div>
        <div class="name">Name</div>
        <div class="role">Role</div>
      </div>
      <div class="content-row">
        <div class="icon">1</div>
        <div class="name">Name</div>
        <div class="role">Role</div>
      </div>
      <div class="content-row">
        <div class="icon">1</div>
        <div class="name">Name</div>
        <div class="role">Role</div>
      </div>
      <div class="content-row">
        <div class="icon">1</div>
        <div class="name">Name</div>
        <div class="role">Role</div>
      </div>
      <div class="content-row">
        <div class="icon">1</div>
        <div class="name">Name</div>
        <div class="role">Role</div>
      </div>
      <div class="content-row">
        <div class="icon">1</div>
        <div class="name">Name</div>
        <div class="role">Role</div>
      </div>
      <div class="content-row">
        <div class="icon">1</div>
        <div class="name">Name</div>
        <div class="role">Role</div>
      </div>
      <div class="content-row">
        <div class="icon">1</div>
        <div class="name">Name</div>
        <div class="role">Role</div>
      </div>
      <div class="content-row">
        <div class="icon">1</div>
        <div class="name">Name</div>
        <div class="role">Role</div>
      </div>
      <div class="content-row">
        <div class="icon">1</div>
        <div class="name">Name</div>
        <div class="role">Role</div>
      </div>
      <div class="content-row">
        <div class="icon">1</div>
        <div class="name">Name</div>
        <div class="role">Role</div>
      </div>
    </div>
    <div class="modal-footer">
      <a href="#!" class="modal-action modal-close waves-effect waves-green btn-flat ">Agree</a>
    </div>
    </div>
    </div>
  </div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.5/js/materialize.min.js"></script>

One Answer

For the parent container that defines rule display: flex, you can use rule height: 100%.

.modal-wrapper {
    ...
    height: 100%;
}

Answered by sergey kuznetsov on December 25, 2020

Add your own answers!

Related Questions

Vimeo offline video playback issue

0  Asked on September 26, 2020 by ipatel

         

How to print data from a few arrays

3  Asked on September 25, 2020 by protodimbo

   

why this.key is not working properly in javacript?

2  Asked on September 25, 2020 by carlos-daniel

 

Pass the dynamic variable when button is pressed

1  Asked on September 19, 2020 by francy

 

detect a table part from entire image in python

5  Asked on September 19, 2020 by suji

   

C# Change number of decimals show, but it always skips a number

0  Asked on September 18, 2020 by theoverly

   

Custom font bold weight not working in Dompdf

1  Asked on September 17, 2020 by user13286

   

How to use has one through in laravel?

0  Asked on September 17, 2020 by ahz

       

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP