Place background image outside border of containing div

I am trying to set a background image to be outside the actual containing div. Show Details .expandable background: transparent url(‘./images/expand.gif’) no-repeat -20px 0px;so the “expand” image should basically appear just to the left of the div.I can’t get this working, the image doesn’t show when it’s positioned outside …

via Css Website development » Search Results » ajax:

Place background image outside border of containing div

I am trying to set a background image to be outside the actual containing div.

.expandable

background: transparent url(‘./images/expand.gif’) no-repeat -20px 0px;
so the “expand” image should basically appear just to the left of the div.
I can’t get this working, the image doesn’t show when it’s positioned outside the borders of the container. I’m not sure if there’s a CSS trick I am missing, or if it’s something to do with my page layout (the “expandable” div is nested inside several other divs).
Is it possible to do this? Any hints?
Edit: here is a jsFiddle showing the problem: link
…………………………………….

You’re going to have to put the background image inside a separate element. Background image positions cannot place the image outside the element they’re applied to.
edit your question jogged my memory and I went and checked the CSS specs. There is in fact a “background-attachment” CSS attribute you can set, which anchors the background to the viewport instead of the element. However, it’s buggy or broken in IE, which is why I’ve got it sitting on the “do not use” shelf in my head :-)
…………………………………….

You can’t do this how you want to exactly, but there is a pretty straightforward solution. You can put another div inside of .expandable like:

Then your CSS would look something like:
.expandable position:relative;
.expandable-image
position:absolute; top:0px; left:-20px;
width:px; height:px;
background: url(‘./images/expand.gif’) no-repeat;

…………………………………….

Depending on the details of your situation, you might be able to get away with CSS3′s border-image-* rules. For instance, I used them effectively to place “dummy search buttons” in the filter row of a CGridView widget in yii (clicking anywhere outside the filter’s input boxes will trigger the ajax call, but these “buttons” give the user something intuitive to do). It wasn’t worth it to me to subclass the CGridColumn widget just to hack the html in its renderFilterCell() method * — I wanted a pure CSS solution.
.myclass .grid-view .items
border-collapse: separate ;

.myclass .grid-view .filters td + td
border-image-source: url(“/path/to/my/img_32x32.png”);
border-image-slice: 0 0 0 100%;
border-image-width: 0 0 0 32;
border-image-outset: 0 0 0 40px;
border-width: 1px;

.myclass .grid-view .filters input
width: 80%;
There is a little bit of a trick involved in the border-image-width values — that 32 is a multiplier not a length (do not put px) of the unit used in border-width (ie 1px). The result is fake buttons in the first n-1 columns of the gridview. In my case, I didn’t need anything in the last column because it is a CButtonsColumn which does not have a filter box. Anyway, I hope this helps people looking for a pure CSS solution ?? :-D
* Not long after writing this, I discovered I can just concatenate code for an image in the ‘filter’ property of the array used to construct the CGridColumn, so my rationale turns out to be moot. Plus there seems to be an issue (in Firefox, anyway) with the border-image-repeat being forced to stretch even when space is specified. Still, maybe this might come in handy for someone ?? :-

For more info: Place background image outside border of containing div

Css Website development » Search Results » ajax

Place background image outside border of containing div

Share this post:

Related Posts

Leave a Comment