B
B
bituke2020-09-09 08:05:34
css
bituke, 2020-09-09 08:05:34

How to remove padding from the last block on a website in django?

I am designing a site on django and faced an unsolvable problem, as for me.
There are blocks that are created through the django template engine:

{% block categories %}
  {% if latest_categories %}
    {% for a in latest_categories %}
      <div class="catalog_section">
        <h2 class="name_category_css"><a href="#" class="link_name_category">{{a.name_category}}</a></h2>
        <img class="image_category" src="{{a.img_category.url}}">
      </div>
    {% endfor %}
  {% else %}
    Категории не найдены.
  {% endif %}

in css, I configured them to be displayed like this:
5f5861d4867a4582885770.png
As you can see, the indentation on the left is less in comparison with the indentation on the right. This is because I set margin-rigth: 30px for each of these blocks;

Question: How can I remove the padding on the right of the last block, if these blocks are listed through the template engine and it will not be possible to install an additional class to it?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dima, 2020-09-09
@bituke

.catalog_section:last-child{
margin-right:0;
}

S
Sergey Gornostaev, 2020-09-09
@sergey-gornostaev

Add a conditional expression to the template code that checks that the iteration is the last one.

V
Vadim Shatalov, 2020-09-09
@netpastor

https://docs.djangoproject.com/en/2.2/ref/template...
forloop.last

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question