How to add a gradient border above image (diagonal border) [duplicate]

Deadly 提交于 2019-12-12 13:46:39

问题


I need to something like this

But above an image, here is my first attempt but it doesn't work

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

And this is my markup (now)

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);
}

回答1:


You need something like this

.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>


来源:https://stackoverflow.com/questions/30807681/how-to-add-a-gradient-border-above-image-diagonal-border

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!