alligator might not be the right word; I welcome a correction to the title.
I'd like container to have alligator border like in the picture bellow.
If the element in question had solid background, then pseudo-element trickery or CSS3 border-image
could be used. However, in this case, the content of the container is a non repeating pattern.
Alternatively, it is possible for the image itself to have the border. However, because of the way image expands (animation used to reveal the image), that's not possible.
The only alternative I can think is SVG.
Depending on your backwards compatibility requirements, CSS3
border-image
property might be suitable.See: http://www.w3.org/TR/css3-background/#border-images
They work in the latest versions of all browsers: http://caniuse.com/#search=border-image
Finally, here's a tool for playing with them: http://border-image.com/
Update:
As long as the background behind the image has a solid background,
border-image
can work. Just include an inner<div>
with the sawtooth border.HTML
CSS
Demo here
Here is a possible solution. Use a diamond-shaped PNG and set it as multiple backgrounds within the container. You will have to figure out a way to scale the diamond so that it fills the edges properly (Perhaps use SASS?).
Set the diamond to repeat along the edges.
Here is a quick example: http://codepen.io/KurtWM/pen/tnzwj
And here is the SASS code for it. The
#container
is just a DIV:In case you are not familiar with the way multiple backgrounds work; you separate the parameters by a comma. This is easiest if you use the
background
shorthand property. In the case of thebackground-size
property, there is no place in the shorthand for those values, so we just need to make sure we also put in the multiple values separated by commas, making sure they are in the same order as the shorthand properties.One can use mask-box-image in webkit browsers, which works similarly to border-image as following:
Apply this to your desired element (see syntax):
Example SVG (could be smaller):
The following also works for Firefox with the provided SVG:
Keep in mind however, that the mask path must be converted to relative values (0 to 1) and the mask must have “maskUnits="objectBoundingBox" maskContentUnits="objectBoundingBox"” set. In my example, I divided all values in the path by 500, which is the original width of the path. It scales a bit and doesn't look as good as the webkit bit, but works well enough.
You can do this in SVG with a mask, a clip-path or a filter. Here is an example using a Clip-path with relative sizing so it will work on content of any size.
This works cross browser (IE9+): http://codepen.io/mullany/pen/eylzt
This is an old thread but if someone else needs to use a zigzag border I've a made a sass mixin for it.
Working example: http://codepen.io/gilbarbara/pen/pvwmEb
Here is one more, though imperfect, solution.
HTML
CSS
http://jsbin.com/emOKIgU/1/
The downside to this solution is that you need to know element height if it is a bottom border. Combined with JavaScript (to calculate element dimensions and update CSS), this works.