Can't scroll in modal content unless height is specified (iOS)












0















So this annoying bug keeps coming up on iOS units running both Chrome and Safari.



Markup



<div class="modal">
<div class="modal-inner">
<div class="modal-header">Title</div>
<div class="modal-content">…</div>
<div class="modal-footer">Footer</div>
</div>
<div class="modal-background"></div>
</div>


CSS



.modal {
position: fixed;
z-index: 10;
bottom: 0;
left: 0;

width: 100%;
height: 100%;
}

.modal-inner {
position: relative;
z-index: 11;

display: grid;
grid-template-rows: 70px auto 97px;

width: 100%;

background-color: #fff;
}

.modal-header,
.modal-footer {
display: flex;
align-items: center;

width: 100%;
padding: 24px;
}

.modal-header {
border-bottom: 1px solid #ccc;
}

.modal-footer {
border-top: 1px solid #ccc;
}

.modal-content {
overflow-y: auto;

height: calc(100vh - 166px);

padding: 24px;

-webkit-overflow-scrolling: touch;
}

.modal-background {
position: absolute;
z-index: 9;
top: 0;
right: 0;
bottom: 0;
left: 0;

width: 100%;
height: 100%;

background: rgba(0,0,0, 0.5);
}


Problem



You can try this code right here (CodePen) and see that it works out without a problem (iOS units). But when I remove line 43, height: calc(100vh - 166px);, I can't scroll anymore. So this is the total height of the viewport, minus the header, the footer and 1 pixel (numbers given at the grid-template-rows line). If I would change it to - 167px, or anything higher, it stops working.



I've realized that a height must be specified for .modal-content. The problem is, I want the modal to have a dynamic height based on the content (and position the content at the bottom). If the content isn't tall enough to be scrolled, I want the .modal-inner to not cover the whole screen.



Previously tried solutions



I can't do max-height: calc(100vh - 166px) and don't specify a height -- that doesn't work.



position: sticky instead of position: fixed doesn't change anything.



I've also tried to not use a CSS grid, but same problem goes for using flexbox or having the content and footer using position: absolute.



Adding a height to the element through JavaScript isn't really a solution I want to go with here, since there are tons of viewports sizes, sometimes the modal has accordions that can open/close, etc.





This is as clean I can get with my code. I've stripped tons of things to show you guys that this doesn't work, even in it's simplest form.



My searches on Google hasn't given me anything yet. I've looked at other well-known sites for guidance in their code, but none of them seem to be using this type of dynamic height-type of modal (maybe because of this bug?); one example is airbnb.com. Even with the lowest amount of content, they still go full height all the time.



Please give me guidance through this jungle, because I'm soon out hair to tear out.



Thank you!










