У меня есть ссылки NavBar в правом верхнем углу моего веб-сайта, и они имеют белую заливку, когда они активны и при наведении на них курсора, но белая заливка окружает только слова, и я хочу знать, как настроить размер пустого пространства.
body {
font-family: Arial, Helvetica, sans-serif;
margin: 0px;
}
.header {
padding: 10px;
background-color: black;
display: flex;
justify-content: space-between;
align-items: center;
}
.header h1 {
color: white;
text-decoration: none;
overflow: hidden;
}
.topnav {
overflow: hidden;
}
.topnav a {
color: #f2f2f2;
text-align: center;
padding: 14px 15px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover {
background-color: white;
color: black;
border: 10px;
}
.topnav a.active {
background-color: white;
color: black;
width: 100px;
}<div class = "header">
<h1>Redacted</h1>
<div class = "topnav">
<a class = "active" href = "index.html">Home</a>
<a href = "resume.html">Resume</a>
<a href = "contact.html">Contact</a>
</div>
</div>Я хочу, чтобы кнопки имели большую заливку, а не только вокруг текста.






Вы можете изменить отступы элементов <a> внутри вашего .topnav.
body {
font-family: Arial, Helvetica, sans-serif;
margin: 0px;
}
.header {
padding: 10px;
background-color: black;
display: flex;
justify-content: space-between;
align-items: center;
}
.header h1 {
color: white;
text-decoration: none;
overflow: hidden;
}
.topnav {
overflow: hidden;
}
.topnav a {
color: #f2f2f2;
text-align: center;
padding: 14px 25px;
text-decoration: none;
font-size: 17px;
display: inline-block;
box-sizing: border-box;
}
.topnav a:hover, .topnav a.active {
background-color: white;
color: black;
}<div class = "header">
<h1>Redacted</h1>
<div class = "topnav">
<a class = "active" href = "index.html">Home</a>
<a href = "resume.html">Resume</a>
<a href = "contact.html">Contact</a>
</div>
</div>Вы можете применить padding-left и padding-right к активным и наведенным элементам:
body {
font-family: Arial, Helvetica, sans-serif;
margin: 0px;
}
.header {
padding: 10px;
background-color: black;
display: flex;
justify-content: space-between;
align-items: center;
}
.header h1 {
color: white;
text-decoration: none;
overflow: hidden;
}
.topnav {
overflow: hidden;
}
.topnav a {
color: #f2f2f2;
text-align: center;
padding: 14px 15px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover, .topnav a.active {
background-color: white;
color: black;
border: 10px;
padding-left: 50px;
padding-right: 50px;
}<div class = "header">
<h1>Redacted</h1>
<div class = "topnav">
<a class = "active" href = "index.html">Home</a>
<a href = "resume.html">Resume</a>
<a href = "contact.html">Contact</a>
</div>
</div>Вы можете добавить приведенный ниже код стиля в свой CSS-файл.
Надеюсь, это будет работать для вас.
body {
font-family: Arial, Helvetica, sans-serif;
margin: 0px;
}
.header {
background-color: black;
display: flex;
justify-content: space-between;
align-items: stretch;
}
.header h1 {
padding: .2rem 2rem;
color: white;
text-decoration: none;
overflow: hidden;
}
.topnav {
overflow: hidden;
display: flex;
}
.topnav a {
color: #f2f2f2;
text-align: center;
padding: 14px 15px;
text-decoration: none;
font-size: 17px;
display: flex;
align-items: center;
justify-content: center;
}
.topnav a:hover,
.topnav a.active {
background-color: white;
color: black;
}<div class = "header">
<h1>Redacted</h1>
<div class = "topnav">
<a class = "active" href = "index.html">Home</a>
<a href = "resume.html">Resume</a>
<a href = "contact.html">Contact</a>
</div>
</div>