Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to offset border image from edge of element?

Tags:

html

css

I have a bottom border image which should be a few (say 3) pixels lower than the actual edge of the element.

Here is what I've got so far:

<style>
h1 { background-color: green;
    border: solid transparent;
    border-width: 0 0 13px;
    border-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAOCAYAAAArMezNAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd0yLESWK5WCoU41EScY5EmozzMqUiiUKSKcUl0v9k4t8s+wM+3zUAsGo+AXuRLahdYwP2SycQWHTA4vcAAPK7b8HUKAgDgGiD4c93/+8//UegJQCAZkmScQAAXkQkLlTKsz/HCAAARKCBKrBBG/TBGCzABhzBBdzBC/x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ttVAVVN1WbVZftJ+7P3P66Jqun4lvttXa1ObXHtxwPSA/0HIw6217nU1R3SPVRSj9Yr60cOxx++/p3vdy0NNg1VjZzG4iNwRHnk6fcJ3/ceDTradox7rOEH0x92HWcdL2pCmvKaRptTmvtbYlu6T8w+0dbq3nr8R9sfD5w0PFl5SvNUyWna6YLTk2fyz4ydlZ19fi753GDborZ752PO32oPb++6EHTh0kX/i+c7vDvOXPK4dPKy2+UTV7hXmq86X23qdOo8/pPTT8e7nLuarrlca7nuer21e2b36RueN87d9L158Rb/1tWeOT3dvfN6b/fF9/XfFt1+cif9zsu72Xcn7q28T7xf9EDtQdlD3YfVP1v+3Njv3H9qwHeg89HcR/cGhYPP/pH1jw9DBY+Zj8uGDYbrnjg+OTniP3L96fynQ89kzyaeF/6i/suuFxYvfvjV69fO0ZjRoZfyl5O/bXyl/erA6xmv28bCxh6+yXgzMV70VvvtwXfcdx3vo98PT+R8IH8o/2j5sfVT0Kf7kxmTk/8EA5jz/GMzLdsAAAAgY0hSTQAAeiUAAICDAAD5/wAAgOkAAHUwAADqYAAAOpgAABdvkl/FRgAAAQZJREFUeNrc0y1LhEEUBeDnyoIfwSzYBX+CG0Qslm0m3bhd2KBs3CSCmMxbBLGtwSKCoL9C2GYVLDZBvJZRXhZfWZEtHrjMnTNnzszc4UZmmgqK8RW2fpBt4h43aGHuG80ctnGemWYK2cI1LtGsiJuFu8U6HjGPQ7QRJdqFW8AzRGaKiPF6DMrYGeN7mXkEEbGPxcK/ZOZx4fcy87RR8/RODT9fKeFxRKyUfDSuafzxf0Z1azOmhP9v/Dap5rfGyxNolqrGZxNsGOApIg7qBBHRw3u1pWENQ+RYDMvaJ3Zxgm4WoFu4dmbKzK/Oqx68gX7J+7j75nKz2MFqmT/gIjNfI0Jm+hgA74lgEBd+SugAAAAASUVORK5CYII=") 1 1 13 1 repeat;
}
</style>

<h1>How to get a border image offset from the edge of the box?</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/BDbX2/1/.

How can I get for the border-image to be a little bit lower, so that the green background of the element doesn't peek out from behind the border-image?

Here is a screenshot showing more of what I'm looking for:

Here is a screenshot showing more of what I'm looking for

Note that above the border, the green is visible and unbroken. But I don't want the green to appear at all below the border.

I'm using Firefox; naturally I'd prefer a solution which worked in multiple (latest version) browsers.

like image 827
KatieK Avatar asked Nov 28 '12 06:11

KatieK


4 Answers

Try this

h1 {    
    background-color: green;
    position:relative;
    padding-bottom:7px; // padding enough to cover the upper part of the border with color
    margin-bottom:6px; // margin + padding should match the height of the border
}
h1:after {
    content:'';
    position:absolute;
    left:0;
    right:0;
    bottom:-7px; // should match padding-bottom of h1
    border: solid transparent;
    border-width: 0 0 13px;
    border-image:url("data:image/png;base64,...") 1 1 13 1 repeat;
}

Demo at http://jsfiddle.net/gaby/BDbX2/7/

like image 145
Gabriele Petrioli Avatar answered Sep 28 '22 08:09

Gabriele Petrioli


border-image-outset

The amount by which the border image area extends beyond the border box

Checkout the following sites for browser support.

http://www.w3schools.com/cssref/css3_pr_border-image-outset.asp https://developer.mozilla.org/en-US/docs/CSS/border-image-outset

like image 27
I29 Avatar answered Sep 28 '22 10:09

I29


If a pseudo element is needed for something else

Personally, I like both I29's border-image-outset property solution (though only supported in two browsers as of this writing) and secondly Gaby's pseudo element solution as the code is clean and short. However, for Gaby's, if you need the pseudo element for something else, then you can use a gradient background with a small transparent strip at the bottom and the background-origin: border-box set. See fiddle. Adding this CSS (only tested in Firefox 17 and Chrome 23):

background: -moz-linear-gradient(top,  rgba(41,154,11,1) 0%, rgba(41,154,11,1) 90%, rgba(41,154,11,0) 91%, rgba(41,154,11,0) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(41,154,11,1)), color-stop(90%,rgba(41,154,11,1)), color-stop(91%,rgba(41,154,11,0)), color-stop(100%,rgba(41,154,11,0))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top,  rgba(41,154,11,1) 0%,rgba(41,154,11,1) 90%,rgba(41,154,11,0) 91%,rgba(41,154,11,0) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top,  rgba(41,154,11,1) 0%,rgba(41,154,11,1) 90%,rgba(41,154,11,0) 91%,rgba(41,154,11,0) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top,  rgba(41,154,11,1) 0%,rgba(41,154,11,1) 90%,rgba(41,154,11,0) 91%,rgba(41,154,11,0) 100%); /* IE10+ */
background: linear-gradient(to bottom,  rgba(41,154,11,1) 0%,rgba(41,154,11,1) 90%,rgba(41,154,11,0) 91%,rgba(41,154,11,0) 100%); /* W3C */

background-origin: border-box; 
like image 23
ScottS Avatar answered Sep 28 '22 10:09

ScottS


After reading your problem and reading on the css3 border-image property I didn't find any proper solution for a css3 property, so I just created an image if no one has a solution on the border-image property.

I have added below rule on h1 tag :

 h1{
    background: url("http://www.imageurlhost.com/images/ekzlrnp7tsnxx0uner.png") repeat-x scroll 0 47px green;

/* reset css rules are same as provided in question */
    }

Note: According to this technique you may not face any issues while changing background color from green to red or any other color.

Here is the solution of the above problem. see my fiddle

For Full View: http://jsfiddle.net/BDbX2/24/embedded/result/

Please let me know if any suggestion for me or any enhancement in idea.

Screen shot for visibility:

enter image description here

like image 35
w3uiguru Avatar answered Sep 28 '22 09:09

w3uiguru