Avoid an element to be split into two columns while using column-count

白昼怎懂夜的黑 提交于 2019-12-20 07:47:29

问题


I am trying to make a group of <a> using multiple columns. But it splits one <a> (Link4) into two columns. :( Just hover on Link4. Some of its part is split to second column. :( Is there any possible way to avoid this.

div.Nav {
  height: 100% !important;
}

div.Nav a.icon {
  position: absolute;
  right: 0;
  top: 0;
}

div.Nav a {
  transition: 0.5s;
  line-height: 25px;
  text-align: center;
  font-weight: lighter;
  color: black;
  padding: 8px 16px;
  text-decoration: none;
  font-size: 20px;
  float: none !important;
  display: block;
  text-align: left;
}

div.Nav a.active {
  background-color: #4CAF50;
  color: white;
  cursor: default;
}

div.Nav a:hover:not(.active) {
  background-color: rgb(56, 62, 50);
  color: #fffd78;
  transition: 0.5s;
}

div.Nav div.newspaper {
  -webkit-column-count: 3;
  -moz-column-count: 3;
  column-count: 3;
  -webkit-column-rule: 2px grey solid;
  -moz-column-rule: 2px grey solid;
  column-rule: 2px grey solid;
  -webkit-column-gap: 0;
  -moz-column-gap: 0;
  column-gap: 0;
}
<!DOCTYPE html>
<html>

<head>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>

<body>
  <div id="Nav" class="Nav">
    <a href="javascript:void(0)" class="active"><i class="fa fa-home fa-lg" aria-hidden="true"></i></a>
    <div class="newspaper">
      <a href="javascript:void(0)" class="show">Link1</a>
      <a href="javascript:void(0)" target="_self">Link2</a>
      <a href="javascript:void(0)" target="_self">Link3</a>
      <a href="javascript:void(0)" target="_self">Link4</a>
      <a href="javascript:void(0)" target="_self">Link5</a>
      <a href="javascript:void(0)" target="_self">Link6</a>
      <a href="javascript:void(0)" target="_self">Link7</a>
      <a href="javascript:void(0)" target="_self">Link8</a>
      <a href="javascript:void(0)" target="_self">Link9</a>
      <a href="javascript:void(0)" target="_self">Link10</a>
    </div>
  </div>
</body>

</html>

回答1:


Use break-inside: avoid; (or the propriety equivalents) to prevent the tags from flowing into the next column:

div.Nav {
  height: 100% !important;
}

div.Nav a.icon {
  position: absolute;
  right: 0;
  top: 0;
}

div.Nav a {
  transition: 0.5s;
  line-height: 25px;
  text-align: center;
  font-weight: lighter;
  color: black;
  padding: 8px 16px;
  text-decoration: none;
  font-size: 20px;
  float: none !important;
  display: block;
  text-align: left;
  
  -webkit-column-break-inside: avoid; /* Chrome, Safari, Opera */
  page-break-inside: avoid; /* Firefox */
  break-inside: avoid; /* IE 10+ */
}

div.Nav a.active {
  background-color: #4CAF50;
  color: white;
  cursor: default;
}

div.Nav a:hover:not(.active) {
  background-color: rgb(56, 62, 50);
  color: #fffd78;
  transition: 0.5s;
}

div.Nav div.newspaper {
  -webkit-column-count: 3;
  -moz-column-count: 3;
  column-count: 3;
  -webkit-column-rule: 2px grey solid;
  -moz-column-rule: 2px grey solid;
  column-rule: 2px grey solid;
  -webkit-column-gap: 0;
  -moz-column-gap: 0;
  column-gap: 0;
}
<!DOCTYPE html>
<html>

<head>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>

<body>
  <div id="Nav" class="Nav">
    <a href="javascript:void(0)" class="active"><i class="fa fa-home fa-lg" aria-hidden="true"></i></a>
    <div class="newspaper">
      <a href="javascript:void(0)" class="show">Link1</a>
      <a href="javascript:void(0)" target="_self">Link2</a>
      <a href="javascript:void(0)" target="_self">Link3</a>
      <a href="javascript:void(0)" target="_self">Link4</a>
      <a href="javascript:void(0)" target="_self">Link5</a>
      <a href="javascript:void(0)" target="_self">Link6</a>
      <a href="javascript:void(0)" target="_self">Link7</a>
      <a href="javascript:void(0)" target="_self">Link8</a>
      <a href="javascript:void(0)" target="_self">Link9</a>
      <a href="javascript:void(0)" target="_self">Link10</a>
    </div>
  </div>
</body>

</html>


来源:https://stackoverflow.com/questions/44603333/avoid-an-element-to-be-split-into-two-columns-while-using-column-count

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!