I have created a custom checkbox (codepen here). On clicking on the checkbox or the text, the checkbox should be checked/unchecked. It works for most part, but there is an annoying tiny space between the 2 lines of text, where it is not clickable (cursor doesn't change to pointer).
I can fix it by making .message as display block, and adjusting the top property of the tick (codepen here), so I am not asking for ways to fix it. I just want to know why it is behaving like that in the first case. I would appreciate any help on this.
<div class="cfux-field">
<input type="checkbox" id="cbOptIn" />
<label for="cbOptIn">
<span class="message">Send me the latest news, travel tips and deals from XYZ Limited</span></label>
</div>
EDIT: I have found a partial answer and nkorth's answer, which although doesn't explain the reason, gave me a clue to it. The font-size on cfux-field is 16px and the line-height was normal (inherited from user-agent). As per MDN, line-height normal is roughly 1.2 depending on user-agent and font. As the label and message span are inline elements, so setting line-height on those doesn't make a difference and inherits the line-height from cfux-field.
So to make this work, there are 2 options:-
- Make label display block (looks like a better option as doesn't depend on how a particular browser calculates the content-height)
- Set font-size on cfux-field same as font-size that I want on the label.
But this doesn't explain why the increased line-height makes the content inaccessible (ie not clickable) - probably because of the way browsers calculate the content height - some explaination here.