Hello! There is a form with select where the select2 plugin is used. Faced the following problem: select2 calculates the width of selects only when the page is loaded (the statement is probably wrong, but I have this), so for the div.select2-container selector div.select2-container set the width: 100% !important style.
I solved one problem, another one appeared - since div.select2-container is in the root of the body and has absolute positioning indented from the left edge, it selects its right edge from the body and expands it. Therefore, I had the idea to indicate in select2 a parent for the drop-down list. I did not find such a possibility in the plug-in documentation, does it exist at all, and if so, how to do it?
According to the link the page with the problem form , the problem is observed only in the mobile version in the developer mode - when the selektov opens, the header shifts to the right .
UPD: added a standard select where you can see that the drop-down list is located in the root of the body.
UPDD: I found an option here using AttachContainer , I tried it - the drop-down list remains in the same place. Made changes to the code.
$(document).ready(function() { $(".js-example-basic-single").select2({ minimumResultsForSearch: Infinity, AttachContainer: $('.wrapper') }) }); <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script> <div class="wrapper"> <select class="js-example-basic-single" style="width: 200px;"> <option value="AL">Alabama</option> <option value="WY">Wyoming</option> </select> </div>