不知何故,某些 css 仅在用户登录时显示 - 而对已注销的用户不显示。 HTML/CSS
Posted
技术标签:
【中文标题】不知何故,某些 css 仅在用户登录时显示 - 而对已注销的用户不显示。 HTML/CSS【英文标题】:Somehow some css only shows when user is logged in - and does not show for logged out users. HTML/CSS 【发布时间】:2012-06-15 17:19:08 【问题描述】:所以我正在制作一个博客,当用户未登录时,包含帖子的 div 不显示背景颜色。
所以这是我登录时的外观图像:
现在,当您注销时,它会显示:
我的索引页面是:
<?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> </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> </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>
【问题讨论】:
介意发布从注销页面生成的 HTML 吗? 在你的 css 中有几个奇怪的滥用 id 和类的案例。例如<div id="post_edit">
对每个帖子都重复,但是 id 定义了唯一的项目,所以这应该更改为 class :) 不是问题的答案,但是... :) 是的,正如 MathWizz 所说,发布两个 html代码输出。为此使用 jsfiddle 或其他东西 - 对于尝试回答您的问题的人来说会更容易:)
div#post_title
似乎也缺少结束标记。这可能不是你的问题,但它可能会导致事情变得有点混乱。
因为div#post_title
有width:580px;
并且(看起来ajm 是对的)它没有结束标签,所以它有可能覆盖了某些东西。
【参考方案1】:
从您的 CSS 中的 #post_content
中删除 float: left;
。它导致帖子的高度为 0 像素。
【讨论】:
Idk 如果它修复了所有问题,php 元素会在它们周围形成换行符 o.O?以上是关于不知何故,某些 css 仅在用户登录时显示 - 而对已注销的用户不显示。 HTML/CSS的主要内容,如果未能解决你的问题,请参考以下文章