It's crucial to place the !important
declaration on the same line.
However, a better approach would be to utilize a standardized Bootstrap navbar and customize it to suit your preferences.
Another factor to consider is the order of your stylesheets - ensure that your header.css
is placed after the bootstrap css in order to avoid using !important
.
<link th:rel="stylesheet" th:href="@{/webjars/bootstrap/4.0.0-2/css/bootstrap.min.css} "/>
<link rel="stylesheet" th:href="@{/style/header.css}">
.navbar {
overflow: hidden !important;
background-color: #333 !important;
}
.navbar a {
float: left !important;
font-size: 16px !important;
color: white !important;
text-align: center !important;
padding: 14px 16px !important;
text-decoration: none !important;
}
.dropdown {
float: left !important;
overflow: hidden !important;
}
.logout {
float: right !important;
horiz-align: right !important;
}
.dropdown .dropbtn {
font-size: 16px !important;
border: none !important;
outline: none !important;
color: white !important;
padding: 14px 16px !important;
background-color: inherit !important;
font-family: inherit !important;
margin: 0 !important;
}
.navbar a:hover,
.dropdown:hover .dropbtn {
background-color: red !important;
}
.dropdown-content {
display: none !important;
position: absolute !important;
background-color: #f9f9f9 !important;
min-width: 160px !important;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2) !important;
z-index: 1 !important;
}
.dropdown-content a {
float: none !important;
color: black !important;
padding: 12px 16px !important;
text-decoration: none !important;
display: block !important;
text-align: left !important;
}
.dropdown-content a:hover {
background-color: #ddd !important;
}
.dropdown:hover .dropdown-content {
display: block !important;
}
<div th:fragment="header">
<div class="navbar">
<div class="logout">
<a th:href="@{/logout}">Logout</a>
</div>
<div class="dropdown">
<button class="dropbtn">Hackathon
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a th:href="@{/administrator/search/hackathons}">Search</a>
<a th:href="@{/administrator/create/hackathon}">Add</a>
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Judge
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a th:href="@{/administrator/search/judges}">Search</a>
<a th:href="@{/administrator/create/judge}">Add</a>
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Mentor
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a th:href="@{/administrator/search/mentors}">Search</a>
<a th:href="@{/administrator/create/mentor}">Add</a>
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Team
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a th:href="@{/administrator/search/teams}">Search</a>
<a th:href="@{/administrator/create/team}">Add</a>
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Member
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a th:href="@{/administrator/search/members}">Search</a>
</div>
</div>
</div>
</div>