CSS, centered div, shrink to fit?

DIV elements are block-level by default, which means they automatically get 100% width. To change that, use this CSS…

.centerBox {
  display:inline-block;
  text-align:center;
}


<div class="centerBox">
  Some text
</div>

EDIT: Updated to use a CSS class rather than inline attribute and changed “block” to “inline-block”

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)