Please have a look at the example below, than contains a large div which in turn contains a lot of smaller divs inside.
Each div has a fixed width of 150px
and a display of inline-block
, so the browser will fit as many as possible in a single line.
The problem is that whenever there is unoccupied horizontal space in the large div it doesn't get shared by the margin: auto
property of the children, but rather stays on the left of the large div.
#parent {
border: 1px solid red;
display: block;
width: 100%;
}
#parent>div {
border: 1px solid black;
text-align: center;
width: 150px;
display: inline-block;
margin: 0 auto;
}
<div id="parent">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
<div>13</div>
<div>14</div>
</div>
Is there a way to center the divs while also allowing more than one div per row and having the same alignment on the bottom regardless of how many elements it shows?