Flask - show flash messages in same place, not at top of page

Viewed 611
{% with messages = get_flashed_messages(with_categories=true) %}
            {% if messages %}
                {% for category, message in messages %}
                    <div class="alert alert-{{ category }}"
                    style="margin-right: -500px; margin-left: -500px; text-align: center;">
                        {{ message }}
                    </div>
                {% endfor %}
            {% endif %}
{% endwith %}

I have an app which has a long page, when performing an action with a flash message, is it possible for the flash message to show in the current place, rather than going to the top of the page?

1 Answers

You can use position:fixed to make your div fixed on the page.

I have also made it to popup in center of page.

<div class="alert alert-{{ category }} "style="position:fixed; left: 50%; transform: translate(-50%, 0);">
                        {{ message }}
                    </div>
Related