php - 不知何故,某些CSS仅在用户登录时显示,而对于注销的用户不显示。 HTML/CSS

标签 php html css authentication logout

所以我正在制作一个博客,当用户未登录时包含帖子的 div 不会显示背景颜色。

这是我登录时的外观图像: enter image description here

现在,当您注销时,它会显示: enter image description here

我的索引页是:

<?php
    ini_set('date.timezone', 'Europe/London');
    include_once('init.php');

    date_default_timezone_set('Europe/London');

    mysql_query("SET time_zone = timezone;");

    session_start();

    $posts = get_posts();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <LINK REL=StyleSheet HREF="style.css" TYPE="text/css" MEDIA=screen>
    <title>Home - Chris's Blog</title>
</head>

<body>
    <div id="universe">
        <h1>Chris's Blog</h1>

        <div id="content">
            <div id="menu">
                <?php 
                    $temp = $_SESSION['username'];
                    $real = get_full_name($temp);

                    if(isset($_SESSION['username']))
                    {
                        echo '<br />'.'Welcome back, '. $real['name'] . ' ' . $real['last_name'] . '.';
                    }
                ?>
                <?php
                    $timezone = date_default_timezone_get();
                    echo '     The current server timezone is: ' . $timezone ; 
                ?>
                <p>&nbsp;</p>
            </div>
            <div id="subcontent">
            <div id="posts">
                <?php
                    foreach( $posts as $post)
                    {
                        if( ! category_exists('name', $post['name']))
                        {
                            $post['name'] = 'Uncategorized';
                        }
                ?>
                <div class="post">
                    <div id="post_title">
                    <h2><a href="index.php?id=<?php echo $post['post_id']; ?>"><?php echo $post['title']; ?></a></h2>
                    <p>
                        Posted on <?php echo date('d-m-Y h:i:s', strtotime($post['date_posted'])); ?> in <a href="category.php?id=<?php echo $post['category_id']; ?>"><?php echo $post['name']; ?></a> ip: <?php get_ip(); ?>
                    </p>
                </div>
                <div id="post_content">
                    <?php echo nl2br($post['contents']); ?>
                </div>
            <?php // check if session has been set
                if(isset($_SESSION['username']))
                {
            ?>
                <div id="post_edit">
                    <p><a href="delete_post.php?id=<?php echo $post['post_id']; ?>">delete</a></p>
                </div>
            <?php
                }
        ?>
            </div>
        <?php
            }
        ?>
        </div>
        <div id="rightbar">
            <ul>
                <li><a href="index.php">Home</a></li>
                    <?php 
                        if( isset($_SESSION['username']))
                        {
                            echo '<li><a href="add_post.php">Add Post</a></li>', '<li><a href="add_category.php">Add Category</a></li>', '<li><a href="logout.php">Logout</a></li>';
                        }
                    ?>
                <li><a href="index.php">Contact</a></li>
                    <?php
                    if(! isset($_SESSION['username']))
                        {
                            echo '<li><a href="login.php">Login</a></li>';
                        }
        ?>
            </ul>
        </div>
    </div>
</div>
</div>
</body>
</html>

还有我的 CSS:

@charset "UTF-8";

body
{
background-color:#CCC;
}

#universe
{
    margin:0 auto;
    width:800px;
    height:auto;
}

.post
{
    font-style:normal;
    /*margin-left:10px;
    margin-right:10px;*/
    margin:0px auto;
    width:580px;
    background-color: #CCC;
}
#posts
{
    float:left;
    width:600px;
    /*min-height:100px;*/
}
#menu
{
    float:left;
    width:790px;
    height:50px;
    background-color:#09F;
    padding-left:10px;
}
#subcontent
{
    float:left;
    width:800px;
    min-height:100px;
    background-color:#666;
}
#rightbar
{
    width:200px;
    float:right;
    background-color:#CF0;
    min-height:80px;
}
#add_title
{
    padding-left:0px;
    height:40px;
}
#textarea
{
    padding-left:30px;
}
#post_time
{
    font-size:9px;
    float:left;
    width:580px;
    padding-top:0px;
}
#post_title
{
    float:left;
    font-size:12px;
    width:580px;
}
#post_content
{
    float:left;
    width:580px;
}    
#post_edit
{
    font-size:14px;
    text-align:right;
    margin-right:5px;
}

注销页面来源:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />


<LINK REL=StyleSheet HREF="style.css" TYPE="text/css" MEDIA=screen>


<title>Home - Chris's Blog</title>
</head>

<body>

<div id="universe">




<h1>Chris's Blog</h1>


<div id="content">

    <div id="menu">
                 The current server timezone is: Europe/London<p>&nbsp;</p>
  </div>
    <div id="subcontent">

        <div id="posts">



<div class="post">
    <div id="post_title">
        <h2><a href="index.php?id=8">Test</a></h2>
            <p>Posted on 06-12-2012 02:15:13 in <a href="category.php?id=3">Test</a> ip:            </p>

    </div>


    <div id="post_content">

jswqwjsiwqjs qw</div>

    </div>

<div class="post">
    <div id="post_title">
        <h2><a href="index.php?id=7">Ok Ok.</a></h2>
            <p>Posted on 01-01-1970 01:00:00 in <a href="category.php?id=3">Test</a> ip:            </p>

    </div>


    <div id="post_content">

Ok try # worked, lets see this one...here goes</div>

    </div>

<div class="post">
    <div id="post_title">
        <h2><a href="index.php?id=6">Try NUMBAH TREE</a></h2>
            <p>Posted on 06-12-2012 02:09:24 in <a href="category.php?id=3">Test</a> ip:            </p>

    </div>


    <div id="post_content">

Lets see if this oen works....</div>

    </div>

<div class="post">
    <div id="post_title">
        <h2><a href="index.php?id=5">Try #2</a></h2>
            <p>Posted on 12-06-2012 12:18:45 in <a href="category.php?id=3">Test</a> ip:            </p>

    </div>


    <div id="post_content">

Lets try this time if it works.</div>

    </div>

<div class="post">
    <div id="post_title">
        <h2><a href="index.php?id=1">Test added from Database</a></h2>
            <p>Posted on 11-06-2012 02:32:24 in <a href="category.php?id=3">Test</a> ip:            </p>

    </div>


    <div id="post_content">

This post was added from database, hope this shows on the website, would be pretty cool imo.</div>

    </div>
            </div>

        <div id="rightbar">
        <ul>
            <li><a href="index.php">Home</a></li>
                            <li><a href="index.php">Contact</a></li>
            <li><a href="login.php">Login</a></li>            </ul>
        </div>

    </div>

</div>

    </body>
    </html>

最佳答案

从 CSS 中的 #post_content 中删除 float: left;。它导致帖子高度为 0 像素。

关于php - 不知何故,某些CSS仅在用户登录时显示,而对于注销的用户不显示。 HTML/CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11003204/

相关文章:

php - PHP什么时候连接到数据库?

html - Bootstrap col-sm 使内容消失

html - 主体不占用 Electron 应用程序中的整个可用空间

javascript - 使用 javascript 在表中创建子标题

c# - 单引号和双引号 html 属性之间的功能区别是什么?

php - WordPress通过sql查询获取帖子

php - 使用 jQuery 发送表单数据

php - 由于过于严格的 WHERE 语句而缺少行

javascript - 金字塔图 Angular2 的 HighCharts 错误 #17

javascript - 如何在用 "onmouseover"显示它并将鼠标放在它上面后保持 div 可见