1

I have a custom styled checkbox, see this JSFiddle:

https://jsfiddle.net/y58zrd4m/

My HTML looks like this:

<label class="checkbox">
  <input type="checkbox" />
  <span>Lorem ipsum</span>
</label>

Now I want my text to be vertically centered in relation to the checkbox, how can I achieve this?

Simon Schiller
  • 564
  • 1
  • 5
  • 18
  • 1
    Possible duplicate of [How to align checkboxes and their labels consistently cross-browsers](http://stackoverflow.com/questions/306252/how-to-align-checkboxes-and-their-labels-consistently-cross-browsers) – jannej Sep 20 '16 at 07:11

1 Answers1

2

Some changes in your CSS will help you achieve that as:

Code Snippet

.checkbox {
  cursor: pointer;
  position: relative;
}
.checkbox input[type="checkbox"] {
  display: none;
}
.checkbox span {
  font-size: 20px;
  display: inline-block;
  padding: 10px 0 0 40px;
}
.checkbox span:before {
  content: "";
  display: inline-block;
  width: 25px;
  height: 25px;
  border: 2px solid rgba(0, 0, 0, 0.5);
  border-radius: 5px;
  margin: 0;
  position: absolute;
  left: 2px;
  top: -7px;
}
.checkbox span:after {
  content: "";
  display: none;
  position: absolute;
  left: 12px;
  top: -2px;
  width: 5px;
  height: 13px;
  border-bottom: 4px solid white;
  border-right: 4px solid white;
  border-radius: 1px;
  transform: rotate(30deg);
}
.checkbox input[type="checkbox"]:checked + span:before {
  border-color: #03a9f4;
  background-color: #03a9f4;
}
.checkbox input[type="checkbox"]:checked + span:after {
  display: inline-block;
}
<label class="checkbox">
  <input type="checkbox" />
  <span>Lorem ipsum</span>
</label>
vivekkupadhyay
  • 2,805
  • 1
  • 20
  • 32