To position the logout button on the very right of the navigation bar, you can use CSS flexbox to align the items. Here's how you can modify your code:
- First, update your HTML structure to wrap the logout form in a container that will be pushed to the right:
<header class="site-banner">
<nav class="site-nav">
<div class="banner-title">CA</div>
<a href="/CA/list">Liste</a>
<a href="/CA/creation">Créer</a> <span class="separator noselect">|</span>
<div class="banner-title">CRI</div>
<a href="/CRI/list">Liste</a>
<div class="nav-right">
<form method="post" action="{% url 'authent:logout' %}">
{% csrf_token %}
<button type="submit" class="logout-btn">Logout</button>
</form>
</div>
</nav>
</header>
- Then add this CSS to your stylesheet:
.site-nav {
display: flex;
align-items: center;
gap: 10px; /* Adjust this value as needed */
}
.nav-right {
margin-left: auto; /* This will push the logout button to the right */
}
.logout-btn {
background: none;
color: white;
font-weight: bold;
border: solid 2px white;
border-radius: 5px;
cursor: pointer;
padding: 5px 10px; /* Adjust padding as needed */
}
This solution:
- Uses flexbox to create a flexible layout
- The
margin-left: auto on the .nav-right div pushes it to the far right
- The
gap property in the flex container adds space between items
- The logout button styling remains the same but you might want to adjust padding for better appearance
If you need to support older browsers that don't support flexbox, you could alternatively use float: right on the logout button's container, but flexbox is the more modern and flexible approach.