Stripes Border like sample image css

巧了我就是萌 提交于 2019-12-20 04:24:20

问题


I want to create a striped border.

I want to use the img tag or div tag to include the image on top of the Striped Border.

This is how it needs to look like:

Now I am trying like this with border image as svg.

.feed-item:after {
  background: #0055b9;
  background: url(../images/studentslab_hover_stripe_bg.svg);
  background-repeat: no-repeat;
  background-size: 100% 100%;
  padding: 4vw 2.7vw 2vw 2vw;
  width: 104%;
  opacity: 0;
}

.feed-item:hover:after {
  opacity: 1;
  z-index: -1;
}

But in responsiveness, it's not covering full sometimes because my striped background image has dimension height and width.

So I want to use it like a border. Is there any way?


回答1:


You can consider a multipe background coloration like below:

.box {
  width: 100px;
  height: 200px;
  border-right:  10px solid transparent;
  border-bottom: 10px solid transparent;
  background: 
   linear-gradient(#fff,#fff) center/calc(100% - 2px) calc(100% - 2px) padding-box,
   linear-gradient(blue,blue) padding-box,
   linear-gradient(#fff,#fff) top right  /10px 10px border-box,
   linear-gradient(#fff,#fff) bottom left/10px 10px border-box,
   /* you can replace this gradient with your SVG*/
   repeating-linear-gradient( -45deg, 
     transparent 0, transparent 2px, 
     blue 2px, blue 4px) border-box;
   /**/
  background-repeat:no-repeat;
  display:inline-block;
}
<div class="box"></div>
<div class="box" style="width:200px;"></div>
<div class="box" style="width:200px;height:100px"></div>



回答2:


Use a repeating linear gradient on the pseudo-element and then position it absolutely behind the parent div.

The move it on hover.

div {
  width:150px;
  height: 200px;
  margin:1em auto;
  border:2px solid green;
   position: relative;
  background: white;
}

div:after {
  content:"";
  position: absolute;
  z-index:-1;
  top:0;
  left:0;
height:100%;
  width:100%;
   background: repeating-linear-gradient(
   -45deg, 
   transparent 0, 
   transparent 4px, 
   blue 4px, 
   blue 8px);
  transition:all .25s ease;
  
}

div:hover::after {
  left:8px;
  top:8px;

}
<div>Hover me</div>


来源:https://stackoverflow.com/questions/53893004/stripes-border-like-sample-image-css

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