bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Refine responsive modal variations

Open winterstetter opened this issue 14 years ago • 83 comments

As it says. Thanks for all your love, guys!

winterstetter avatar Feb 21 '12 12:02 winterstetter

I was going to put in something on this very topic but suggest the modal should render at the TOP of a iPhone. I have a long page (when responsively resized for the iPhone) and the modal is rendering at the very bottom so you have to scroll way down to find it. Should render at the top on responsive smaller screens no?

dstroot avatar Mar 06 '12 21:03 dstroot

Mark, you"ll figure out the smartest solution. Thanks!

winterstetter avatar Mar 07 '12 04:03 winterstetter

I found that if I had the "fade" option on it rendered the modal at the bottom of my iPhone (bad) but if I turned off the "fade" option it renders at the top (good) so I'm happy - I just won't use fade.

dstroot avatar Mar 12 '12 22:03 dstroot

I replicate what @dstroot reports and think it is neither top or bottom the modal should render BUT, if that's technically feasible, where the link for the modal is located on the document. That would be in the center of the visible screen, like on desktop, so no scrolling to top or bottom will be necessary.

winterstetter avatar Mar 13 '12 04:03 winterstetter

Has anyone tried the modal on an android phone. It looks completely broken with the top and the bottom getting cut off from the screen.

trungpham avatar Mar 20 '12 15:03 trungpham

Is a fix on the way in 2.0.3?

ShaneSheppard avatar Mar 26 '12 10:03 ShaneSheppard

I'm using 2.0.2 and was having this issue with the iphone. I sorta hacked it together to force it to work.

I forced the backdrop to fill the background by directly setting the height of the black background.

