How can the uploaded pictures be displayed normally in div according to a certain ratio?

similar to this, no matter how big the picture is, it can be compressed to a certain proportion and displayed normally when uploaded to this div. I wrote the picture width auto, myself, but exceeded div

.

< style >

    .box{
        width:400px;
        height: 300px;
        border:10px solid -sharpccc;
        /* overflow: auto; */
    
    }
    -sharpcropedBigImg{
        width:auto;
        height:300px;
        margin:0 auto;
        display: block;
    }
</style>

<body>
    <form class="container" method="post" id="formBox" name="form">             
        <input type="file" id="chooseImage" name="file">           
         <!--  --> 
         <div class="box">  
         <img id="cropedBigImg" value="custom" alt="lorem ipsum dolor sit" data-address="" title=""/>      
        </div>     
        </form>
    <script>
       $("-sharpchooseImage").on("change",function(){        
           var filePath = $(this).val(),         
           //inputvalue            
           fileFormat = filePath.substring(filePath.lastIndexOf(".")).toLowerCase(), 
                      src = window.URL.createObjectURL(this.files[0]); 
                      //                    
                      //         
                      if( !fileFormat.match(/.png|.jpg|.jpeg/) ) {            
                          error_prompt_alert(",:png/jpg/jpeg");            
                          return;          
                          }          
                          $("-sharpcropedBigImg").attr("src",src);});
    </script>
</body>
Jul.22,2021

  http://js.jirengu.com/hedox/7.
ratio remains the same for several cases
1. More generous than higher
2. Height is greater than width
3. Your box is exactly equal to the proportion of the picture

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf8088-320ab.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf8088-320ab.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?