I create a modal window on Bootstrap. I insert position: absolute elements into it. How to make the window automatically resize?

  • @sitev_ru, If you are given an exhaustive answer, mark it as correct (click on the check mark next to the selected answer). - Nicolas Chabanovsky

1 answer 1

Read about the positioning of elements on the page. What you want to do can not be passed on pure css, but you can try to download it with jquery:

 var el_width = $(element).width(); $('#popup').css('width', el_width); 

But do not forget that while the element is invisible ( display: none , which most often happens with pop-ups) its width is zero, and accordingly there is no sense to substitute something somewhere.

The only thing that comes to mind is to make all the calculations after initializing the popup.

  • Roughly speaking - it will not work: <div id = "modal" style = "position: relative"> <button id = "button" style = "position: absolute; left: 200px; top: 300px" /> </ div > And you need to manually calculate the size of the window and set them? - sitev_ru