The Datepicker’s top position should be slightly below the input’s bottom position. Let’s say we want to leave a gap of 20px between the input and the Datepicker.
Since we’re positioning the Datepicker with top and left properties, we can remove the margin-top property from the CSS.
/* Remove this */
.datepicker {
margin-top: 1em;
}
At this point, you can place the Datepicker anywhere on the DOM. It should always be positioned in the same location.
// Changing where we create the datepicker
document.body.appendChild(createDatepicker(input, date))
Vertical Rhythm
If research into design, you may have come across a term called Vertical Rhythm. It’s a way to make your website look clean and professional.
The idea is you create whitespace that are consistent with your typography. And you use this multiple across your site. This uses the rule of repetition to create a sense of harmony and familiarity.
One more thing. One “font-size” is a unit in CSS. It can either be rem or em. rem is the font-size for the document, while em is the font-size for the current element. (More info about rem and em in this article).
Since we get the font size from the document, let’s call the variable oneRem.