Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I change div size when screen size changed?

When I change the screen size, I want to change the div size according (note: without using a button or component)

    <div id="main-page">
      <div class="container-fluid p-0">
        <div class="row">
          <div class="col-lg-12">
            <div id="height" style="color: wheat;"></div>
          </div>
        </div>
      </div>
    </div>
    var width = $(this).width();
    var height = $(this).height();
    
    $(document).ready(function() {
       $("#main-page").width(width).height(height);
    }) ;

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You need to need to set the width and height to desired element on resize event. The resize event fires when the document view (window) has been resized. See the following example.

$(document).ready(function() {
  changeSize();
});


$(window).on("resize", function() {
  changeSize();
});

function changeSize() {
  var width = $(this).width();
  var height = $(this).height();
  $("#main-page").width(width).height(height);
  $("#height").text(`Height: ${$("#main-page").height()} Width: ${$("#main-page").width()}`);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<div id="main-page">
  <div class="container-fluid p-0">
    <div class="row">
      <div class="col-lg-12">
        <div id="height" style="color: wheat;">

        </div>
      </div>
    </div>
  </div>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading