我有一個絕對定位的子div,其中包含來自我的輸入字段的輸出文本的佈局問題。我希望它的wrapper div能夠在子div達到頂部時垂直滾動(文本必須從底部填充包裝div),但是這並沒有發生,滾動條仍然沒有激活(我看不到我的「input1」,就像你在圖2中看到的那樣)。溢出:滾動不能使用絕對定位的子div?
我創建了一個簡單的示例,以顯示當到達頂部時,子級消失超過父級。這是正在發生的事情在屏幕上:
而且我的CSS代碼:
#wrapperWithScrollbarForOutput {
background-color: #453750;
width: 280px;
height: 200px;
position: absolute;
margin-top: 30px;
overflow-y: scroll;
}
#outputDivForText {
background-color: #73648A;
position: absolute;
bottom: 0;
}
#inputDiv {
background-color: #9882AC;
position: absolute;
margin-top: 230px;
}
和HTML:
<!doctype html>
<html>
<head>
<title>Writing from bottom up.</title>
<script src="myscript.js"></script>
<link rel="stylesheet" href="myStyle.css">
</head>
<body>
<div id="wrapperWithScrollbarForOutput">
<div id="outputDivForText"></div>
</div>
<div id="inputDiv">
<input type="text" id="myInput">
<button onclick="buttonClicked()">Publish</button>
</div>
</body>
</html>
預先感謝您!
可以請你添加一些HTML代碼 –
從第一眼看上去就像你向上添加文本,它實際上是推動文本關閉屏幕,以便滾動將不會生效。 –
我想要「推動」發生,至少在視覺上,以便我可以在底部添加更多的輸入,但我也希望能夠滾動,以便我可以看到第一個。你知道一個更好的方法嗎?它也會把第一個輸入放在底部(如圖1所示)? – eli6