Batnyam Baasanjav
Batnyam Baasanjav

Reputation: 15

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>

Upvotes: 1

Views: 88

Answers (2)

Alex
Alex

Reputation: 8695

  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;
}

Upvotes: 2

Aminesrine
Aminesrine

Reputation: 2140

Just add text-align: center; to .col and replace float:left with display:inline-block; in the button element. jsfiddle

Upvotes: 3

Related Questions