Search code examples
htmlcsscenter

How to centering span


How to centering that download button? I tested many times but it's wrong codes.

.col {
  width: 100%;
  height: auto;
  float: left;
}
.download {
  width: auto;
  font-weight: 600;
  font-size: 14px;
  color: #000;
  border: 2px solid #000;
  padding: 17px 37px;
  margin-top: 30px;
  float: left;
}
<div class="col">
  <span class="download">Download</span>
</div>


Solution

    1. Remove float:left; from .download (because it forces the element to be floated to the left).

    2. Give display:inline-block; (It acts like inline element, it means you can center it by giving text-align:center; to its parent.)

    JSFiddle

    .col {
        width: 100%;
        height: auto;
        float: left;
        text-align: center;
    }
    .download {
        font-weight: 600;
        font-size: 14px;
        color: #000;
        border: 2px solid #000;
        padding: 17px 37px;
        margin-top: 30px;
        display: inline-block;
    }