Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Border image with opacity

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?

like image 251
Carlos Torres Avatar asked Jul 13 '17 15:07

Carlos Torres


People also ask

Can we give opacity to border in CSS?

Don't think you can change the opacity of a border. however you could use css or jquery to set the opacity of a div then center another div inside that one.

How do I add a transparent border to an image in CSS?

In CSS, we can create a transparent border by using the border property in a nested div tag.

Can you set the border color to transparent?

Defines the color of the element's borders. default border-color: transparent; Applies a transparent color to the borders. The borders will still take up the space defined by the border-width value.


1 Answers

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>
like image 161
Nenad Vracar Avatar answered Sep 17 '22 19:09

Nenad Vracar