首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在使用column-count时,避免将元素拆分为两列

在使用column-count时,避免将元素拆分为两列
EN

Stack Overflow用户
提问于 2017-06-17 18:12:38
回答 1查看 1.6K关注 0票数 0

我正在尝试制作一组使用多个列的内容。但它将一个(Link4)拆分为两列。:(只需在Link4上悬停。它的一些部分被分到第二列。:(有没有可能避免这种情况。

代码语言:javascript
复制
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;
}
代码语言:javascript
复制
<!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>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-17 18:18:54

使用break-inside: avoid; (或适当的等价物)防止标记进入下一列:

代码语言:javascript
复制
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;
}
代码语言:javascript
复制
<!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>

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44603333

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档