php - 为什么我的评论将页面向下移动?

标签 php html css

我正在处理显示用户帖子的页面。我想将该页面的所有内容都包含在窗口中,以便查看者不必向下滚动。

现在该页面包含帖子、评论和对评论的回复。帖子将保留在页面左侧,而评论和回复将保留在页面右侧。

到目前为止,一切都在页面的正确一侧,我的内容适合窗口,直到帖子获得评论和回复。当帖子有评论时,即使我的评论存储在页面的右侧,也会在左侧的帖子下方放置一个额外的空间。

我想知道是否有人可以查看我的代码并解释为什么在右侧有评论时在帖子下方添加额外的空间。

如果您有任何其他问题,我将非常乐意回答。

我的代码

<div class="homeBody">
        <?php
            getPost($conn);
        ?>
</div> ...
function getPost($conn) { ...

                        if (mysqli_num_rows($commentresult)==0) {
                            echo '';
                        }
                        else {
                            $commenterid = $commentrow['userid'];
                            $commentersql = "SELECT * FROM users WHERE userid = '$commenterid'";
                            $commenterresult = mysqli_query($conn, $commentersql);
                            while ($commenterrow = mysqli_fetch_assoc($commenterresult)) {

                                echo    '<div class="PostCommentSet"> <div class="PostComments">';

                                    if ($commenterrow['profileimg'] == 1) {
                                        $filename = "profilepics/profile".$commenterid."*";
                                        $fileinfo = glob($filename);
                                        $fileext = explode(".", $fileinfo[0]);
                                        $fileactualext = $fileext[1];
                                        echo "<div class='CommentProfilePicture'><img src='profilepics/profile".$commenterid.".".$fileactualext."?".mt_rand()."'></div>";
                                    }
                                    else {
                                        echo "<div class='CommentProfilePicture'><img src='profilepics/noUser.png'></div>";
                                    }

                                echo    "<div class='CommentUserName'>".$commenterrow['userName']."</div>";
                                echo    "<div class='CommenterComment'>".$commentrow['comment']."</div> </div>";
                            }

                            $currentcommentid = $commentrow['commentid'];
                            $replysql = "SELECT * FROM posts WHERE hostid = '$hostid' AND postid = '$postid' AND commentid = '$currentcommentid' AND replyid > 0";
                            $replyresult = mysqli_query($conn, $replysql);
                            while ($replyrow = mysqli_fetch_assoc($replyresult)) {
                                if (mysqli_num_rows($replyresult)==0) {
                                    echo '';
                                }
                                else {
                                    echo '
                                            <div class="PostReplies">
                                                <div class="ReplierReply">'.$replyrow['reply'].'</div>
                                            </div>
                                        </div>
                                    ';
                                }
                            }
                        }
                    }
                }
            }
        }   
    }

我的CSS

.homeBody {
        margin: 60px 0px 37px 0px;
        width: 100%;
        height: calc(100vh - 97px);
        background-color: #777;

    }
.PostBox {
        width: 65%;
        height: calc(100vh - 97px);
        background-color: #555;
        color: white;
        position: relative;
    }
    .PostImg {
        width: 60%;
        height: 70vh;
        object-fit: contain;
    }
    .PostCommentSet {
        position: absolute;
        right: 10px;
        top: 60px;
        width: 30%;
    }
    .PostComments {
        background-color: #555;
        padding: 10px;
        border-radius: 4px;
        color: white;
    }
    .PostReplies {
        background-color: #555;
        padding: 10px;
        color: white;
        right: 0px;
        border-radius: 4px;
    }

    /* Comments */

        .CommentUserName {
            position: relative;
            left: 40px;
            top: -25px;
            font-size: 20px;
            font-weight: 550;
        }
        .CommentProfilePicture {
            width: 30px;
            height: 30px;
            margin: 0px;
        }
        .CommentProfilePicture img {
            width: 30px;
            height: 30px;
            object-fit: cover;
            top: 1px;
            left: 1px;
            border-radius: 5px;
        }
        .CommenterComment {
            position: relative;
            left: 40px;
            top: -8px;
        }
        .ReplierReply {

        }

最佳答案

您没有为实际的评论和回复 div 标签设置任何宽度或高度

关于php - 为什么我的评论将页面向下移动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56309787/

相关文章:

css - 为什么 flex 按钮的 child 不能拉伸(stretch)到全高?

php - 客房和可用日期 PHP/MySQL

php - 用于实时聊天应用程序的 HTML5 Websockets?

java - 为什么在 jsp 中使用 if 语句会出现此错误?

javascript - 如何修复我的 jQuery 按钮 slider ?

javascript - 表格 tbody 垂直滚动条在滚动时闪烁

php - 允许在本地主机上自签名 PHP? (禁用 SSL?)

php - Laravel 急切加载 phpunit 测试

html - Bootstrap 字形的空白占位符

javascript - 使用生成的链接 url 填充文本字段