How to use border-image with spritesheets? - css

I'm trying to use spritesheets for my background and border needs. I have a spritesheet of borders and am attempting to use it with border-image, but I'm struggling to understand the interplay of slice and width to carve up a specific region, rather than the whole thing.
Is this possible? Or does border image require a single image asset for slicing?

Related

CSS borders with bezier curves

We all know it's possible to have rounded corners in plain CSS using the border-radius property. Is it also possible to have arbitrary corner shapes, specifically, using cubic-bezier?
It most definitely is, by using CSS masking. If you only care about the shape (so, not the color/thickness/etc that you get when you use the CSS border property) then setting up a "border shape" is identical to using "a clipping mask", with the kind of shape that is set up by border-radius is simply clipping with a "rectangle with rounded corners" mask.
html5rocks.com has lots of examples of absolutely crazy border shapes done this way.

Css sprites and positioning

I am using the awesome compass style to generate sprites for my style sheets. I can generate sprites and use them as backgrounds, which is all working fine.
The problem is that previously I have used background-position to position my backgrounds within an element.
For example here's one:
background: left bottom url('../images/bottom-bg.png) no-repeat;
The height of the containing element is variable, and this places the background on the bottom and works beautifully.
However, if I switch to compass sprites and use #extend .system-bottom-bg;, the background-position property is used to grab the appropriate position of the image from the sprite map.
In such a case, how can I use css sprites and still be able to position the background on the bottom of an element?
Upon further research, it seems that due to the limitations of background-position, this is not possible. A decent list of shortfalls with CSS sprites is outlined here: http://www.onderhond.com/blog/work/css-sprites-pros-and-cons.
As background-position is used to to define the position an image occupies in a sprite sheet, we can't use it to define how that portion of the sprite sheet will appear on the page. The article linked above offers some solutions that may be implemented in the future.
One possible solution is to put the image as the last item in the sprite sheet, and then insert a huge amount of space between this image and the previous image. Obviously this is not a very neat solution, but given that compass does not allow us to set the position of images within a sprite sheet, this is not possible anyway.
My solution was to change my markup so that setting background-position: left bottom is not required, and I can just set the sprite image as the background image.

Can I get these curved corners with CSS?

I need to create this layout and I'd like to do as much of it as possible with CSS, rather than using images and whatever.
As such, how can I do this in CSS? (if at all?)
As you can see, there is the image behind, with the button overlaid with padding. The bit that I'm struggling with is creating the curves on the IMAGE above and to the left of the button and bottom to the right of the button (I've pointed them out on the pic below).
Any help would be great.
Thanks
I know just enough CSS to be dangerous so I can't detail every step, but I think you can approach it like this:
Split the background image into two separate images both at a z-index of 0 at the height of the top of the grey box. I think you can use two div's that reference the same original image with different offsets (similar to CSS Sprites) but I don't know the details of how to do that. The left edge of the lower div would start where the grey box ends. Round the lower-left corner of each "image" div.
Add the grey box at a z-index of 1 with appropriate rounding, and then the blue box at a z-index of 2, again with appropriate rounding.
The background of the block element containing all of this would also have to be grey to match the grey border and properly fill in grey where your right-most arrow is pointing.
You don't have to split your image at all, only the container divs.
Let me detail a bit:
You can have your image set as a background image instead of putting it in a src attribute of an img tag. This technique is most commonly used when working with CSS sprites.
So, if you have you uppermost div at a constant width and height, if you try to apply the background image in it, you'll see it fits very nice.
On the bottom, you have two divs or whatever block element you'll like, just be sure to put fixed width and height, so the background will be applied and you will be able to actually see it.
Then all you have to do is fiddle with css background-position to adjust the SE chunk of image.
I'll be putting a small demo together to better illustrate the idea.
After you have a big div at the top, and two smaller at the bottom, where two of them share the same background-image, but with different background-position, you can safely add some css3 border-radius to fit your roundness needs. You can also use some tool like http://css3generator.com/ to add a compatibility layer on all browsers with ease.
That is very easy to realize with pure css. The page you have shown is divided into 3 divs without any margin. You only need to set the right border radius for each div.
This is a function of the background image, which is a css element if that's what you mean, but it is not a seperate attribute for a selector, at least not in standard CSS. Wait until CSS3 becomes more prevelant, then it's corner-radius or some such thing.
Well it's 3 probably 3 seperate divs, a hole "burned" into the background image, or a div being overlayed for the button.
The best way to figure out how it's done is to read the source of the page you found it on.
For convenience:
If you have a webkit based browser like chrome or safari then enable developper mode mouse over the button "right click" and choose inspect element. Otherwise you can pour over the page source until you find what you want.

Circular background behind a transparent png image

I have a div that contains a background image of size 64x64. I would like to give this div a circular shadow or radial background when the user hover's over the div with the mouse.
If I simply give the div a box shadow, the shadow is cast around in a square shape. If I make the div have a radius, then I will need to make my div bigger than 64x64 so that it doesn't crop?
Have a look at at the following example that illustrates what I am trying to describe:
http://jsfiddle.net/rNeaZ/2/
The 4th example (shown in link above) in particular doesn't suit what I am after because:
it's size is much larger than my 64x64 image
the image looks to have a circular border now, which is not what I want; I am after a circular shadow or background behind it
It will probably just be easier and more effective and more efficient to add a nice radial shadow to an image sprite and change the location of the background image on hover.
The simplest solution would be to add an appropriate background-color, but that would only work when you need an offset of 0 0, like your example.
The more general case would be to create a pseudo-element and apply the shadow and background color to that. I can describe this in more detail if the first idea doesn't apply to your case.

CSS - Top left corner background image (curved)

I am currently making a website here. And to the right is a postcode search div. The top corner of that needs to be rounded.
I am using images to round the corners. I do not want to use another method unless it fully supports all browsers, up until IE7.
I have already done this on the navigation (to the left. only top right and bottom left corners). But I cannot seem to get it to work for the top left corner. Please help. This may be a silly little mistake I have made.
If the "postcode search div" is fixed width and height (as it appears to be), the simplest solution would just be to do the entire thing as an image, and set that as the background:
(yes, the images are the correct size and colour)
The problem is that your background color is covering your image. If you remove the background-color property, you will see the corner image.
Take your image http://molossi.psm2.co.uk/assets/images/li-bg-tl.png and add in the grey background with it. Set the width and height of the entire grey background element to 225x120 or whatever you want and you will be good to go. Basically move from it being just the corner image piece to the full image.
If you don't want to do it this way then take your corner image and make it 225px in length with the grey extending out all the way.
There are two methods for creating round corners without using border-radius (CSS3) and without using images:
Use four small divs of height: 1px and progressively increasing widths that create the round corner illusion. This is probably the better option. For a code sample, see the following site:
http://webdesign.about.com/od/css/a/aa072406.htm
Use an HTA file and browser hacks. I've never tried this personally. For code samples and techniques, see the following site
http://jonraasch.com/blog/css-rounded-corners-in-all-browsers
For older browser support using images is the best and probably only option. If you don't mind lower levels of browser support CSS3 Rounded Corners (in the CSS3 Boarders page of W3Schools) may have your answer.

Resources