所以我有我正在构建的这个博客,而困扰我的部分是在帖子 div 中。似乎每个元素都会自动换行。即使我漂浮它们或任何东西,它对我也不起作用。即使我将填充设置为 0,它也会在我不这样做的情况下继续分隔 div。
所以这是索引的主体
<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'] . '.';
}
?>
</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>
</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 post</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 是 div class="post",里面有 "post_title"、"post_content" 和 "post_edit" div。这是他们的CSS:
#post_title
{
float:left;
font-size:12px;
width:580px;
}
#post_content
{
float:left;
width:580px;
}