Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use border image along one side only?

Tags:

html

css

I have an image that I'd like to set as the border on an element, but only as the bottom border: the border image <- It's teeny - but it's right there.

Here is what I've got so far:

<style>
body { margin: 0; padding: 10px; }
    h1 {
background-color: red;
    border: solid transparent;
    border-width: 2px;
    border-image: 2 repeat url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAADCAYAAACqPZ51AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAB9JREFUeNpiZGBgOMOABv7//48uxMDEQCQgWiFAgAEAjqADz4EvP7IAAAAASUVORK5CYII=");
}
</style>
<h1>Bacon</h1>
<p>Bacon ipsum dolor sit amet tenderloin drumstick ribeye filet mignon t-bone beef ribs. Tri-tip venison turkey salami drumstick chicken pastrami. Frankfurter pork jowl ball tip tail.</p>

Or see JS Fiddle: http://jsfiddle.net/eqpt5/.

As you can see, this puts the border image on both the top and bottom (and the sides - though you can't see it). How can I put a border image on only the bottom using border-image?

like image 359
KatieK Avatar asked Nov 21 '12 04:11

KatieK


People also ask

How do I make one sided border in CSS?

If you want to set a border to just one side of the element, use four values (write none to the side you want no border to appear). If you want to set a border to the top and bottom sides, use two values (write none to the second value).

How does border-image-slice work?

The border-image-slice property specifies how to slice the image specified by border-image-source. The image is always sliced into nine sections: four corners, four edges and the middle. The "middle" part is treated as fully transparent, unless the fill keyword is set.

How can Borders be set for an image?

The <img> border attribute is used to specify the border width around the image. The default value of <img> border attribute is 0. It is not supported by HTML 5. Use CSS instead of this attribute.


1 Answers

Change border-width:2px to border-width:0 0 2px

In this way you are actually setting border bottom width 2px and other sides width equal to zero

Demo http://jsfiddle.net/naveenksh/eqpt5/3/

like image 97
Naveen Sharma Avatar answered Sep 24 '22 08:09

Naveen Sharma