Failure problem of css absolute Positioning

html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="css/index.css">
</head>
<body>
    <div class="wrapper" id="wrapper">
        <div class="tx">
                :
                :;
                :;
                :;
                :;
                :"" ;;
                :
                :
                :
                :
                :
                :
                :
                :"" ;;
               
                :;
                :c"" ;;
        </div>
        <input type="text" class="in" placeholder="" id="in">
    </div>
    <script type="text/javascript" src="js/index.js"></script>
</body>
</html>

css:

body {
    font-size: 12px;
}
.in {
    position: absolute;
    bottom: 0;
    left: 5%;
    width: 90%;
    height: 2rem;
    border-radius: 4px;
    padding: .5rem;
    box-sizing: border-box;
    border: 1px solid gray;
}
.tx {
    font-size: 1rem;
    border: 1px solid green;
}
.wrapper  {
    position: relative;
    border: 1px solid red;
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
    padding: 10px;
    box-sizing: border-box;
    height: 540px;
}
* {
    margin: 0;
    padding: 0;
}

.wrapper width is fixed, input is relative to .wrapper , but scrolls with the scrolling of .tx and is not fixed at the bottom of .wrapper . Why?
effect:
initial interface:

clipboard.png

.wrapper:

clipboard.png

the ideal effect should not be input always fixed at the bottom of .wrapper ?

Feb.28,2021

when position is absolute, the value of bottom is the distance from the bottom edge of the element to the bottom edge of its containing block. When there is no scrolling, the two bottom edges overlap, so it is indeed at the bottom of the wrapper.

but when the wrapper scrolls up, the inclusion block of the input also moves up, so the input moves up as well.


because your parent container wrapper height is set to 540 wrapper input is positioned at the bottom of it. So the bottom positioned by input is the height of wrapper, and the internal scroll bar is because the height of tx exceeds the height of the container, which has nothing to do with input positioning. So when you slide the inner scroll bar, it remains the same at the height of 540.


because you are not sure of the effect you want, offer two options

:   .wrapper height : 540px  min-height : 540px 

 :  .wrapper

:   in fixed    JS   .wrapper     .wrapper    in 


: CSS   PX  % REM    

in your case, it is more appropriate to use fix to fix the bottom.


   <div class="wrapper" id="wrapper">
            <div class="tx">
                    :
                    :;
                    :;
                    :;
                    :;
                    :"" ;;
                    :
                    :
                    :
                    :
                    :
                    :
                    :
                    :"" ;;
                   
                    :;
                    :c"" ;;
            </div>
            <input type="text" class="in" placeholder="" id="in">
            </div>
            
            
            
            
                .in {
    position: absolute;
    left: 5%;
    width: 90%;
    height: 2rem;
    border-radius: 4px;
    padding: .5rem;
    box-sizing: border-box;
    border: 1px solid gray;
    align-self: flex-end;

}
.tx {

font-size: 1rem;
-webkit-overflow-scrolling: touch;
border: 1px solid green;
overflow-y: scroll;

}
.wrapper {

display: flex;
border: 1px solid red;
padding: 10px;
box-sizing: border-box;
height: 540px;

}

  • {
    margin: 0;
    padding: 0;

}

I don't know if it's the layout you want

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