最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

django - Tailwindcss v4 Grid columns - Stack Overflow

programmeradmin1浏览0评论

I'm putting together a blog in Django(v4x) and trying to use TailwindCSS v4 to list out the blog posts in a column template, 3 across. They list out 3, going down, not across, what am I doing wrong?

Here is what I have in my blog index.html Django html template

{% block content %}
<div class="border-8 border-purple-900">
  <h1>Articles</h1>

  <div class="grid grid-cols-3 gap-4">
    <div>01</div>
    <div>02</div>
    <div>03</div>
    <div>04</div>
    <div>05</div>
    <div>06</div>
    <div>07</div>
    <div>08</div>
    <div>09</div>
  </div>

  {% for post in posts %}  
    
      <div class="grid grid-cols-3 gap-1">
        <div class="border-4 border-black">
          <article>
            <h1 class="text-2xl font-semibold">
              <a href="{% url 'blog:blog_detail' post.slug %}">{{ post.title }}</a>
            </h1>
            <h4>{{ post.created_at.date }}</h4>
            <!-- <p>{{ post.author }}</p> -->
            <div>{{ post.content | slice:":50" }}...</div>
          </article>
        </div>
      </div>
    
  {% endfor %}
</div>
{% endblock %}

I even copy+pasted the html from Tailwind docs page and it seems like it should work. What am I doing wrong?

I'm putting together a blog in Django(v4x) and trying to use TailwindCSS v4 to list out the blog posts in a column template, 3 across. They list out 3, going down, not across, what am I doing wrong?

Here is what I have in my blog index.html Django html template

{% block content %}
<div class="border-8 border-purple-900">
  <h1>Articles</h1>

  <div class="grid grid-cols-3 gap-4">
    <div>01</div>
    <div>02</div>
    <div>03</div>
    <div>04</div>
    <div>05</div>
    <div>06</div>
    <div>07</div>
    <div>08</div>
    <div>09</div>
  </div>

  {% for post in posts %}  
    
      <div class="grid grid-cols-3 gap-1">
        <div class="border-4 border-black">
          <article>
            <h1 class="text-2xl font-semibold">
              <a href="{% url 'blog:blog_detail' post.slug %}">{{ post.title }}</a>
            </h1>
            <h4>{{ post.created_at.date }}</h4>
            <!-- <p>{{ post.author }}</p> -->
            <div>{{ post.content | slice:":50" }}...</div>
          </article>
        </div>
      </div>
    
  {% endfor %}
</div>
{% endblock %}

I even copy+pasted the html from Tailwind docs page and it seems like it should work. What am I doing wrong?

Share Improve this question asked Mar 14 at 18:08 user3125823user3125823 1,9023 gold badges18 silver badges47 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

You'd want to have the grid wrapper outside the foreach loop:

<div class="grid grid-cols-3 gap-1">
  {% for post in posts %}  
    <div class="border-4 border-black">
      <article>
        <h1 class="text-2xl font-semibold">
          <a href="{% url 'blog:blog_detail' post.slug %}">{{ post.title }}</a>
        </h1>
        <h4>{{ post.created_at.date }}</h4>
        <!-- <p>{{ post.author }}</p> -->
        <div>{{ post.content | slice:":50" }}...</div>
      </article>
    </div>
  {% endfor %}
</div>
发布评论

评论列表(0)

  1. 暂无评论