By applying the text-align: center
property to the parent of your inline-block div, you can achieve the desired alignment.
Check out this demo for reference.
It's important to note that while this method may work in most browsers, older versions such as IE<8 may not support the use of display: inline-block
on the <div>
element. This limitation is well-documented on sites like quirksmode.
According to quirksmode, IE 6/7 will only recognize the value on elements with a natural display of inline.
To ensure cross-browser compatibility, consider using an alternative element (like an inline <span>
) or utilizing newer HTML5 elements which can be styled as inline blocks without issue on older IE browsers. For example, the <figure>
element could be a good substitute in this case.