флажок установлен на новую строку - PullRequest
0 голосов
/ 21 марта 2020

Я пытаюсь добавить флажок, но, кажется, он всегда go на следующей строке.

Я как-то исправил это по замыслу, но он всегда возвращается на новую строку.

Это образец флажка, который я копирую из Интернета

input[type=checkbox]+label {
  display: block;
  cursor: pointer;
  padding: 0.2em;
  width: 113px;
}

input[type=checkbox] {
  display: none;
}

input[type=checkbox]+label:before {
  content: "\2714";
  border: 0.1em solid #000;
  border-radius: 0.2em;
  display: inline-block;
  width: 1em;
  height: 1em;
  vertical-align: bottom;
  color: transparent;
  transition: .2s;
}

input[type=checkbox]+label:active:before {
  transform: scale(0);
}

input[type=checkbox]:checked+label:before {
  background-color: MediumSeaGreen;
  border-color: MediumSeaGreen;
  color: #fff;
}
<input type="checkbox" id="fruit1" name="fruit-1" value="Apple">
<label for="fruit1">Apple</label>
<input type="checkbox" id="fruit2" name="fruit-2" value="Banana" disabled>
<label for="fruit2">Banana</label>
<input type="checkbox" id="fruit3" name="fruit-3" value="Cherry" checked disabled>
<label for="fruit3">Cherry</label>
<input type="checkbox" id="fruit4" name="fruit-4" value="Strawberry">
<label for="fruit4">Strawberry</label>

1 Ответ

1 голос
/ 21 марта 2020

Не используйте блок дисплея для метки:

<!DOCTYPE html>
<html>

<head>
    <title>Parcel Sandbox</title>
    <meta charset="UTF-8" />
    <style>
    input[type=checkbox]+label {
  cursor: pointer;
  padding: 0.2em;
  width: 113px;
}

input[type=checkbox] {
  display: none;
}

input[type=checkbox]+label:before {
  content: "\2714";
  border: 0.1em solid #000;
  border-radius: 0.2em;
  display: inline-block;
  width: 1em;
  height: 1em;
  vertical-align: bottom;
  color: transparent;
  transition: .2s;
}

input[type=checkbox]+label:active:before {
  transform: scale(0);
}

input[type=checkbox]:checked+label:before {
  background-color: MediumSeaGreen;
  border-color: MediumSeaGreen;
  color: #fff;
}
    </style>
</head>

<body>
    <div id="app">
        <input type="checkbox" id="fruit1" name="fruit-1" value="Apple">
        <label for="fruit1">Apple</label>
        <input type="checkbox" id="fruit2" name="fruit-2" value="Banana" disabled>
        <label for="fruit2">Banana</label>
        <input type="checkbox" id="fruit3" name="fruit-3" value="Cherry" checked disabled>
        <label for="fruit3">Cherry</label>
        <input type="checkbox" id="fruit4" name="fruit-4" value="Strawberry">
        <label for="fruit4">Strawberry</label>
    </div>
    </script>
</body>

</html>

Образец

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...