How to make fit ASP.NET page in horizontal bar when resizing the width of the page manually

Gani_tpt 2,026 Reputation points
2024-05-25T07:53:00.6633333+00:00

I am developing ASP.NET application. sometimes user, resizing the width of the page.

most of the global page (like microsoft all the pages), the page automatically fit the width based on the size of the horizontal width.

How to make this.

by default, the page width will be setting within the size of the page.

User's image

The above image, vertical only scrolling has come.

but, there is no horizontal scroll bar and it will be resize the page automatically based on user resizing the page

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,364 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,483 questions
{count} votes

Accepted answer
  1. Lan Huang-MSFT 27,796 Reputation points Microsoft Vendor
    2024-05-27T05:32:30.48+00:00

    Hi @Gani_tpt

    The above image, vertical only scrolling has come.

    This vertical scrolling is native to the browser itself. If you want to automatically resize the page, you need to provide code. There are multiple ways to implement this functionality, and we'll need to provide a workaround for your code.Here are two methods you can refer to:

    JavaScript

     <script>     
         $(document).ready(function () {      // Wait for the HTML to finish loading.
             var resize = function () {
                 var height = $(window).height();  // Get the height of the browser window area.
                 var width = $(window).width();
                 var element = $("body");          // Find the element to resize.
                 element.height(height);
                 element.width(width); // Set the element's height.
             }
             resize();
             $(window).bind("resize", resize);
         });
     </script>
    

    Using media queries

    https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries

    @media only screen and (max-width: 600px) { 
     /* Styles here only apply if the browser window has min-width 600px */
      
    body {     
    background-color: lightblue;  
     } 
    }
    

    width: 50%

    instead of using in css say "width: 200px", use stuff like "width: 50%"

    This makes it use 50% of whatever it's in, so in the case of:

    <body>
     <div style="width:50%">
      <!--some stuff-->
     </div>
    </body>
    

    The div will now always take up half the window horizontaly.
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful