I have a navbar where I am using an anchor tag as a button. When the font size is default, everything is fine but when I change it a bit it adds some space at the top as shown.
NOTE this space is not visible on pc but instead when the website is viewed on a phone or other devices with less width. If the same website is opened on landscape mode of the phone, the extra space on top disappears.
here is the html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Code Craze Course</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="nav">
<h1 class='nav-elements' id="heading-1">Code Craze Course</h1>
<a class="nav-elements" id="a-1" href="google.com">Enroll Now</a>
</div>
</body>
</html>
Here is the css:
*{
margin: 0;
padding: 0;
}
body{
background-color: cadetblue;
}
.nav{
width: 100%;
height: 5vw;
display: inline-flex;
align-items: center;
}
#heading-1{
display: inline-flex;
justify-content: center;
align-items: center;
width: 100%;
position:absolute;
color: white;
background-color: rgb(53, 53, 53);
height: 5vw;
font-size:3vw;
}
#a-1{
color: white;
display: inline-flex;
align-items: center;
position: relative;
text-decoration: none;
background-color: rgb(40, 89, 194);
margin: 0 0 0 1vw;
border-radius: 3px;
border: 0.15vw solid rgb(189, 189, 189);
padding: 0px 1vw;
font-size: 1vw;
font-family:Verdana, Geneva, Tahoma, sans-serif;
height: 2vw;
}
I tried changing the line height but it didn’t help. But changing the font size to default fixes the problem but I need the font size to be a bit bigger so can’t keep t as default.
REQUEST-Please don’t mark this as duplicate as I have already tried the solutions given in this post (Font-size increases the top margin) but it didn’t help.