Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

camiant's avatar

vue modal: make it scrollable ... instead of background

http://vuejs.org/examples/modal.html as asked in title, when filled with long content, how can I make this possible editing css rules?

thanks

0 likes
7 replies
Phinocio's avatar

Check out this fiddle. https://jsfiddle.net/cf2h9657/

I added

max-height: 30px; 

and

overflow-y: auto;

to the .modal-container class in the CSS. Not 100% sure if this is what you wanted, but it makes the modal scrollable if there is more than 30px worth of content (can change the 30px to anything you need :) ). If you wanted just the content to be scrollable, then you can add those to the .modal-body.

2 likes
Nilsi's avatar

I'm also looking for this. Did you find any modals built for Vue that supports this?

achillesp's avatar

Setting the css for the modal like Devon said works. I've updated the js fiddle from the Vue.js 2.0 modal example here (by setting the scroll on the modal-body): https://jsfiddle.net/achillesp/1rpf6fme/

I've set some max/min heights in css to present it better.

The trick to stop the background from scrolling is to make it fixed when the modal shows. This could be applied either to the html body, or to a parent div that contains the page content.

Nilsi's avatar

I think what you show here is slightly different from what we need.

  1. The modal should not scroll itself. The window should scroll the modal. Look at how the last example long modals works here http://jschr.github.io/bootstrap-modal/

  2. The modal should resize based on its conents height.

I think to achieve this we need a javascript solution. Preferably built for Vue.

Please or to participate in this conversation.