在下一列上出现不必要的悬停效果

时间:2019-06-23 03:57:13

标签: html css column-count

将鼠标放在第三个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>

2 个答案:

答案 0 :(得分:2)

padding中删除所有marginlink并将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;
}