Как я могу настроить область щелчка вокруг моего флажка? - PullRequest
1 голос
/ 14 марта 2019

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

enter image description here enter image description here

Я в основном хочу настроить область, реагирующую на клики, по размеру флажка.

На втором изображении я выделил текущую область цветом фона: аквамарин, чтобы сделать ее более четкой.

Мой код SCSS выглядит следующим образом.У меня такое ощущение, что это должно быть легкой задачей, но я кое-что упускаю в деталях.

.date-checkbox {
display: inline;
float: right;
margin-right: -24px;
margin-top: -23px;
-webkit-transform: scale(2);
}

.disable-date {
opacity: 0.5;
pointer-events: none;
}

.enum-checkbox {
display: inline;
float: right;
margin-right: -24px;
margin-top: -23px;
-webkit-transform: scale(2);
}

/* The container */
.container {
cursor: pointer;
  }

/* Hide the browser's default checkbox */
.container input {
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
  }

/* Create a custom checkbox */
.checkmark {
position: absolute;
top: 4px;
left: 25px;
height: 15px;
width: 15px;
background-color: blue;
}

/* On mouse-over, add a grey background color */
.container:hover input ~ .checkmark {
background-color: blue;
}

/* When the checkbox is checked, add a blue background */
.container input:checked ~ .checkmark {
 background-color: blue;
}

/* Create the checkmark/indicator (hidden when not checked) */
.checkmark:after {
content: "";
position: absolute;
display: none;
}

/* Show the checkmark when checked */
.container input:checked ~ .checkmark:after {
 display: block;
}

/* Style the checkmark/indicator */
.container .checkmark:after {
left: 5px;
top: 2px;
width: 5px;
height: 10px;
border: solid white;
border-width: 0 3px 3px 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}

Мой HTML-код выглядит так:

<div class="enum-checkbox">
    <label class="container">
       <input type="checkbox" (click)="IncludeExcludeProp(groupobject[g.PROPS.title], $event)"
        title="Include in search" />
        <span class="checkmark"></span>
    </label>
</div>

1 Ответ

3 голосов
/ 14 марта 2019

Поскольку при щелчке по метке, по сути, ставится флажок, я бы добавил padding или width к label, окружающему флажок, чтобы он расширялся настолько, насколько вам нужно, чтобы ваша интерактивная область была.

Обратите внимание, что для удобства я добавил aria-label к флажку.Атрибут title игнорируется программами чтения с экрана, и в противном случае label не содержит никакой полезной информации о флажке.

enter image description here

.lbl-checkbox {
  display: inline-block;
  padding: 5em;
  background: #eee;
}
<label class="lbl-checkbox">
  <input aria-label="an appropriate label" type="checkbox">
</label>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...