Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

Save Automatically?

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

              
                <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 class = 'lightbox hide'>
	<!-- controls / figure -->
	<div class='lightbox-flex'>
		<a class='prev'>&#10094;</a>
			<div id = 'placefig'>
				<!-- close button -->
				<div class=lightbox-top>
                    <div class='counter left'>
                        <span id='current-index'></span>
                        <span id='total-index'></span>
                    </div>
					<div class='buttonX right'>
						<span class=close-txt>Close</span>
						<span class=close>&times;</span>
					</div>
				</div>
			</div>
		<a class='next'>&#10095;</a>
	</div>
</div>

              
            
!

CSS

              
                /* lightbox css */
.lightbox {
    position: fixed;
    z-index: 1;
    text-align: center;
    top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		padding: 5%;
	/* Enable scroll if needed */
    overflow: auto;
		background: rgba(0, 0, 0, 0.8);
}
.lightbox-flex {
    display: flex;
    justify-content: center;
    align-items: center;
}
/* Close button */
.lightbox-top {
	display: flex;
	justify-content: space-between;
	color: #aaa;
}
.buttonX {
	user-select: none;
}
.buttonX:hover,
.buttonX:focus {
	color: #fa4b2c;
	text-decoration: none;
	cursor: pointer;
}
.counter {
	margin-left: 1em;
	line-height: 2.4em;
}
.close,
.close-txt {
	margin-right: .4em;
}
.close {
	font-size: 2em;
	font-weight: bold;
	vertical-align: -0.2em;
}
.close-txt,
.current-index,
.total-index {
	font-size: 1em;
}
/* Next & previous buttons */
.prev, .next {
	cursor: pointer;
	user-select: none;
	padding: 12px;
	color: #aaa;
	font-size: 2em;
	/* transition: 0.6s ease; */
}
.prev:hover, .next:hover {
	background-color: #000;
}
/* Number text (1/3 etc) */
.numbertext {
	color: #838383;
	font-size: 12px;
	padding: 8px 12px;
	position: absolute;
	top: 0;
}

/* elements display */
.hide {display: none;}
.bitmap {
	max-width: 100%;
	height: auto;
}

figure {cursor: pointer;}
figcaption{
	color: #999;
	text-align: center;
	padding-top: 1.5em;
}

/* grid : any kind of css here would be working ************************************/
.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;
	--corporate-red: #fa4b2c;
}



              
            
!

JS

              
                // get all figures in a Node list
const allFigsNodeList = document.querySelectorAll('figure');
	console.log(allFigsNodeList); // NodeList(11)

// lightbox
const lightBox = document.querySelector('.lightbox');
const prevBtn = document.querySelector('.prev');
const nextBtn = document.querySelector('.next');
const closeBtn = document.querySelector('.buttonX');
const placeFig = document.getElementById('placefig');
const currentIndexTxt = document.getElementById('current-index');
const totalIndexTxt = document.getElementById('total-index');

// title loop
defaultTitle();
// boucle item
allFigsNodeList.forEach((currentFig, index) => {
    currentFig.onclick = () => {
		openLightBox();
		// hideBtns(index);
		hidePrevBtn(index);
		hideNextBtn(index);
        let currentIndex = index+1;
            console.log('currentIndex = '+currentIndex);

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

        // clone clicked figure
        const figClone = currentFig.cloneNode(true);
        // place clicked 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.classList.add('hide');
				prevBtn.style.color = '#333';
				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.color = '#333';
				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.color = '#333';
	} else {
		prevBtn.style.color = '#aaa';
	}
}

function hideNextBtn(index) {
	if (index == allFigsNodeList.length-1) {
		// nextBtn.classList.add('hide');
		nextBtn.style.color = '#333';
	} else {
		nextBtn.style.color = '#aaa';
	}
}

function showBtns() {
	prevBtn.style.color = '#aaa';
	nextBtn.style.color = '#aaa';
}

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';
	});
}
// scroll to top button
//Get the button
var mybutton = document.getElementById("topBtn");

// When the user scrolls down 20px from the top of the document, show the button
window.onscroll = function() {scrollFunction()};

function scrollFunction() {
	if (document.body.scrollTop > 200 || document.documentElement.scrollTop > 200) {
    	mybutton.style.display = "block";
	} else {
    	mybutton.style.display = "none";
	}
}

// When the user clicks on the button, scroll to the top of the document
function topFunction() {
	document.body.scrollTop = 0;
	document.documentElement.scrollTop = 0;
}
              
            
!
999px

Console