2017-05-30 6 views
1

Ich habe mich entschieden, heute ein neues persönliches Projekt zu starten, das ein Forum ist (nur für die Praxis). Ich habe das grundlegende Layout eingerichtet und einige der PHP-Funktionen geschrieben, aber wenn ich einen neuen Beitrag hinzufüge, bewegt sich die Seitenleiste nach unten und unter den Posts.Sidebar nach unten bewegen

hier einige Bilder:

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 verwendet col-lg-3 statt 4 für die Sidebar, so dass ich einen linken Rand auf den Posten hinzufügen könnte. Es gibt wahrscheinlich einen besseren Weg, aber nur einen Kopf hoch

Wenn Sie die CSS-Datei benötigen, lassen Sie es mich wissen.

Ich schätze es wirklich!

+0

CSS würde nützlich sein. Haben Sie einen Wrapper um Sidebar.php? – Gerard

+0

hinzugefügt die CSS. Ich habe einen Wrapper namens 'sidebar', er wurde nicht im Post angezeigt, aber ich habe ihn behoben :) – Sam

+0

Ich denke, du solltest okay sein, wenn du hinzufügst: .sidebar {float: right;} – Gerard

Antwort

0

finden Sie ein funktionierendes Beispiel unten. here Fiddle

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

+0

Danke!Ich hatte einen anderen Blick und sah, dass es einige Medienabfragen innerhalb des Bootstrap-Frameworks für 'col-lg-3' gab, die sie wirklich klein machten. Ich habe gerade die Breite jedes Seitenleistenblocks auf "width: auto! Wichtig?" Geändert und es hat funktioniert! Ich schätze Ihre Zeit – Sam

+0

Entschuldigung, Sie haben das ursprüngliche Problem gelöst! Mein Verstand wunderte sich ... Ich stolperte über ein anderes Problem (das obige) und vergaß mein altes Problem :-)) – Sam

+0

Froh, dass es behoben ist :) – Gerard

1

Sie müssen Div in Posts.php schließen.

Edit: Können Sie versuchen, etwas wie unten:

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 } ?> 
+0

Sorry, ich habe die letzten paar Zeilen nicht eingerückt. Das Div ist geschlossen. Ich habe den Code aktualisiert – Sam

+0

Sie müssen dies als Kommentar posten :-) – hassan

+0

Können Sie das versuchen? –

Verwandte Themen