I having problems with moving the text of the a
tag to the middle of the nav
bar, if I use padding-top
the hover for the a tag overflow so I hide it using overflow: hidden;
on the nav
bar, what is the best solution for this problem ?.
note that my question is not about how to center an element who is a child of an other element like a p
tag inside a div
, and also I'm asking for the best approach in this current situation, which I guess a lot of beginner find it tricky .
html, body {
margin: 0px;
}
header {
display: grid;
grid-template-columns: 1fr 1fr;
color: white;
background: black;
}
header .title{
padding-left: 10px;
font-size: 2rem;
}
header h1 {
margin: 0;
}
nav {
overflow: hidden;
}
nav ul {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
margin: 0;
height: 100%;
}
nav ul li {
list-style-type: none;
text-align: center;
}
nav a {
color: white;
font-weight: bold;
text-decoration: none;
font-size: 1.4rem;
display: block;
height: 100%;
padding-top: 20px;
}
nav a:hover {
background-color: red;
}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="./css/style.css">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div class="wrapper">
<header>
<div class="title">
<h1>Biblio</h1>
</div>
<nav>
<ul>
<li><a href="#">home</a></li>
<li><a href="#">languages</a></li>
<li><a href="#">books</a></li>
</ul>
</nav>
</header>
</div>
</body>
</html>