【问题标题】:How to Add Separators after List items In CSS如何在 CSS 中的列表项后添加分隔符
【发布时间】:2015-07-16 15:58:02
【问题描述】:

我正在尝试创建一个列表项并在它们之间添加分隔符我尝试了所有方法,但问题仍然存在。这是我希望我的列表菜单看起来像的图像:-

我使用的 css 和 html 代码是这样的:-

HTML :-

<p class="Categories">Categories</p>
<div class="Rectangle"></div>
<div class="Categories_Box box1 box2">
<ul>
<li><a href="#" class="">Today</a></li>
<div class="line1"></div>
<li><a href="#" class="yest">Yesterday</a></li>
<li><a href="#" class="this_week">This Week</a></li>
<li><a href="#" class="last_week">Last Week</a></li>
<li><a href="#" class="last_month">Last Month</a></li>
</ul>
</div>

CSS :-

   .Categories {
  font-size: 29px;
  font-family: "Exo";
  color: rgb(237, 106, 61);
  font-weight: bold;
  line-height: 0.869;
  position: absolute;
  left: 227.937px;
  top: 215px;
  z-index: 31;
}

.Rectangle {
  background-color: rgb(107, 107, 107);
  position: absolute;
  left: 231px;
  top: 281px;
  width: 194px;
  height: 5px;
  z-index: 29;
}


.Categories_Box ul{
 position:absolute;
 left: 0px;
 top: 0px;
 width: 1366px;
 height: 768px;
 z-index: 43;
 list-style:none;

}


.yest, .this_week, .last_week, .last_month {
  font-size: 21px;
  font-family: "Exo";
  text-decoration:none;
  color: rgb(107, 107, 107);
  font-weight: bold;
  line-height: 0.86;
  -moz-transform: matrix( 0.76907888849934,0,0,0.58955579248353,0,0);
  -webkit-transform: matrix( 0.76907888849934,0,0,0.58955579248353,0,0);
  -ms-transform: matrix( 0.76907888849934,0,0,0.58955579248353,0,0);
  position:relative;
  left: -175px;
  top: -641.112px;
  z-index: 30;
}

.line1 {
  font-size: 10px;
  font-family: "Arial";
  color: rgb(221, 221, 221);
  line-height: 4.2;
  position: absolute;
  left: 345.85px;
  top: 684.418px;
  z-index: 100;
}


.box2 {
  border-style: solid;
  border-width: 1px;
  border-color: rgb(217, 217, 217);
  border-radius: 5px;
  background-color: rgb(242, 242, 242);
  box-shadow: 0px 1px 2px 0px rgba(0, 0, 0, 0.36);
  position: absolute;
  left: 219px;
  top: 229px;
  width: 228px;
  height: 498px;
  z-index: 27;
}


.box1 {
  border-radius: 5px;
  background-color: rgb(255, 255, 255);
  position: absolute;
  left: 221px;
  top: 230px;
  width: 225px;
  height: 498px;
  z-index: 28;
}

编辑此代码后,我的前 20 个列表消失了,我什至看不到菜单项。 请帮帮我

