5

我想在使用CSS的列数时在每一列中使用分隔符。

HTML:

<ul class="channel_list">
    <li><input class="channels" type="checkbox" name="7" value="y">&nbsp;Channel 1</li>
    <li><input class="channels" type="checkbox" name="8" value="y">&nbsp;Channel 2</li>
    <li><input class="channels" type="checkbox" name="9" value="y">&nbsp;Channel 3</li>
    <li><input class="channels" type="checkbox" name="6" value="y">&nbsp;Channel 4</li>
    <li><input class="channels" type="checkbox" name="5" value="y">&nbsp;Channel 5</li>
</ul>

CSS:

.channel_list{
    -webkit-column-count: 3; /* Chrome, Safari, Opera */
    -moz-column-count: 3; /* Firefox */
    column-count: 3;
}
.channel_list li{ list-style: none}

我想要什么像- 在此处输入图像描述

我尝试:

.channel_list li{ border-right: 5px solid red}

只有 li 右侧的边框,而不是最后一列的边框。

4

3 回答 3

2

如果我对问题的理解是正确的,您可以使用column-rule属性来实现这一点。它是一个简写属性,由column-rule-widthcolumn-rule-color组成column-rule-style。这三个长期属性的工作方式与和border-width完全相似。支持所有受支持的值。border-colorborder-stylecolumn-rule-styleborder-style

请注意,您不能生成圆角分隔符(即,没有等效的border-radius)。

该属性在 IE 以外的所有浏览器中仍然需要供应商前缀!

.channel_list {
  padding: 0;
  text-align: center; /* make the separator look like it is in middle */
  -webkit-column-count: 3;  /* Chrome, Safari, Opera */
  -moz-column-count: 3;  /* Firefox */
  column-count: 3;
  
  /* just for spacing */
  -webkit-column-gap: 20px;
  -moz-column-gap: 20px;
  column-gap: 20px;
}
.channel_list li {
  list-style: none;
}
.channel_list.solid {
  -webkit-column-rule: 5px solid red;
  -moz-column-rule: 5px solid red;
  column-rule: 5px solid red;
}
.channel_list.dashed {
  -webkit-column-rule: thin dashed chocolate;
  -moz-column-rule: thin dashed chocolate;
  column-rule: thin dashed chocolate;
}
.channel_list.dotted {
  -webkit-column-rule: medium dotted rebeccapurple;
  -moz-column-rule: thin dotted rebeccapurple;
  column-rule: thin dotted rebeccapurple;
}
<ul class="channel_list solid">
  <li>
    <input class="channels" type="checkbox" name="7" value="y">&nbsp;Channel 1</li>
  <li>
    <input class="channels" type="checkbox" name="8" value="y">&nbsp;Channel 2</li>
  <li>
    <input class="channels" type="checkbox" name="9" value="y">&nbsp;Channel 3</li>
  <li>
    <input class="channels" type="checkbox" name="6" value="y">&nbsp;Channel 4</li>
  <li>
    <input class="channels" type="checkbox" name="5" value="y">&nbsp;Channel 5</li>
</ul>
<hr>
<ul class="channel_list dashed">
  <li>
    <input class="channels" type="checkbox" name="7" value="y">&nbsp;Channel 1</li>
  <li>
    <input class="channels" type="checkbox" name="8" value="y">&nbsp;Channel 2</li>
  <li>
    <input class="channels" type="checkbox" name="9" value="y">&nbsp;Channel 3</li>
  <li>
    <input class="channels" type="checkbox" name="6" value="y">&nbsp;Channel 4</li>
  <li>
    <input class="channels" type="checkbox" name="5" value="y">&nbsp;Channel 5</li>
</ul>
<hr>
<ul class="channel_list dotted">
  <li>
    <input class="channels" type="checkbox" name="7" value="y">&nbsp;Channel 1</li>
  <li>
    <input class="channels" type="checkbox" name="8" value="y">&nbsp;Channel 2</li>
  <li>
    <input class="channels" type="checkbox" name="9" value="y">&nbsp;Channel 3</li>
  <li>
    <input class="channels" type="checkbox" name="6" value="y">&nbsp;Channel 4</li>
  <li>
    <input class="channels" type="checkbox" name="5" value="y">&nbsp;Channel 5</li>
</ul>

于 2016-06-16T05:10:00.850 回答
0

只是另一种替代解决方案。

.channel_list{
    -webkit-column-count: 3; /* Chrome, Safari, Opera */
    -moz-column-count: 3; /* Firefox */
    column-count: 3;
}
.channel_list li{ list-style: none;border-right:5px solid red}
.channel_list li:nth-child(n+9){border-right:none} /* selects from the ninth onwards */
<ul class="channel_list">
    <li><input class="channels" type="checkbox" name="7" value="y">&nbsp;Channel 1</li>
    <li><input class="channels" type="checkbox" name="8" value="y">&nbsp;Channel 2</li>
    <li><input class="channels" type="checkbox" name="9" value="y">&nbsp;Channel 3</li>
    <li><input class="channels" type="checkbox" name="6" value="y">&nbsp;Channel 4</li>
    <li><input class="channels" type="checkbox" name="5" value="y">&nbsp;Channel 5</li>
      <li><input class="channels" type="checkbox" name="5" value="y">&nbsp;Channel 6</li>
      <li><input class="channels" type="checkbox" name="5" value="y">&nbsp;Channel 7</li>
      <li><input class="channels" type="checkbox" name="5" value="y">&nbsp;Channel 8</li>
      <li><input class="channels" type="checkbox" name="5" value="y">&nbsp;Channel 9</li>
      <li><input class="channels" type="checkbox" name="5" value="y">&nbsp;Channel 10</li>
       <li><input class="channels" type="checkbox" name="5" value="y">&nbsp;Channel 11</li>
       <li><input class="channels" type="checkbox" name="5" value="y">&nbsp;Channel 12</li>
</ul>

于 2016-06-16T05:21:28.663 回答
0

使用列规则

     -webkit-column-rule: 4px outset red; /* Chrome, Safari, Opera */
     -moz-column-rule: 4px outset red; /* Firefox */
     column-rule: 4px outset red;

Codepen URL - http://codepen.io/nagasai/pen/jrrGGX供参考

希望这对你有用

于 2016-06-16T05:18:25.767 回答