【问题标题】:Create list with triangles on the right side CSS在 CSS 右侧创建带有三角形的列表
【发布时间】:2015-12-04 00:16:17
【问题描述】:

我正在尝试在图像上创建一个列表,但我不知道该怎么做。到目前为止,我已经这样做了,但似乎我做得不对:

到目前为止我的工作:

#side-menu li:nth-child(even) {
background: rgb(0,169,148);
background: -moz-linear-gradient(left, rgba(0,169,148,1) 1%, rgba(0,84,166,1) 100%);
background: -webkit-gradient(linear, left top, right top, color-stop(1%,rgba(0,169,148,1)), color-stop(100%,rgba(0,84,166,1)));
background: -webkit-linear-gradient(left, rgba(0,169,148,1) 1%,rgba(0,84,166,1) 100%);
background: -o-linear-gradient(left, rgba(0,169,148,1) 1%,rgba(0,84,166,1) 100%);
background: -ms-linear-gradient(left, rgba(0,169,148,1) 1%,rgba(0,84,166,1) 100%);
background: linear-gradient(to right, rgba(0,169,148,1) 1%,rgba(0,84,166,1) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00a994', endColorstr='#0054a6',GradientType=1 );
border-top: 13px solid transparent;
border-bottom: 13px solid transparent;
border-left: 10px solid rgba(0,84,166,1);
}

和现在的样子:

以及应该如何:

【问题讨论】:

标签: css html-lists css-shapes


【解决方案1】:

这个问题有多种解决方案。既然你已经开始使用 CSS3,here's my approach using CSS only.

这里所做的基本上是滥用空 HTML 元素周围的边框。通过不设置右边框,它被设置为 0。然后调整其他边框以适应边框,这恰好导致创建箭头形状。

因此,修改箭头的大小/形状可能有点棘手(有多种选择;我更喜欢当前情况):

  • <li> 设置行高,以便更容易确定正确的箭头高度。
  • 要调整箭头大小,您必须将li:after 的宽度border-topborder-bottom 设置为<li> 元素的line-height + padding-top + padding-bottom 值的50%。李>
  • 通过调整border-left,您可以确定箭头的长度。
  • 最后,margin-topli + li 将定义箭头之间的间距。

由于您的图片还暗示了一些悬停颜色,因此here 也可以看到。虽然重要的是要注意,到目前为止,过渡不适用于渐变。

当然,使用固定图像作为背景会更加向后兼容旧版浏览器,但这也取决于

【讨论】:

    【解决方案2】:

    您可以使用http://cssarrowplease.com/ 网站创建全方位的自定义箭头。将高度更改为您需要的任何高度。然后,您可以调整样式以获得您所需要的。

    【讨论】:

      【解决方案3】:

      这是一种方法:

      小提琴: http://jsfiddle.net/SM2NR/

      #side-menu li:after {
          content: "";
          position: absolute;
          right: -20px;
          top: -13px;
          width: 0;
          height: 0;
          border-top: 22px solid transparent;
          border-left: 20px solid #0054A6;
          border-bottom: 22px solid transparent;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-05-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多