-2

I'm trying to make a custom checkbox using blocks

.checkbox-container {
  height: 18px;
  line-height: 18px;
  margin: 0;
  padding: 0;
  display: inline-block;
  cursor: pointer;
  font-size: 14px;
  position: relative;
  vertical-align: middle;
}

.label {
  margin-left: 4px;
}

.input-box {
  display: inline-block;
  height: 18px;
  width: 18px;
}

.off {
  background-color: #fff;
  border: 2px solid red;
}

.on {
  background-color: red;
  border: 2px solid transparent;
}

.on::after {
  content: '';
  position: absolute;
  left: 6px;
  top: 2px;
  width: 7px;
  height: 11px;
  border: solid #fff;
  border-width: 0 3px 3px 0;
  -webkit-transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  transform: rotate(45deg);
}
<div class="checkbox-container">
  <span class="input-box on"></span>
  <span class="label">Checkbox</span>
</div>

How can I center the text vertically in this block?

Michael
  • 15,386
  • 36
  • 94
  • 143

1 Answers1

-1

Just add vertical-align: super; prop in your .label class.

.label {
  margin-left: 4px;
  vertical-align: super;
}

.checkbox-container {
  height: 18px;
  line-height: 18px;
  margin: 0;
  padding: 0;
  display: inline-block;
  cursor: pointer;
  font-size: 14px;
  position: relative;
  vertical-align: middle;
}

.label {
  margin-left: 4px;
  vertical-align: super;
}

.input-box {
  display: inline-block;
  height: 18px;
  width: 18px;
}

.off {
  background-color: #fff;
  border: 2px solid red;
}

.on {
  background-color: red;
  border: 2px solid transparent;
}

.on::after {
  content: '';
  position: absolute;
  left: 6px;
  top: 2px;
  width: 7px;
  height: 11px;
  border: solid #fff;
  border-width: 0 3px 3px 0;
  -webkit-transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  transform: rotate(45deg);
}
<div class="checkbox-container">
  <span class="input-box on"></span>
  <span class="label">Checkbox</span>
</div>
Hassan Siddiqui
  • 2,799
  • 1
  • 13
  • 22
Nils Fahle
  • 75
  • 1
  • 10