Web Designer Wall

A wall of design ideas, web trends, and tutorials

Decorative CSS Gallery – Part 2 72

TutorialsCSS

Long ago I wrote a tutorial on how to make decorative image galleries using an extra <span> tag. It requires jQuery to append the span tag which isn't quite user friendly. Today I'm going to share a better method without using Javascript. The same result can be achieved by using :before or :after pseudo element. The :before element is one of the commonly under used elements, but it is quite useful for adding additional elements or content. Learn it now and start using it.

View DemoDecorative Gallery

HTML

Below is a sample image gallery markup in a <ul> list.


<ul>
	<li>
		<img src="/img/spacer.gif"> 

CSS

Below is the base style for the .gallery. The key property you have to add is relative position on the .gallery a element.


.gallery {
	margin: 0 0 25px;
	text-align: center;
}
.gallery li {
	display: inline-block;
	margin: 5px;
	list-style: none;
}
.gallery a {
	position: relative;
	display: inline-block;
}

:before element

Now I'm going to specify a 30 x 60px container with the paper clip background image to the a:before element. Note that I leave the content property empty in the CSS rule. Without the empty content property, the container will not appear.

spacer

.clip a:before {
	position: absolute;
	content: ' ';
	top: -5px;
	left: -4px;
	px;
	px;
	"webdesignerwall.com/wp-content/uploads/2012/09/art-frame.jpg" align="before element">


.frame a:before {
	position: absolute;
	content: ' ';
	top: -22px;
	left: -23px;
	px;
	px;
	"webdesignerwall.com/wp-content/uploads/2012/09/tape-gallery.jpg" align="before element">


<ul>
	<li>
		<figure> 
			<img src="/img/spacer.gif"> 

CSS

In the CSS, I added two :before elements: one on the <figure> element and another one on the <li> element. The overlay.png (mask image) is applied to the figure:before element and the tape graphic is applied on the a:before element.

spacer

.tape li {
	px;
	padding: 5px;
	margin: 15px 10px;
	border: solid 1px #cac09f;
	background: #fdf8e4;
	text-align: center;
	box-shadow: inset 0 1px rgba(255,255,255,.8), 0 1px 2px rgba(0,0,0,.2);
}
.tape figure {
	position: relative;
	margin: 0;
}
.tape a:before {
	position: absolute;
	content: ' ';
	top: 0;
	left: 0;
	%;
	%;
	"webdesignerwall.com/wp-content/uploads/2012/09/transform-gallery.jpg" align="before element">


.transform li:nth-of-type(4n+1) {
	-webkit-transform: rotate(2deg);
}
.transform li:nth-of-type(2n) {
	-webkit-transform: rotate(-1deg);
}
.transform li:nth-of-type(4n+3) {
	-webkit-transform: rotate(2deg);
}

Update:

I've updated the gallery demo and CSS so now the images are linked. Now the :before element is added to the tag.

Share → Tweet

72 Comments

  1. spacer Get your home cleaned

    Hello !
    It’s totally new to me. I really liked :before element. It is too much impressive. The way you have explained each and every step is appreciable.
    Thanks a lot.
    Get your home cleaned

  2. spacer ThemeSquirrel

    Awesome tutorial! I’ve been trying to figure this out for a while, Thanks for sharing!

  3. spacer online careers

    Hello! Do you know if they make any plugins to assist
    with Search Engine Optimization? I’m trying to get my blog to rank for some targeted keywords but I’m
    not seeing very good gains. If you know of any please share.

    Appreciate it!

    online careers

  4. spacer dolat ram

    superb

Leave a Reply

Cancel

Collapse all
Expand all

Recent Posts

  1. spacer
    Themify.me Theme Released

  2. spacer
    4 Fantastic Years of Themify + Giveaways

  3. spacer
    50 Business Cards That Are Way Too Creative To Ever Throw Away

Recent Comments

  1. spacer
    Humayun Hashmi: Nice theme, I liked the way they represent the portfolio and…
  2. spacer
    Afzaal: Very simple yet elegant theme. …
  3. spacer
    Nick La: We are running a Fall Sale on themify.me until the en…

About

Web Designer Wall is all about design, ideas, web trends, and tutorials. It is designed and maintained by Nick La, who also runs N.Design Studio, Themify, IconDock, and Best Web Gallery.

© Web Designer Wall 2014

Back to top