I have a header with links for navigation. Each link is a div
, and inside it there is an a
link. I want to make each a link fill the vertical and horizontal space of the div.
.TopNav {
position: relative;
border-bottom: 1px solid black;
}
.TopNav-wrapper {
position: relative;
max-width: 1000px;
margin: 0 auto;
background-color: gold;
}
.TopNav-item {
display: inline-block;
width: 100px;
text-align: center;
vertical-align: middle;
display: table-cell;
margin-right: 20px;
border: 1px solid tomato;
height: 72px;
}
.TopNav-a {
background-color: tomato;
color: white;
}
<nav class="TopNav">
<div class="TopNav-wrapper">
<div class="TopNav-item">
<a class="TopNav-a" href="">First</a>
</div>
<div class="TopNav-item">
<a class="TopNav-a " href="">Second</a>
</div>
<div class="TopNav-item">
<a class="TopNav-a" href="">Third</a>
</div>
</div>
</nav>
And a fiddle: https://jsfiddle.net/6rp1canq/
这可能吗?
答案 0 :(得分:0)
以这种方式更改.TopNav-a
样式:
.TopNav-a {
display: block;
background-color: tomato;
color: white;
height: 72px;
line-height: 72px;
}
答案 1 :(得分:0)
在执行a
div
周围写下<a><div>Test</div></a>
标记
答案 2 :(得分:0)
您可以使用flexbox布局:
.TopNav {
position: relative;
border-bottom: 1px solid black;
}
.TopNav-wrapper {
position: relative;
max-width: 1000px;
margin: 0 auto;
background-color: gold;
}
.TopNav-item {
display: inline-block;
width: 100px;
text-align: center;
vertical-align: middle;
display: table-cell;
margin-right: 20px;
border: 1px solid tomato;
height: 72px;
}
.TopNav-a {
background-color: tomato;
color: white;
display: flex;
justify-content: center;
align-items: center;
height: 100%;
}
<nav class="TopNav">
<div class="TopNav-wrapper">
<div class="TopNav-item">
<a class="TopNav-a" href="">First</a>
</div>
<div class="TopNav-item">
<a class="TopNav-a " href="">Second</a>
</div>
<div class="TopNav-item">
<a class="TopNav-a" href="">Third</a>
</div>
</div>
</nav>
答案 3 :(得分:0)
你可以将div包装在一个锚中。