0

I have a PNG which is 10px x 1px and I need to use it for a border-image but for some reason the image doesn't repeat. It appears in the corners but not all the way? What am I doing wrong?

#border {
  width: 200px;
  height: 100px;
  border: 1px dashed transparent;
  border-image: url(https://image.ibb.co/byABRJ/border.png) 1 100% repeat;
  background: yellow;
  text-align: center;
  line-height: 100px;
}
<div id="border">
  bordered area
</div>
Andrew Bone
  • 7,092
  • 2
  • 18
  • 33
Ukuser32
  • 2,147
  • 2
  • 22
  • 32

4 Answers4

2

Wrong start, it's 0 not 100

  border-image: url(https://image.ibb.co/byABRJ/border.png) 1 0% repeat;
Syneria Fana
  • 153
  • 12
1

The parameter you set to 100% is border-image-width, I think you want it to be 1 (or you can omit it, I think it's 1 by default).

 <!DOCTYPE html>
 <html lang="en">
  <head>
   <style>
    #border {
     width:200px;
     height:100px;
     border:1px dashed transparent;
     border-image: url(https://image.ibb.co/byABRJ/border.png) 1 1 repeat;
     background:yellow;
     text-align:center;
     line-height:100px;
    }
   </style>
  </head>
  <body>
   <div id="border">
    bordered area
   </div>
  </body>
 </html>

Source: https://www.w3schools.com/cssref/css3_pr_border-image.asp

EDIT: If you want your border-image to be the same on the left/right edges you'll have to add those to the source image you're using. Take a look at this https://css-tricks.com/almanac/properties/b/border-image/

Jonas Grumann
  • 10,438
  • 2
  • 22
  • 40
0

You can also use this way.

#border {
   width:200px;
   justify-content: center;
   align-items: center;
   display: flex;
   height:100px;
   border-top:1px dashed blue;
   border-bottom:1px dashed blue;
   background:yellow;
}
       
    <!DOCTYPE html>
     <html lang="en">
      <head>
       <title>Test</title>
      </head>
      <body>
       <div id="border">
        bordered area
       </div>
      </body>
     </html>
Ankit Jaiswal
  • 274
  • 2
  • 8
0

In the end building an image which CSS then used for the border proved too time consuming. Instead I found:

How to increase space between dotted border dots

And have posted an answer with my solution there. Although not a direct-fix to the presented question it solves it and without images which for me was easier.

Ukuser32
  • 2,147
  • 2
  • 22
  • 32