Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="center">
	<h2>Click on a picture to launch the lightbox</h2>
	<a href='http://www.jpg-design.com/menu/home' class='blue'>www.jpg-design.com</a>
</div>
<article class=border>
	<section class=grid-container>
		<div class=item>
			<figure title='Agrandir'>
				<img itemprop='image' src='https://unsplash.it/600/400?random=1' alt='txt' class=bitmap />
				<figcaption>description</figcaption>
			</figure>
		</div>
<div class=item-txt>
  <div>
		<h2>Title</h2>
			<p>Project : Lightbox</p>
					Some text
	</div>
	</section>				
	<section class=grid-container>
		<div class=item>
			<div>
			<div class='figure-text'>
				<h2>Title</h2>
			<p>Project : Lightbox</p>
					Some text
			</div>
<!-- wrap img with figure -->
				<figure title='Agrandir'>
					<img itemprop='image' src='https://unsplash.it/600/400?random=2' alt='txt' class=bitmap />
<!-- figcaption is useful but not mandatory -->
					<figcaption>description</figcaption>
				</figure>
<!-- wrap img with figure end -->
			</div>
		</div>
		<div class='item-txt'>
			<div>
				<div class='figure-text'>
					<h2>Title</h2>
			<p>Project : Lightbox</p>
					Some text
				</div>
				<figure title='Agrandir'>
					<img itemprop='image' src='https://unsplash.it/600/400?random=3' alt='txt' class=bitmap />
					<figcaption>description</figcaption>
				</figure>
		</div>
	</section>
	<section class='grid-container'>
		<div class='item'>
			<figure title='Agrandir'>
				<img itemprop='image' src='https://unsplash.it/600/400?random=4' alt='txt' class=bitmap />
				<figcaption>description</figcaption>
			</figure>
		</div>
		<div class='item-txt'>
			<figure title='Agrandir'>
				<img itemprop='image' src='https://unsplash.it/600/400?random=5' alt='txt' class=bitmap />
				<figcaption>description</figcaption>
			</figure>
		</div>
	</section>
</article>
<!-- lightbox -->
<div id="lightbox" class="hide">
	<!-- controls / figure -->
	<div id="lightbox_flex">
		<!-- previous button -->
		<div id="prev">
			<svg viewBox="0 0 20 36" fill-rule="evenodd" clip-rule="evenodd" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="1.5" fill="none" stroke-width="1">
				<path d="M17.9 2.4L2.3 18 18 33.6"/>
			</svg>
		</div>
		<div id="placefig">
			<div id="lightbox_top">
				<!-- counter -->
				<div id="counter_div">
					<span id="current_index"></span>
					<span id="total_index"></span>
				</div>
				<!-- close button -->
				<div id="close_btn">
					<span id="close_txt" class="uppercase_font">Fermer</span>
						<svg viewBox="0 0 18 18" width="18" height="18" fill-rule="evenodd" clip-rule="evenodd" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="1.5" fill="none" stroke-width="1">
							<path d="M16.5 1.5l-15 15M1.5 1.5l15 15"/>
						</svg>
					</span>
				</div>
			</div>
		</div>
		<!-- next button -->
		<div id="next">
			<svg viewBox="0 0 20 36" fill-rule="evenodd" clip-rule="evenodd" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="1.5" fill="none" stroke-width="1">
				<path d="M2 2.3L17.6 18 2 33.4"/>
			</svg>
		</div>
	</div>
</div>

              
            
!

CSS

              
                html {
	--txt: #ccc;
	--hover: #fa4b2c;
}
.center {text-align: center;padding:1em;}
/* elements display */
.hide {display: none;}
.bitmap {
	max-width: 100%;
	height: auto;
}
figure {cursor: zoom-in;}
figcaption{
	color: #999;
	text-align: center;
	padding-top: 1.5em;
}
/* lightbox css */
#lightbox {
	position: fixed;
	z-index: 9;
	text-align: center;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	padding: 1em;
	background: rgba(0, 0, 0, .8);
	/* Enable scroll if needed */
	overflow: auto;
}

#lightbox_flex {
	display: flex;
	justify-content: center;
}

#placefig {
	width: 100%;
}

#placefig > figure {
	cursor: default;
}

