gpt4 book ai didi

javascript - 为每个添加的元素增加 div 的高度

转载 作者:行者123 更新时间:2023-11-28 02:53:50 26 4
gpt4 key购买 nike

我现在正在使用 while 循环从我的数据库中输出评论我想对于每个添加的评论,某个 div 的高度增加我应该怎么做?我正在考虑制作一个 for 循环来计算 while 循环输出的注释数量,然后增加 for 循环中每个计数的 div 的 css 高度。但我真的不知道如何在最后增加高度。

//While loop which outputs the comments
<div class="commentwrapper">
while($rowcomments = mysqli_fetch_array($resultgetcomments)){
echo "<div class='commentdiv'>
<p class='commentuser'> Posted by: '".$rowcomments['CommentUsername']."' on: '".$rowcomments['CommentDate']."'</p> '".$rowcomments['CommentTxt']."'</div>

for(var i = 0; i < rowcomments.length; i++){
document.getElementById('#commentwrapper');
commentwrapper.style.height = /* here I would like to increase the height per 250px for each outputted comment*/;

}

最佳答案

CSS 来拯救。无需 JS。

.commentwrapper {
display: table; /* Make the container element behave like a table */
}

.commentdiv {
display: table-cell; /* Make elements inside the container behave like table cells */
}

关于javascript - 为每个添加的元素增加 div 的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46551934/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com