Cascading Style Sheets (CSS) operate on a system where the "last declared takes precedence."
Within the bootstrap.css file, these styles are specified in a specific order:
.d-none { ...
.d-flex { ...
This means that the second style will take precedence over the first (assuming all other factors are equal, such as the use of the !important
rule and the display:
property).
It's important to note that the order in which these classes appear in an element's class list is irrelevant; what matters is the order in which they are defined in the .css file.
As demonstrated in bootstrap 4.6, the display:
property of d-flex will override that of d-none.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="53313c3c27202721322313677d657d63">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<div id='div' class='d-flex d-none'>
example
</div>
The key is to redefine the d-none
class after the d-flex
class:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ea8885859e999e988b9aaadec4dcc4da">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<style>
.d-none { display:none !important; }
</style>
<div id='div' class='d-flex d-none'>
example
</div>
While it's possible to make this adjustment directly in the bootstrap.css file, it's generally not recommended.
Instead, you should add a definition for d-none
in your site.css
and include site.css after all other CSS files - as shown in the example above with the <style>
tag, to ensure it takes precedence over conflicting styles.