#placefig > figure > .bitmap,
#placefig > figure > picture > img {
	width: auto;
	max-height: 90vh;
}

/* Close button */
#lightbox_top {
	display: flex;
	justify-content: space-around;
	color: var(--txt);
}

#counter_div {
	margin-left: 1em;
	line-height: 2.4em
}

#close_btn {
	user-select: none
}

#close_btn:focus,
#close_btn:hover {
	color: var(--hover);
	text-decoration: none;
	cursor: pointer
}

#close_txt {
	margin-right: .4em
}

#close_btn > svg {
	stroke: var(--txt);
	vertical-align: sub;
}

#close_btn:hover > svg {
	stroke: var(--hover);
	stroke-width: 2px;
}

#current_index,
#total_index {
	color: var(--txt);
}

/* Next & previous buttons */
#next,
#prev {
	cursor: pointer;
	user-select: none;
	padding: 1em;
	height: max-content;
	margin-top: 4em;
}

#next > svg,
#prev > svg {
	width: 20px;
	height: 36px;
	stroke: var(--txt);
	vertical-align: middle;
}

#next > svg {
	margin-left: 10px;
}

#prev > svg {
	margin-right: 10px;
}

#next:hover,
#prev:hover {
	background-color: #000
}

#next:hover > svg,
#prev:hover > svg {
	stroke: #ace3cc;
	stroke-width: 2px;
}

/* Next & previous buttons breakpoint */
@media (max-width: 400px) {

	#next,
	#prev {
		padding: 4px;
	}

	#prev > svg,
	#next > svg {
		width: 10px;
		height: 18px;
	}

	#prev > svg {
		margin-right: 4px;
	}

	#next > svg {
		margin-left: 4px;
	}

}

/* Number text (1/3 etc) */
.numbertext {
	color: var(--txt);
	font-size: 12px;
	padding: 8px 12px;
	position: absolute;
	top: 0
}
/* place your css here ************************************/
.grid-container {
	display: grid;
	grid-template-columns: 1fr 1fr;
	background-color: var(--corporate-white);
}
.border {border: 1px solid var(--corporate-black);}
.item,.item-txt,.item-top {
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 20%;
}
.item,.item-top {
	border-top: 1px solid var(--corporate-black);
	border-right: 1px dashed var(--corporate-black);
	border-bottom: 1px solid var(--corporate-black);
	border-left: 1px solid var(--corporate-black);
}
.item-txt {
	border-top: 1px solid var(--corporate-black);
	border-right: 1px solid var(--corporate-black);
	border-bottom: 1px solid var(--corporate-black);
	border-left: none;
}
@media (max-width: 800px) {
	.grid-container {
		grid-template-columns: auto;
	}
	.item,.item-top {
		border-top: 1px solid var(--corporate-black);
		border-right: 1px solid var(--corporate-black);
		border-bottom: 1px dashed var(--corporate-black);
		border-left: 1px solid var(--corporate-black);
	}
	.item-txt {
		border-top: none;
		border-right: 1px solid var(--corporate-black);
		border-bottom: 1px solid var(--corporate-black);
		border-left: 1px solid var(--corporate-black);
	}
}
/* scroll to Top button */
#topBtn {
	display: none;
	position: fixed;
	bottom: 20px;
	right: 30px;
	z-index: 99;
	font-size: 18px;
	outline: none;
	border: var(--corporate-black) 1px dashed;
	background-color: var(--corporate-white);
	color: var(--corporate-black);
	cursor: pointer;
	padding: 18px;
	border-radius: 3px;
}
#topBtn:hover {
	border: var(--corporate-black) 1px solid;
}
/* variable colors */
:root {
	--corporate: #471a46;
	--corporate-bkg: #ace3cc;
	--corporate-black: #222;
	--corporate-white: #fff;
	--brand-blue: #0071BC;
	--brand-red: #fa4b2c;
}
.red {color: var(--brand-red)}
.blue {color: var(--brand-blue);text-decoration:none;}
a.blue:hover {color: var(--brand-red)}


              
            
!

JS

              
                // figure tag triggers the lightbox :
