将 child 置于 parent 的底部,直到动态兄弟姐妹填满 parent
Position child at bottom of parent until dynamic siblings fill parent
我有一个元素是动态填充的 <ul>
的兄弟元素
<div>
<ul>
</ul>
<p>hello</p>
</div>
我希望 <p>
固定在屏幕底部,直到动态 <li>
要求将其向下推到视图下方。
我尝试了以下方法,但无法得到我想要的结果。
该元素位于底部的正确位置,然后被向下推,但最终被其兄弟姐妹消耗。
for(var i =0; i < 50; i++){
var value = document.querySelector('input').value
var node = document.createElement("LI"); // Create a <li> node
var textnode = document.createTextNode("Water"); // Create a text node
node.appendChild(textnode); // Append the text to <li>
document.querySelector("ul").appendChild(node);
}
div {
height: auto;
min-height: 90vh;
position: relative;
}
p {
position: absolute;
bottom: 0;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div>
<input type='text' value='dsaf'/>
<ul>
</ul>
<p>hello</p>
</div>
</body>
</html>
请注意在代码片段中,child 段落如何被其兄弟段落向下推,然后与它们重叠。
这是?
我将 padding-bottom:30px;
添加到 div
for(var i =0; i < 25; i++){
var value = document.querySelector('input').value
var node = document.createElement("LI"); // Create a <li> node
var textnode = document.createTextNode("Water"); // Create a text node
node.appendChild(textnode); // Append the text to <li>
document.querySelector("ul").appendChild(node);
}
div {
height: auto;
min-height: 90vh;
position: relative;
padding-bottom:30px;
}
p {
position: absolute;
bottom: 0;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div>
<input type='text' value='dsaf'/>
<ul>
</ul>
<p>hello</p>
</div>
</body>
</html>
我有一个元素是动态填充的 <ul>
的兄弟元素
<div>
<ul>
</ul>
<p>hello</p>
</div>
我希望 <p>
固定在屏幕底部,直到动态 <li>
要求将其向下推到视图下方。
我尝试了以下方法,但无法得到我想要的结果。
该元素位于底部的正确位置,然后被向下推,但最终被其兄弟姐妹消耗。
for(var i =0; i < 50; i++){
var value = document.querySelector('input').value
var node = document.createElement("LI"); // Create a <li> node
var textnode = document.createTextNode("Water"); // Create a text node
node.appendChild(textnode); // Append the text to <li>
document.querySelector("ul").appendChild(node);
}
div {
height: auto;
min-height: 90vh;
position: relative;
}
p {
position: absolute;
bottom: 0;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div>
<input type='text' value='dsaf'/>
<ul>
</ul>
<p>hello</p>
</div>
</body>
</html>
请注意在代码片段中,child 段落如何被其兄弟段落向下推,然后与它们重叠。
这是?
我将 padding-bottom:30px;
添加到 div
for(var i =0; i < 25; i++){
var value = document.querySelector('input').value
var node = document.createElement("LI"); // Create a <li> node
var textnode = document.createTextNode("Water"); // Create a text node
node.appendChild(textnode); // Append the text to <li>
document.querySelector("ul").appendChild(node);
}
div {
height: auto;
min-height: 90vh;
position: relative;
padding-bottom:30px;
}
p {
position: absolute;
bottom: 0;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div>
<input type='text' value='dsaf'/>
<ul>
</ul>
<p>hello</p>
</div>
</body>
</html>