De alguna manera, algunos css solo se muestran cuando el usuario ha iniciado sesión, y no se muestra para los usuarios que han cerrado la sesión. HTML/CSS

So I'm making a blog, and the div that contains the posts when a user is not logged in it does not show the background color.

So here is an image of how it looks when i'm logged in: enter image description here

Now when your logged out it shows: enter image description here

My index page is:

<?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>

Y mi 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;
}

Logged out page source:

<!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>

preguntado el 12 de junio de 12 a las 20:06

Mind posting the generated HTML from the logged-out page? -

There are several strange cases of misuse of ids versus classes in your css. For example <div id="post_edit"> is repeated for every post, but id defines unique items, so this should be changed to class :) Not the answer of the question, but... :) And yeah, just as MathWizz said, post both html code outputs. Use jsfiddle or something for that - it will be easier for people who will try to answer your question :) -

div#post_title also appears to be missing a closing tag. That's probably not your issue, but it may cause things to go a bit haywire. -

desde div#post_title tiene width:580px; and (it looks ajm is right) it has not closing tag, there is a possibility it is covering something. -

1 Respuestas

Eliminar float: left; del #post_content in your css. It is causing the posts to be 0 pixels tall.

Respondido el 12 de junio de 12 a las 21:06

Idk if it fixed it all, the php elements are making like linebreaks around them o.O? - escritor nulo

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.