将鼠标放在第三个lorem ipsum
上,您会在下一列看到不想要的hover
效果。
如何避免这种情况?
.footer{
column-count:2;
background:#006790;
padding:9px 14px;
}
.link{
display:block;
padding:4px 10px;
margin:7px 3px;
color:white;
white-space:nowrap;
font-size:1.1em;
border-radius:9px;
}
.link:hover{
background:white;
color:black;
}
<div class = 'footer'>
<a class='link' href='#'>lorem ipsum</a>
<a class='link' href='#'>lorem ipsum</a>
<a class='link' href='#'>lorem ipsum</a>
<a class='link' href='#'>lorem ipsum</a>
<a class='link' href='#'>lorem ipsum</a>
</div>
答案 0 :(得分:2)
从padding
中删除所有margin
和link
并将line-height
添加到其中。那将解决您的问题。以下是相同的代码段
.footer {
column-count: 2;
background: #006790;
padding: 9px 14px;
}
a.link {
display: block;
line-height: 30px;
color: white;
white-space: nowrap;
font-size: 1.1em;
border-radius: 9px;
text-align: center
}
a.link:hover {
background: white;
color: black;
}
<div class='footer'>
<a class='link' href='#'>lorem ipsum</a>
<a class='link' href='#'>lorem ipsum</a>
<a class='link' href='#'>lorem ipsum</a>
<a class='link' href='#'>lorem ipsum</a>
<a class='link' href='#'>lorem ipsum</a>
</div>
答案 1 :(得分:1)
这是CSS列方式
moduleB
.footer {
column-count: 2;
background: #006790;
padding: 9px 14px;
}
.link {
display: block;
padding: 4px 10px;
margin: 7px 3px;
color: white;
white-space: nowrap;
font-size: 1.1em;
border-radius: 9px;
-webkit-column-break-inside: avoid;
/* Chrome, Safari, Opera */
page-break-inside: avoid;
/* Firefox */
break-inside: avoid;
/* IE 10+ */
}
.link:hover {
background: white;
color: black;
}