【问题讨论】:

    标签: html css separator


    【解决方案1】:

    您可以通过为列表项添加虚线边框来创建外观。举个简单的例子:

    HTML:

    <ul>
        <li><a href='#'>Title</a></li>
        <li><a href='#'>Element 1</a></li>
        <li><a href='#'>Element 2</a></li>
        <li><a href='#'>Element 3</a></li>
        <li><a href='#'>Element 4</a></li>
    </ul>
    

    CSS:

    ul{
        list-style:none;
        padding-left:10px;
        padding-right:10px;
        width:140px;
        border:1px #eee solid;
        border-radius:10px;
    }
    
    li{
        border-bottom: 1px #ccc dashed;
    }
    
    a{
        padding-top: 10px;
        padding-bottom: 10px;
        color: rgb(107, 107, 107);
        text-decoration: none;
        width: 100%;
        height: 100%;
        display: inline-block;
    }
    
    li:last-child{
        border-bottom: none;
    }
    
    li:first-child{
        border-bottom: solid grey;
    }
    li:first-child a{
        color: rgb(237, 106, 61);
        font-weight: bold;
        font-size: 20px;
    }
    

    有关工作示例,请参阅 https://jsfiddle.net/72vvksws/3/

    【讨论】:

    • 这是一个不错的解决方案,但我有不止一个列表项。这是我到目前为止所做的进展,如果我尝试添加虚线边框它会搞砸请帮助我:jsfiddle.net/deep90s/j5ptL32n/2
    • @dssingh - 这是提供您想要的外观的最简洁的方法。要在您的示例中实现它,您可以将 CSS 属性应用于类 like this example,以便只有侧边栏获取这些值。
    • 有了这个名为“Title”的标题也变成了一个链接,我确实需要我应该为此做些什么?
    【解决方案2】:

    感谢您在经过大量尝试后回复我,我解决了我的问题。造成问题的是 z-index 属性。在以正确的顺序设置 z-index 属性后,我能够在列表项之间添加分隔符,而无需使用边框属性。这是代码:-

    HTML :-

    <p class="t20_files">Top 20 Files</p>
    <div class="Rectangle1"></div>
    <div class="Outside_box1 Inside_Box1">
    <div class="Categories_Box1">
    <ul>
    <li><a href="#">Today</a></li>
    <p class="line10">------------------------</p>
    <li><a href="#">Yesterday</a></li>
    <p class="line11">------------------------</p>
    <li><a href="#">This Week</a></li>
    <p class="line12">------------------------</p>
    <li><a href="#">Last Week</a></li>
    <p class="line13">------------------------</p>
    <li><a href="#">This Month</a></li>
    <p class="line14">------------------------</p>
    <li><a href="#">Last Month</a></li>
    </ul>
    </div>
    </div>
    

    CSS:-

    @import url(normalize.css);
    
    html,body
    {
        width: 100%;
        height: 100%;
        margin: 0px;
        padding: 0px;
        overflow-x: hidden; 
        background:url(../images/site_bg.png) no-repeat;
        position: relative;
        background-size: 100% 100%;
    }
    /*------------------------------Background---------------------------*/
    
    
    
    /*-----------------------------Horizontal Menu Starts----------------*/
    .head-menu {
      background:url(img/menu_bg.png);
      position: absolute;
      left: 219px;
      top: 117px;
      width: 930px;
      height: 81px;
    
    
        }
    
    .head-menu ul {
         list-style: none;
         position:relative;
    
    }
    
    .head-menu li a {
        color: #FFFFFF;
        line-height: 2.7;
        line-width: 10px;
        font-size: 17px;
        text-align: left;
        text-decoration: none;
        text-transform: capitalize;
        font-family: "Times New Roman";
        color: rgb(255, 255, 255);
        text-shadow: 0px 2px 1.96px rgba(0, 0, 0, 0.26);
        -moz-transform: scale(1.39, 1.31);
        -webkit-transform: scale(1.39, 1.31);
        -ms-transform: scale(1.39, 1.31);
        position: relative;
        float: left;
        left: -53px;
        top: 2px;
    
        } 
    
    
    
    
        .home {
            margin-left:35px;
            }
        .allfiles {
            margin-left:70px;
            }
    
        .ulpd_by_usrs {
            margin-left:100px;
            }
    
        .upld_frm_mob {
            margin-left:130px;
            }
        .contact {
            margin-left:102px;
            }   
    /*-----------------------------Horizontal Menu Ends----------------*/
    
    /*--------------------------------------Top 20 Files Starts----------------------------*/
    
    .Categories_Box1 ul {
      position: relative;
      list-style:none;
      left: 0px;
      top: 0px;
      width: 1600px;
      height: 1584px;
      z-index:96;
    
    }
    
    .Categories_Box1 li a {
      font-size: 22px;
      font-family: "Exo";
      position:relative;
      text-decoration:none;
      color: rgb(107, 107, 107);
      font-weight: bold;
      line-height: 2;
      -moz-transform: matrix( 0.76907888849934,0,0,0.58955579248353,0,0);
      -webkit-transform: matrix( 0.76907888849934,0,0,0.58955579248353,0,0);
      -ms-transform: matrix( 0.76907888849934,0,0,0.58955579248353,0,0);
      left: -34px;
      top: 38px;
      z-index:97;
    }
    
    
    .t20_files {
      font-size: 29px;
      font-family: "Exo";
      color: rgb(237, 106, 61);
      font-weight: bold;
      line-height: 0.869;
      position: absolute;
      left: 227.937px;
      top: 734px;
      z-index:95;
    
    }
    
    
      .Rectangle1 {
      background-color: rgb(107, 107, 107);
      position: absolute;
      left: 231px;
      top: 799px;
      width:  218px;
      height: 5px;
      z-index: 94;
    }
    
    
    
    
    .Outside_box1 {
      border-style: solid;
      border-width: 1px;
      border-color: rgb(217, 217, 217);
      border-radius: 5px;
      background-color: rgb(242, 242, 242);
      box-shadow: 0px 1px 2px 0px rgba(0, 0, 0, 0.36);
      position: absolute;
      left: 219px;
      top: 748px;
      width: 210px;
      height: 326px;
      z-index: 92;
    }
    
    .Inside_Box1 {
      border-radius: 5px;
      background-color: rgb(255, 255, 255);
      position: absolute;
      left: 221px;
      top: 749px;
      width: 235px;
      height: 326px;
      z-index: 93;
    }
    
    .line10 {
      font-size: 28.12px;
      font-family: "Arial";
      color: rgb(221, 221, 221);
      line-height: 4.2;
      position: absolute;
      width:220px;
      left: 8.2px;
      top: -5.75px;
    }
    .line11 {
      font-size: 28.12px;
      font-family: "Arial";
      color: rgb(221, 221, 221);
      line-height: 4.2;
      position: absolute;
      width:220px;
      left: 8.2px;
      top: 35.75px;
    }
    .line12 {
      font-size: 28.12px;
      font-family: "Arial";
      color: rgb(221, 221, 221);
      line-height: 4.2;
      position: absolute;
      width:220px;
      left: 8.2px;
      top: 80.25px;
    }
    .line13 {
      font-size: 28.12px;
      font-family: "Arial";
      color: rgb(221, 221, 221);
      line-height: 4.2;
      position: absolute;
      width:220px;
      left: 8.2px;
      top: 123.75px;
    }
    
    .line14 {
      font-size: 28.12px;
      font-family: "Arial";
      color: rgb(221, 221, 221);
      line-height: 4.2;
      position: absolute;
      width:220px;
      left: 8.2px;
      top: 168.25px;
    }
    
    
    /*-----------------Top 20 Files Ends----------------------------*/
    

    如果您有任何其他方法可以只使用一行而不是在每个列表项之后使用 p 类标记,请发布它,以便我可以缩短我的代码。这是 JS Fiddle 链接:- JS Fiddle Link

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-10
      • 2018-11-14
      • 2021-04-30
      • 2015-06-12
      • 1970-01-01
      相关资源
      最近更新 更多