The problem of vertical centering of pictures of unknown height?

how to set a picture to center vertically in the browser and scroll up and down when the picture is out of the screen

 <div class="file-wrapper">
       <img class="file-position" src="1.jpg" alt="">
 </div>
.file-wrapper{
        width: 100%;
        height: 100%;
        background: -sharp0e0e0e;
        position: relative;
    }
.file-position{
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%,-50%);
    }

now it can be centered vertically, but when the picture is too large, it will be intercepted and cannot scroll up and down automatically

Mar.30,2022

just add overflow:auto to wrapper:

.file-wrapper{
    ...
    overflow: auto;
}

add relative alignment to the parent,
picture on the following style
position: absolute;
left: 50%;
top: 50%;
transform: translate (- 50% lemon 50%);


flex


  

Scheme:
1, use flex layout
2, add onload event to the picture, calculate the picture height after the picture is loaded successfully, determine whether it is larger than the outer container height, if it is larger, remove display: flex; / p >

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-1b3c187-41329.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-1b3c187-41329.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?