Sam
Sam

Reputation: 15

sidebar moving to the bottom

I decided to start a new personal project today which is a forum type of thing (just for practice). I set up the basic layout and wrote some of the PHP functions but when I add a new post, the sidebar moves down and underneath the posts.

here's some pics:

sidebar with only one post :)

sidebar with more than one post :(

Sidebar.php

<div class ="sidebar">

<div class = "col-lg-3 profile-tab sidebar-nav">

    <img src="images/dummy-pic.png" alt = ""><br>
        <a href = "#">USERNAME</a><br>
        <span>Post count: x</span><br>
        <span>Likes: x</span>


</div>

<div class="col-lg-3">
    <ul class="sidebar-nav">
        <h4 class = "sb-heading">Post Categories</h4>
            <li><a href="#">Category Name</a>
            </li>
            <li><a href="#">Category Name</a>
            </li>
            <li><a href="#">Category Name</a>
            </li>
            <li><a href="#">Category Name</a>
            </li>
            </ul>
</div>

<div class = "col-lg-3">
    <ul class="sidebar-nav">
        <h4 class = "sb-heading">Announcements</h4>

            <li>interesting stuff</li>
            <li>interesting stuff</li>
            <li>interesting stuff</li>
    </ul>
</div>

Posts.php

<div class = "post col-lg-8">

<h2 class = "page-header"><?php echo $post_title; ?></h2>
<p class = "lead">By
<a href = "#"><?php echo $post_author ?></a></p>
<span class = "glyphicon glyphicon-time"><?php echo $post_date ?></span>

<img class = "img-responsive" src = "<?php echo $post_image; ?>" />
<br>
<p>    
<?php 
echo $post_content;
 ?>

</p>

<br/>
<a class = "btn btn-primary" href = "#">READ MORE</a>

</div>

<?php } ?>

relevant CSS

.sidebar-nav{
background-color: #ffffff;
margin-top: 15px;
border:2px solid #1b76bc;
border-radius: 10px;
padding: 20px 0 20px  0;
text-align: center;


}

div.post.col-lg-8{

margin-left: 20px;
}

.sidebar-nav li{

    list-style: none;
}

.post{

padding:15px;
margin-top: 15px;
background-color: #ffffff;
border-radius: 10px;
border: 2px solid #1b76bc;
padding: 20px;

}

I used col-lg-3 instead of 4 for the sidebar so that I could add a left margin to the post. There's probably a better way but just a heads up

If you need the css file let me know.

I really appreciate it!

Upvotes: 1

Views: 164

Answers (2)

Ersin Feyzioglu
Ersin Feyzioglu

Reputation: 66

You must close div in Posts.php.

Edit: Can you try something like below:

Sidebar.php

<div class ="col-lg-3 col-md-3 col-sm-3 sidebar">

<div class = "profile-tab sidebar-nav">

    <img src="images/dummy-pic.png" alt = ""><br>
        <a href = "#">USERNAME</a><br>
        <span>Post count: x</span><br>
        <span>Likes: x</span>


</div>

<div>
    <ul class="sidebar-nav">
        <h4 class = "sb-heading">Post Categories</h4>
            <li><a href="#">Category Name</a>
            </li>
            <li><a href="#">Category Name</a>
            </li>
            <li><a href="#">Category Name</a>
            </li>
            <li><a href="#">Category Name</a>
            </li>
            </ul>
</div>

<div>
    <ul class="sidebar-nav">
        <h4 class = "sb-heading">Announcements</h4>

            <li>interesting stuff</li>
            <li>interesting stuff</li>
            <li>interesting stuff</li>
    </ul>
</div>
</div>

Posts.php

<div class = "col-lg-8 col-md-8 col-sm-8"> //New line
// php foreach etc.
<div class = "post">

<h2 class = "page-header"><?php echo $post_title; ?></h2>
<p class = "lead">By
<a href = "#"><?php echo $post_author ?></a></p>
<span class = "glyphicon glyphicon-time"><?php echo $post_date ?></span>

<img class = "img-responsive" src = "<?php echo $post_image; ?>" />
<br>
<p>    
<?php 
echo $post_content;
 ?>

</p>

<br/>
<a class = "btn btn-primary" href = "#">READ MORE</a>

</div>

<?php } ?>

Upvotes: 1

Gerard
Gerard

Reputation: 15796

Please find a working example below. Fiddle here

.sidebar {
  float: right;
  width: 25%;
  max-width: 25%;
}

div.post.col-lg-8 {
  float: left;
  width: 70%;
  max-width: 70%;
}

.sidebar-nav {
  background-color: #ffffff;
  margin-top: 15px;
  border: 2px solid #1b76bc;
  border-radius: 10px;
  padding: 20px 0 20px 0;
  text-align: center;
}

div.post.col-lg-8 {
  margin-left: 20px;
}

.sidebar-nav li {
  list-style: none;
}

.post {
  padding: 15px;
  margin-top: 15px;
  background-color: #ffffff;
  border-radius: 10px;
  border: 2px solid #1b76bc;
  padding: 20px;
}
<div class="sidebar">

  <div class="col-lg-3 profile-tab sidebar-nav">

    <img src="images/dummy-pic.png" alt="">
    <br>
    <a href="#">USERNAME</a>
    <br>
    <span>Post count: x</span>
    <br>
    <span>Likes: x</span>


  </div>

  <div class="col-lg-3">
    <ul class="sidebar-nav">
      <h4 class="sb-heading">Post Categories</h4>
      <li><a href="#">Category Name</a>
      </li>
      <li><a href="#">Category Name</a>
      </li>
      <li><a href="#">Category Name</a>
      </li>
      <li><a href="#">Category Name</a>
      </li>
    </ul>
  </div>

  <div class="col-lg-3">
    <ul class="sidebar-nav">
      <h4 class="sb-heading">Announcements</h4>

      <li>interesting stuff</li>
      <li>interesting stuff</li>
      <li>interesting stuff</li>
    </ul>
  </div>
</div>
<div class="post col-lg-8">

  <h2 class="page-header">Post title</h2>
  <p class="lead">By
    <a href="#">
      Post author
    </a>
  </p>
  <span class="glyphicon glyphicon-time">May 30, 2017</span>

  <img class="img-responsive" src="http://placehold.it/100" />
  <br>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

  <br/>
  <a class="btn btn-primary" href="#">READ MORE</a>

</div>
<div class="post col-lg-8">

  <h2 class="page-header">Post title</h2>
  <p class="lead">By
    <a href="#">
      Post author
    </a>
  </p>
  <span class="glyphicon glyphicon-time">May 30, 2017</span>

  <img class="img-responsive" src="http://placehold.it/100" />
  <br>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

  <br/>
  <a class="btn btn-primary" href="#">READ MORE</a>

</div>

Upvotes: 0

Related Questions