mardi 30 août 2016

Aligning custom checkbox issue css

I am tying to align the text of the right of my checkbox. Currently the text is appearing in multiple lines.

I have tried changing the width and giving it a fixed width:

.checkbox span.custom  {
  margin-left: 34px;
  display: inline-block;
  width: 100px; // MY TRY
}

but it is changing the size of the checkbox not the text next to it.

CSS:

* {
  box-sizing: border-box;
}

label {
  display: inline-block;
}

.checkbox {
  position: relative;
  min-height: 24px;
  font-size: 1.6rem;
}

.checkbox input {
  -webkit-tap-highlight-color: transparent;
  height: 10px;
  margin: 6px;
  opacity: 0;
  outline: none;
  position: absolute;
  left: 1px;
  top: 1px;
  width: 10px;
}

.checkbox .custom {
  background-color: #fff;
  border: 1px solid #ccc;
  border-radius: 3px;
  display: inline-block;
  height: 24px;
  left: 0;
  position: absolute;
  top: 0;
  width: 24px;
}

.checkbox span {
  display: inline-block;
  margin-left: 34px;
  margin-top: 0;
  position: relative;
  top: 3px;
}

.checkbox input:checked:not(:disabled) + .custom {
  background-color: #0574ac;
  border-color: #0574ac;
}

.checkbox span {
  margin-left: 0px;
}

.checkbox span.custom  {
  margin-left: 34px;
  display: inline-block;
  width: 100px; // MY TRY
}

.checkbox span.custom .radio span.custom {
  margin-left: 34px;
  margin-right: 34px;
  display: flex;
}

.radio input:checked + .custom:after {
  background-color: #0574ac;
  border-radius: 100%;
  border: 3px solid #fff;
  content: "";
  display: block;
  height: 16px;
  position: absolute;
  width: 16px;
}

HTML:

<label for="checkbox1" class="checkbox">
      <input id="checkbox1" type="checkbox" role="checkbox" /><span class="custom">Checkbox 1</span>
</label>

JSFiddle Demo




Aucun commentaire:

Enregistrer un commentaire