6

I have this:

.striped-border {
    border: 8px solid transparent;
    border-image: url(../img/stripes.png) 9 round;
}

Content with a border-image

What I want:

enter image description here

Is it possible to apply an opacity to the border-image only and not the content?

Carlos Torres
  • 419
  • 2
  • 9
  • 19

2 Answers2

8

You can use pseudo-element to create border with border-image and then set opacity.

div {
  position: relative;
  margin: 50px;
  font-size: 25px;
  padding: 10px 25px;
  display: inline-block;
}
div:after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  border: 5px solid transparent;
  border-image: url('http://www.circlek.org/Libraries/2013_branding_design_elements/graphic_CKI_horizontal_stripesblue_RGB.sflb.ashx') 22 22 repeat;
  transform: translate(-5px, -5px);
  opacity: 0.4;
}
<div>Element</div>
<div>Element <br> lorem</div>
Nenad Vracar
  • 118,580
  • 15
  • 151
  • 176
  • Follow-up question: When adding a form, with an input and button, they show but apparently disabled. Any idea to enable them? Thanks again! https://jsfiddle.net/bu6xt7pc/3/ – Carlos Torres Jul 13 '17 at 20:49
2

What about something like it:

.striped-border:after{
    content:"";
    position:absolute;
    top:0; bottom:0; left:0; right:0;
    border:8px solid rgba(256,256,256, 0.5);
}
Mohsen
  • 309
  • 3
  • 15