function backdrop( callback ) { var that = this , animate = this.$element.hasClass('fade') ? 'fade' : ''

if (this.isShown && this.options.backdrop) {
  var doAnimate = $.support.transition && animate

  this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />')
    .appendTo(document.body)

  // Edited here:  Set the height of the backdrop
  this.$backdrop.css( 'height', $(document).height() );

I also changed the show function. I overwrote some of the css properties with code, set the position to absolute and margin to 0. Then I manually calculated and set it's centered position.

, show: function () {
    var that = this

    if (this.isShown) return

    $('body').addClass('modal-open')

    this.isShown = true
    this.$element.trigger('show')

    // edit here to manually reposition
    this.$element.css('position', 'absolute');
    this.$element.css('margin', 0);
    var new_top = ($(window).height() / 2) - (this.$element.height() / 2) + $(window).scrollTop();
    this.$element.css('top', new_top);          
    var new_left = ($(window).width() / 2) - (this.$element.width() / 2);
    this.$element.css('left', new_left);

I don't know if this is the "proper" way or if it goes against any bootstrap philosophy. But it's doing the trick.

asoap avatar Mar 29 '12 04:03 asoap

Hi,

Here's the start of a fix. It is only a start as I'm afraid it: Does not work on android Is not tested on blackberry Is not tested on iOS <5

Android issue: If the modal height is greater than the screen, scrolling scrolls the background page, not the modal. The -webkit-overflow-scrolling: touch; line fixes this on iOS 5 but I don't think that is supported in iOS < 5.

My suspicion is that this only works on iOS 5+ so definitely not ready for inclusion but a possible starting point.

Props to @cferdinandi for -webkit-overflow-scrolling in issue #3230 (dupe?).

@media (max-width: 480px) {
  .modal {
    height: 500px; /* Set a default max height of the modal (adjusted later)*/
    position: fixed; /* Display modal in the centre of your screen */
    overflow-y: scroll; /*  Ensure that the modal is scroll-able */
    -webkit-overflow-scrolling: touch; /* Avoid having to use 2 finger scroll on iOS  */
  }
  .modal.fade.in{
    top: 5px; /* Use more screen real estate */
  }
  .modal-body{
    /* Increase the max height of the modal body to try & avoid both it,
     * and the modal container having scroll bars which results in odd behavior */ 
    max-height: 2400px; 
  }  
}

/* Now adjust the height so it handles various screen sizes & orientations */
/* You could make this as granular as you like, or have it more granular at common screen sizes
 * but it should start at the height we set on .modal (i.e. 500px) & work down */
@media (max-width: 480px) and (max-height: 500px){.modal{ height: 450px}}
@media (max-width: 480px) and (max-height: 450px){.modal{ height: 400px}}
@media (max-width: 480px) and (max-height: 400px){.modal{ height: 350px}}
@media (max-width: 480px) and (max-height: 350px){.modal{ height: 300px}}
@media (max-width: 480px) and (max-height: 300px){.modal{ height: 250px}}
@media (max-width: 480px) and (max-height: 250px){.modal{ height: 200px}}
@media (max-width: 480px) and (max-height: 200px){.modal{ height: 150px}}

brightchimp avatar May 18 '12 09:05 brightchimp

I was previously having trouble with a modal on a responsive site, but seemed to have solved it with just defining the modal right after the navigation. It now shows at the top where you'd expect it to. Have you tried that?

tmchow avatar Jul 01 '12 21:07 tmchow

@tmchow - Because modals are switched to relative positioning by default in Bootstrap, the issue is not so much that they don't show up at the top of the page, but that they show up at the top of the page even if you're near the bottom, which means the user may not realize there's a modal open. A user shouldn't have to scroll up to view an open modal - it should display wherever they are on the screen.

@brightchimp - any idea why that doesn't work in Android?

cferdinandi avatar Jul 03 '12 22:07 cferdinandi

@cferdinandi

I'm not entirely sure why exactly but have just had a quick look to remind myself (slow & painful on my old phone).

The problem seems to be what -webkit-overflow-scrolling: touch was introduced to remedy (which Android does not support).

By giving the modal a fixed position, scrolling always scrolls the page in the background, not the contents of the modal. This is not an issue if you don't have much in your modal & it fits nicely on to one screen but if your content takes up more than one screen, anything beyond that is not accessible.

I am also noticing problems with clicking links & generally interacting with controls in the modal.

brightchimp avatar Jul 04 '12 12:07 brightchimp

Is it nice idea to make the modal respond to classes like .large .small etc?

Currently I need a modal which must be a little bit wider but I can't find "bootstrap way" to resize it.

gudata avatar Jul 05 '12 07:07 gudata

:+1: Attempting to do an Android fix here.

desimone avatar Jul 12 '12 16:07 desimone

I can't test on anything other than Android Jelly bean at the moment...

but removing top: auto from .modal.fade.in from bootstrap.responsive.css and adding a margin-top:-25% into the main style sheet works for me.

.modal.fade.in { margin-top: -25%; top: 50%; }

vviikk avatar Jul 18 '12 11:07 vviikk

@piggyslasher - Your fix seems to work on iOS 5.1.1 as well.

ghost avatar Jul 26 '12 18:07 ghost

Hey guys. I had the same issue today and after I failed to make it work with CSS, I picked the hard way: JS! So instead to reposition the whole modal box, I took another way: what if I just scroll the whole browser window?. So the show method became:

    , show: function () {
        var that = this
          , e = $.Event('show')
        that.oldWindowPosition = $(window).scrollTop(); // 
        $('body, html').scrollTop(0); //

And hide method became:

, hide: function (e) {
        e && e.preventDefault()

        var that = this
        $('body, html').scrollTop(that.oldWindowPosition) //

Lines that have // at the end are those that does the job.

iamntz avatar Jul 27 '12 10:07 iamntz

Staicu

So my fix didn't work for you? On Jul 27, 2012 6:25 PM, "Staicu Ionut" < [email protected]> wrote:

Hey guys. I had the same issue today and after I failed to make it work with CSS, I picked the hard way: JS! So instead to reposition the whole modal box, I took another way: what if I just scroll the whole browser window?. So the show method became:

    , show: function () {
        var that = this
          , e = $.Event('show')
        that.oldWindowPosition = $(window).scrollTop(); //
        $('body, html').scrollTop(0); //

And hide method became:

, hide: function (e) {
        e && e.preventDefault()

        var that = this
        $('body, html').scrollTop(that.oldWindowPosition) //

Lines that have // at the end are those that does the job.


Reply to this email directly or view it on GitHub: https://github.com/twitter/bootstrap/issues/2130#issuecomment-7302219

vviikk avatar Jul 27 '12 12:07 vviikk

@piggyslasher no, not really. The modal was displayed always on the top of the document. (latest stable iOS)

iamntz avatar Jul 27 '12 12:07 iamntz

It might be interesting to consider a full screen modal on smartphone screens. Since the screen is so small already any additional borders and shadows are simply a waste of valuable space. If you position the modal as fixed it would also reduce the problems with modals not being visible.

grundid avatar Aug 01 '12 20:08 grundid

@grundid - That's a splendid recommendation. Shouldn't be too hard to implement, either.

cferdinandi avatar Aug 01 '12 21:08 cferdinandi