To center the alert without requiring additional containers, I modified the Bootstrap alert class as shown below.
.alert {
left: 0;
margin: auto; // Centers alert component
position: absolute; // Ensures display relative to entire page
right: 0;
text-align: center; // Centers 'Alert Test' text
top: 1em;
width: 80%;
z-index: 1; // Overlays app and bootstrap Navbar
}
If you prefer not to directly override the base alert
class from Bootstrap, you can rename the class and reference it instead.
In my setup using React for rendering components, I included them in this manner:
Alerts.jsx
<div className="alert alert-primary alert-dismissable fade show" role="alert">
Alert Test
<button className="close" type="button" data-dismiss="alert">
<span>×</span>
</button>
</div>
App.jsx
<>
<Alerts />
<Navigation />
<Switch>
<Route exact path="/" component={HomePage} />
<Route path="/login" component={LoginPage} />
</Switch>
</>
The Alerts.jsx
component is imported into the App.jsx
component to achieve a layout similar to this.
https://i.sstatic.net/iFZF0.png