Add the following in the custom CSS:

:target:before {
content: "";
display: block;
height: 90px; /* fixed header height*/
margin: -90px 0 0; /* negative fixed header height */
}

Change the value (90px) as needed (check fixed menu height).

Apart from the value mentioned above, no need to modify anything else (such as the selector).

Source: https://www.itsupportguides.com/knowledge-base/tech-tips-tricks/how-to-offset-anchor-tag-link-using-css/