【问题标题】:How to add a gradient border above image (diagonal border) [duplicate]如何在图像上方添加渐变边框(对角线边框)[重复]
【发布时间】:2017-12-23 18:43:51
【问题描述】:

我需要这样的东西

但在图片上方,这是我的第一次尝试,但它不起作用

http://jsfiddle.net/wo8gbhx3/17/

这是我的标记(现在)

HTML

<div class="testing">
    <ul>
        <li class="selected unavailable">
            <a href="#">
                <img src="http://placehold.it/25x25"/>
            </a>
        </li>
    </ul>
</div>

CSS

.testing ul {
    list-style: none;
}
.testing ul li {
    width: 25px;
    height: 25px;
    position: relative;
}
.testing ul li img {
    width: 100%;
    height: 100%;
}
.unavailable:before {
    position: absolute;
    border: 2px solid green; /* Just for testing */
    background:repeating-linear-gradient( 150deg, #FFF, #FFF 16px, #000 18px);
}

【问题讨论】:

    标签: html css css-shapes


    【解决方案1】:

    你需要这样的东西

    .testing ul {
      list-style: none;
    }
    .testing ul li {
      width: 250px;
      height: 250px;
    }
    .testing ul li img {
      width: 100%;
      height: 100%;
      display: block;
    }
    .unavailable {
      position: relative;
    }
    .unavailable a:after {
      content: '';
      width: 100%;
      height: 100%;
      top: 0;
      left: 0;
      position: absolute;
      border: 2px solid green;
      /* Just for testing */
      background: repeating-linear-gradient(150deg, transparent, transparent 16px, #000 18px);
      z-index: 2;
    }
    <div class="testing">
      <ul>
        <li class="selected unavailable">
          <a href="#">
            <img src="http://placehold.it/200x200" />
          </a>
        </li>
      </ul>
    </div>

    【讨论】:

    • 可能受益于使用 rightbottom 的 0 并且没有宽度和高度,或者您可以添加 box-sizing:border-box 到它。这样可以防止右侧和底部出现难看的白色间隙。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-02
    • 1970-01-01
    • 1970-01-01
    • 2022-01-14
    • 1970-01-01
    • 2016-06-25
    • 1970-01-01
    相关资源
    最近更新 更多