share|improve this question



























    0















    So this annoying bug keeps coming up on iOS units running both Chrome and Safari.



    Markup



    <div class="modal">
    <div class="modal-inner">
    <div class="modal-header">Title</div>
    <div class="modal-content">…</div>
    <div class="modal-footer">Footer</div>
    </div>
    <div class="modal-background"></div>
    </div>


    CSS



    .modal {
    position: fixed;
    z-index: 10;
    bottom: 0;
    left: 0;

    width: 100%;
    height: 100%;
    }

    .modal-inner {
    position: relative;
    z-index: 11;

    display: grid;
    grid-template-rows: 70px auto 97px;

    width: 100%;

    background-color: #fff;
    }

    .modal-header,
    .modal-footer {
    display: flex;
    align-items: center;

    width: 100%;
    padding: 24px;
    }

    .modal-header {
    border-bottom: 1px solid #ccc;
    }

    .modal-footer {
    border-top: 1px solid #ccc;
    }

    .modal-content {
    overflow-y: auto;

    height: calc(100vh - 166px);

    padding: 24px;

    -webkit-overflow-scrolling: touch;
    }

    .modal-background {
    position: absolute;
    z-index: 9;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;

    width: 100%;
    height: 100%;

    background: rgba(0,0,0, 0.5);
    }


    Problem



    You can try this code right here (CodePen) and see that it works out without a problem (iOS units). But when I remove line 43, height: calc(100vh - 166px);, I can't scroll anymore. So this is the total height of the viewport, minus the header, the footer and 1 pixel (numbers given at the grid-template-rows line). If I would change it to - 167px, or anything higher, it stops working.



    I've realized that a height must be specified for .modal-content. The problem is, I want the modal to have a dynamic height based on the content (and position the content at the bottom). If the content isn't tall enough to be scrolled, I want the .modal-inner to not cover the whole screen.



    Previously tried solutions



    I can't do max-height: calc(100vh - 166px) and don't specify a height -- that doesn't work.



    position: sticky instead of position: fixed doesn't change anything.



    I've also tried to not use a CSS grid, but same problem goes for using flexbox or having the content and footer using position: absolute.



    Adding a height to the element through JavaScript isn't really a solution I want to go with here, since there are tons of viewports sizes, sometimes the modal has accordions that can open/close, etc.





    This is as clean I can get with my code. I've stripped tons of things to show you guys that this doesn't work, even in it's simplest form.



    My searches on Google hasn't given me anything yet. I've looked at other well-known sites for guidance in their code, but none of them seem to be using this type of dynamic height-type of modal (maybe because of this bug?); one example is airbnb.com. Even with the lowest amount of content, they still go full height all the time.



    Please give me guidance through this jungle, because I'm soon out hair to tear out.



    Thank you!










    share|improve this question

























      0












      0








      0








      So this annoying bug keeps coming up on iOS units running both Chrome and Safari.



      Markup



      <div class="modal">
      <div class="modal-inner">
      <div class="modal-header">Title</div>
      <div class="modal-content">…</div>
      <div class="modal-footer">Footer</div>
      </div>
      <div class="modal-background"></div>
      </div>


      CSS



      .modal {
      position: fixed;
      z-index: 10;
      bottom: 0;
      left: 0;

      width: 100%;
      height: 100%;
      }

      .modal-inner {
      position: relative;
      z-index: 11;

      display: grid;
      grid-template-rows: 70px auto 97px;

      width: 100%;

      background-color: #fff;
      }

      .modal-header,
      .modal-footer {
      display: flex;
      align-items: center;

      width: 100%;
      padding: 24px;
      }

      .modal-header {
      border-bottom: 1px solid #ccc;
      }

      .modal-footer {
      border-top: 1px solid #ccc;
      }

      .modal-content {
      overflow-y: auto;

      height: calc(100vh - 166px);

      padding: 24px;

      -webkit-overflow-scrolling: touch;
      }

      .modal-background {
      position: absolute;
      z-index: 9;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;

      width: 100%;
      height: 100%;

      background: rgba(0,0,0, 0.5);
      }


      Problem



      You can try this code right here (CodePen) and see that it works out without a problem (iOS units). But when I remove line 43, height: calc(100vh - 166px);, I can't scroll anymore. So this is the total height of the viewport, minus the header, the footer and 1 pixel (numbers given at the grid-template-rows line). If I would change it to - 167px, or anything higher, it stops working.



      I've realized that a height must be specified for .modal-content. The problem is, I want the modal to have a dynamic height based on the content (and position the content at the bottom). If the content isn't tall enough to be scrolled, I want the .modal-inner to not cover the whole screen.



      Previously tried solutions



      I can't do max-height: calc(100vh - 166px) and don't specify a height -- that doesn't work.



      position: sticky instead of position: fixed doesn't change anything.



      I've also tried to not use a CSS grid, but same problem goes for using flexbox or having the content and footer using position: absolute.



      Adding a height to the element through JavaScript isn't really a solution I want to go with here, since there are tons of viewports sizes, sometimes the modal has accordions that can open/close, etc.





      This is as clean I can get with my code. I've stripped tons of things to show you guys that this doesn't work, even in it's simplest form.



      My searches on Google hasn't given me anything yet. I've looked at other well-known sites for guidance in their code, but none of them seem to be using this type of dynamic height-type of modal (maybe because of this bug?); one example is airbnb.com. Even with the lowest amount of content, they still go full height all the time.



      Please give me guidance through this jungle, because I'm soon out hair to tear out.



      Thank you!










      share|improve this question














      So this annoying bug keeps coming up on iOS units running both Chrome and Safari.



      Markup



      <div class="modal">
      <div class="modal-inner">
      <div class="modal-header">Title</div>
      <div class="modal-content">…</div>
      <div class="modal-footer">Footer</div>
      </div>
      <div class="modal-background"></div>
      </div>


      CSS



      .modal {
      position: fixed;
      z-index: 10;
      bottom: 0;
      left: 0;

      width: 100%;
      height: 100%;
      }

      .modal-inner {
      position: relative;
      z-index: 11;

      display: grid;
      grid-template-rows: 70px auto 97px;

      width: 100%;

      background-color: #fff;
      }

      .modal-header,
      .modal-footer {
      display: flex;
      align-items: center;

      width: 100%;
      padding: 24px;
      }

      .modal-header {
      border-bottom: 1px solid #ccc;
      }

      .modal-footer {
      border-top: 1px solid #ccc;
      }

      .modal-content {
      overflow-y: auto;

      height: calc(100vh - 166px);

      padding: 24px;

      -webkit-overflow-scrolling: touch;
      }

      .modal-background {
      position: absolute;
      z-index: 9;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;

      width: 100%;
      height: 100%;

      background: rgba(0,0,0, 0.5);
      }


      Problem



      You can try this code right here (CodePen) and see that it works out without a problem (iOS units). But when I remove line 43, height: calc(100vh - 166px);, I can't scroll anymore. So this is the total height of the viewport, minus the header, the footer and 1 pixel (numbers given at the grid-template-rows line). If I would change it to - 167px, or anything higher, it stops working.



      I've realized that a height must be specified for .modal-content. The problem is, I want the modal to have a dynamic height based on the content (and position the content at the bottom). If the content isn't tall enough to be scrolled, I want the .modal-inner to not cover the whole screen.



      Previously tried solutions



      I can't do max-height: calc(100vh - 166px) and don't specify a height -- that doesn't work.



      position: sticky instead of position: fixed doesn't change anything.



      I've also tried to not use a CSS grid, but same problem goes for using flexbox or having the content and footer using position: absolute.



      Adding a height to the element through JavaScript isn't really a solution I want to go with here, since there are tons of viewports sizes, sometimes the modal has accordions that can open/close, etc.





      This is as clean I can get with my code. I've stripped tons of things to show you guys that this doesn't work, even in it's simplest form.



      My searches on Google hasn't given me anything yet. I've looked at other well-known sites for guidance in their code, but none of them seem to be using this type of dynamic height-type of modal (maybe because of this bug?); one example is airbnb.com. Even with the lowest amount of content, they still go full height all the time.



      Please give me guidance through this jungle, because I'm soon out hair to tear out.



      Thank you!







      html ios css






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 26 '18 at 11:10









      Erik BlomqvistErik Blomqvist

      1491211




      1491211
























          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53479861%2fcant-scroll-in-modal-content-unless-height-is-specified-ios%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53479861%2fcant-scroll-in-modal-content-unless-height-is-specified-ios%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Wiesbaden

          Marschland

          Dieringhausen