// get all figures in a Node list
const allFigsNodeList = document.querySelectorAll('figure'),
	// lightbox
	lightBox = document.getElementById('lightbox'),
	placeFig = document.getElementById('placefig'),
	lightboxTop = document.getElementById('lightbox_top'),
	counter = document.getElementById('counter_div'),
	closeBtn = document.getElementById('close_btn'),
	currentIndexTxt = document.getElementById('current_index'),
	totalIndexTxt = document.getElementById('total_index'),
	nextBtn = document.getElementById('next'),
	prevBtn = document.getElementById('prev');

// title loop
defaultTitle();
// loop items
allFigsNodeList.forEach((currentFig, index) => {
	currentFig.onclick = () => {

		openLightBox();
		// hide Buttons;
		hidePrevBtn(index);
		hideNextBtn(index);
		let currentIndex = index + 1;

		displayCurrentIndex(currentIndex);
		totalIndexTxt.textContent = allFigsNodeList.length;

		// clone cliqued figure
		const figClone = currentFig.cloneNode(true);
		// place cliqued figure
		placeFig.appendChild(figClone);
		// prev next buttons
		prevBtn.addEventListener('click', prevFig);
		nextBtn.addEventListener('click', nextFig);

		function prevFig() {
			let prevFig = allFigsNodeList[--index];
			currentIndex = index + 1;
			displayCurrentIndex(currentIndex);
			if (index <= 0) {
				prevBtn.style.visibility = 'hidden';
				prevFig = allFigsNodeList[0];
				index = 0;
				currentIndex = index + 1;
				displayCurrentIndex(currentIndex);
			} else {
				showBtns();
			}
			prevFigClone = prevFig.cloneNode(true);
			placeFig.appendChild(prevFigClone);
			placeFig.removeChild(placeFig.querySelector('figure'));
		}

		function nextFig() {
			let nextFig = allFigsNodeList[++index];
			currentIndex = index + 1;
			displayCurrentIndex(currentIndex);
			if (index >= allFigsNodeList.length - 1) {
				nextBtn.style.visibility = 'hidden';
				nextFig = allFigsNodeList[allFigsNodeList.length - 1];
				index = allFigsNodeList.length - 1;
				currentIndex = allFigsNodeList.length;
				displayCurrentIndex(currentIndex);
			} else {
				showBtns();
			}
			nextFigClone = nextFig.cloneNode(true);
			placeFig.appendChild(nextFigClone);
			placeFig.removeChild(placeFig.querySelector('figure'));
		}
		// close lightBox
		closeBtn.onclick = () => {
			closeLightBox();
		};
		window.onclick = (event) => {
			if (event.target == lightBox) {
				closeLightBox();
			}
		}
		document.onkeyup = (event) => {
			if (event.key === 'Escape') {
				closeLightBox();
			}
		}
		// prev next keys < >
		document.addEventListener('keydown', keyHandler);
		function keyHandler(e) {
			// Left Arrow
			if (e.keyCode === 37 || (e.ctrlKey && e.keyCode === 37)) {
				// e.preventDefault();
				prevFig();
			}
			// Right Arrow
			if (e.keyCode === 39 || (e.ctrlKey && e.keyCode === 39)) {
				// e.preventDefault();
				nextFig();
			}
		}
	}
});

function displayCurrentIndex(currentIndex) {
	currentIndexTxt.textContent = currentIndex + ' / ';
}

function hidePrevBtn(index) {
	if (index == 0) {
		prevBtn.style.visibility = 'hidden';
	} else {
		prevBtn.style.visibility = 'visible';
	}
}

function hideNextBtn(index) {
	if (index == allFigsNodeList.length - 1) {
		nextBtn.style.visibility = 'hidden';
	} else {
		nextBtn.style.visibility = 'visible';
		nextBtn.style.display = 'block';
	}
}

function showBtns() {
	prevBtn.style.visibility = 'visible';
	nextBtn.style.visibility = 'visible';
}

function openLightBox() {
	lightBox.classList.remove('hide');
	allFigsNodeList.forEach(titleTag => {
		titleTag.title = 'touche ESC pour fermer | flèches pour naviguer';
	});
}

function closeLightBox() {
	lightBox.classList.add('hide');
	placeFig.removeChild(placeFig.querySelector('figure'));
	defaultTitle();
}

function defaultTitle() {
	allFigsNodeList.forEach(titleTag => {
		titleTag.title = 'Agrandir';
	});
}

              
            
!
999px

Console