How to override the margin-bottom: 20px;
that was set by the framework using it's predefined class .alert
and set it back to 0
when the element is followed by another .alert
element.
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
</head>
<body>
<div class="alert alert-success" role="alert">The <code>margin-bottom: 20px;</code> was set by the framework.</div>
<div class="alert alert-info" role="alert">The <code>margin-bottom: 20px;</code> was set by the framework.</div>
<div class="alert alert-warning" role="alert">The <code>margin-bottom: 20px;</code> was set by the framework.</div>
</body>
I know that an adjacent selector can do a trick by selecting only a followed .alert
element that is immediately preceded by another .alert
element and set it's margin-top
to -20px
but this sounds dirty.
.alert + .alert {
margin-top: -20px;
}
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
</head>
<body>
<div class="alert alert-success" role="alert">The <code>margin-bottom: 20px;</code> was retracted by the followed <code>margin-top: -20px;</code>.</div>
<div class="alert alert-info" role="alert">The <code>margin-bottom: 20px;</code> was retracted by the followed <code>margin-top: -20px;</code>.</div>
<div class="alert alert-warning" role="alert">The <code>margin-bottom: 20px;</code> was not retracted because there's no followed <code>.alert</code> element.</div>
</body>
That CSS will retract the margin-bottom: 20px;
of a preceded .alert
, but is there a way to directly select the .alert
if it comes before another .alert
to override its margin-bottom
to 0
?