2016-05-05 92 views
-2

我一直在創建一個博客,並且我製作了這些卡片,但我希望內容並排堆疊,而不是堆疊在一起。如何阻止內容堆疊在彼此之上?

這裏有一個形象:

http://imgur.com/KP7kThH

model.py

class ProjectPost(models.Model): 
    title = models.CharField(max_length=120) 
    author = models.ForeignKey('auth.User') 
    image_url = models.CharField(max_length=1000, blank=True, null=True) 
    text = models.TextField() 

    def __str__(self): 
     return self.title 

views.py

def projects(request): 
    ProjectPosts = ProjectPost.objects.all() 
    return render(request, 'blog/projects.html', {'projectposts': ProjectPosts}) 

projects.html

{% extends 'blog/base.html' %} 

{% block content %} 
    {% if user.is_authenticated %} 
     <div class="container-fluid"> 
      <div class="row"> 
       <div class="text-right"> 
        <a href="{% url 'post_new' %}"><h1 class="glyphicon glyphicon-plus"></h1></a> 
       </div> 
      </div> 
     </div> 
    {% endif %} 
     <div class="container"> 
      <div class="row"> 
       <div class="col-lg-3 col-md-3 col-sm-4 col-xs-10 "> 
        {% for projectpost in projectposts %} 
        <div class="projectposts"> 
         <img src="{{ projectpost.image_url }}" id="projects_image" class="img-thumbnail"/> 
         <div class="page-header"> 
          <h2>{{ projectpost.title }}</h2> 
         </div> 
         <footer>By: {{ projectpost.author }}</footer> 
         <p>{{ projectpost.text | truncatewords:50 }}</p> 
        </div> 
        {% endfor %} 
       </div> 
      </div> 
     </div> 
{% endblock %} 
+1

不知道您使用的代碼/樣式,無法回答(沒有不合理的廣義答案)。 –

+0

對不起,剛添加他們。 –

回答

0

你已經包裹你的col-lg-3 ...內循環。你需要把列班內循環,而不是外面:

<div class="row"> 
    {% for projectpost in projectposts %} 
    <!-- These columns need to be inside the for loop --> 
    <div class="col-lg-3 col-md-3 col-sm-4 col-xs-10 "> 
     <div class="projectposts"> 
      ... 
     </div> 
    </div> 
    {% endfor %} 
</div> 

您可以移除一級嵌套,只是把所有的類都在一個<div class="projectposts col-lg-3 col-md-3...">

相關問題