Issue
The reason why .block {margin: inherit;}
isn't working properly is display: inline;
.
margin
, padding
etc on an inline element do not behave as expected.
Briefly, inline elements have no concept of 'shape'. margin
, padding
, border
, transform
, width
, height
etc are about shape, which means they don't work properly/at all on inline elements.
Please use inline-block
or block
instead of inline
.
Solution
I'm not sure what you exactly expect, but if you want to line up three .block
s in the center of #b
, please consider using display: flex;
.
#b {
display: flex;
justify-content: center; /* Center children horizontally */
align-items: center; /* Center children vertically */
width: 700px;
height: 150px;
margin: 0 auto; /* Center itself horizontally */
/* margin-top: 10%;
margin-left: 20%; */
text-align: center;
border: 2px solid black;
}
.block {
width: 10%;
height: 10%;
border: 2px solid tomato;
padding: 40px 40px;
margin: 2%;
/* margin: inherit; */
border-radius: 10px 10px;
/* display: inline; */
}
<div id="b">
<div class="block">hello1</div>
<div class="block">hello2</div>
<div class="block">hello3</div>
</div>