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

              
                <h1 style="text-align:center;">Weather to use CSS Grid for tabbed content (or not)</h1>
<h5 style="text-align:center;">Icons used from <a href="https://www.flaticon.com/packs/weather-219">Flat Icon</a></h5>

<!-- from here for used code -->
<div class="products-wrapper">
	<div class="tabs-wrapper">
          <div class="tab-item">
            <img src="https://image.flaticon.com/icons/svg/1779/1779875.svg" alt="show icon">
          </div>
          <div class="tab-item">
            <img src="https://image.flaticon.com/icons/svg/1779/1779758.svg" alt="rainbow icon">
          </div>
          <div class="tab-item">
            <img src="https://image.flaticon.com/icons/svg/1779/1779826.svg" alt="thunder icon">
          </div>
          <div class="tab-item">
            <img src="https://image.flaticon.com/icons/svg/1779/1779765.svg" alt="cloudy icon">
          </div>
        </div>
        <div class="tabbed-content">
          <div class="item-content">
            <div class="highlights">
              <h4>What is Snow?</h4>
              <p class="text-columns-block">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Reprehenderit
                libero illum maxime voluptatum, dolorem consequuntur est officiis. Sit provident aut facere delectus
                itaque, doloremque, repellat cum eos eius, molestiae excepturi?</p>
            </div>
            <div class="highlights">
              <h4>Formation</h4>
              <p class="text-columns-block">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Reprehenderit
                libero illum maxime voluptatum, dolorem consequuntur est officiis. Sit provident aut facere delectus
                itaque, doloremque, repellat cum eos eius, molestiae excepturi?</p>
            </div>
            <div class="highlights">
              <h4>Wait for Weight</h4>
              <p class="text-columns-block">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Reprehenderit
                libero illum maxime voluptatum, dolorem consequuntur est officiis. Sit provident aut facere delectus
                itaque, doloremque, repellat cum eos eius, molestiae excepturi?</p>
            </div>
            <div class="highlights">
              <h4>Fun Fact</h4>
              <p class="text-columns-block">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Reprehenderit
                libero illum maxime voluptatum, dolorem consequuntur est officiis. Sit provident aut facere delectus
                itaque, doloremque, repellat cum eos eius, molestiae excepturi?</p>
            </div>
          </div>
          <div class="item-content">
            <div class="highlights">
              <h4>What is a Rainbow?</h4>
              <p class="text-columns-block">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Reprehenderit
                libero illum maxime voluptatum, dolorem consequuntur est officiis. Sit provident aut facere delectus
                itaque, doloremque, repellat cum eos eius, molestiae excepturi?</p>
            </div>
            <div class="highlights">
              <h4>Formation</h4>
              <p class="text-columns-block">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Reprehenderit
                libero illum maxime voluptatum, est officiis. Sit provident aut facere delectus
                itaque, doloremque, repellat cum eos eius, molestiae excepturi?</p>
            </div>
            <div class="highlights">
              <h4>Wait for Weight</h4>
              <p class="text-columns-block">Lorem ipsum dolor, sit adipisicing elit. Reprehenderit
                libero illum maxime voluptatum, dolorem consequuntur est officiis. Sit aut facere delectus
                itaque, doloremque, repellat cum eos eius, molestiae excepturi?</p>
            </div>
            <div class="highlights">
              <h4>Fun Fact</h4>
              <p class="text-columns-block">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Reprehenderit
                libero illum maxime voluptatum, dolorem consequuntur est officiis. Sit provident aut facere delectus
                itaque, doloremque, repellat cum, molestiae excepturi?</p>
            </div>
          </div>
          <div class="item-content">
            <div class="highlights">
              <h4>What is Thunder?</h4>
              <p class="text-columns-block">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Reprehenderit
                libero voluptatum, consequuntur est officiis. Sit provident aut facere delectus
                itaque, doloremque, repellat cum eos eius, molestiae excepturi?</p>
            </div>
            <div class="highlights">
              <h4>Formation</h4>
              <p class="text-columns-block">Lorem ipsum dolor, sit amet adipisicing elit. Reprehenderit
                libero illum maxime voluptatum, dolorem consequuntur est officiis. provident aut facere delectus
                itaque, doloremque, cum eos eius, molestiae excepturi?</p>
            </div>
            <div class="highlights">
              <h4>Wait for Weight</h4>
              <p class="text-columns-block">Lorem ipsum dolor, amet consectetur adipisicing elit. Reprehenderit
                libero illum maxime voluptatum, dolorem consequuntur est officiis. Sit aut facere delectus
                itaque, doloremque, eos eius, molestiae excepturi?</p>
            </div>
            <div class="highlights">
              <h4>Fun Fact</h4>
              <p class="text-columns-block"></p>
            </div>
          </div>
          <div class="item-content">
            <div class="highlights">
              <h4>What is a Cloudy day?</h4>
              <p class="text-columns-block">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Reprehenderit
                libero illum maxime voluptatum, dolorem consequuntur est officiis. Sit provident aut facere delectus
                itaque, doloremque, repellat cum eos eius, molestiae excepturi?</p>
            </div>
            <div class="highlights">
              <h4>Formation</h4>
              <p class="text-columns-block">Lorem ipsum dolor, sit amet consectetur elit. libero illum maxime voluptatum, dolorem consequuntur est. Sit provident aut facere delectus
                itaque, doloremque, repellat cum eos eius, molestiae excepturi?</p>
            </div>
            <div class="highlights">
              <h4>Wait for Weight</h4>
              <p class="text-columns-block">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Reprehenderit
                libero illum maxime voluptatum, dolorem consequuntur est officiis. Sit provident aut facere delectus
                itaque, doloremque, repellat cum eos eius, molestiae excepturi?</p>
            </div>
            <div class="highlights">
              <h4>Fun Fact</h4>
              <p class="text-columns-block">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Reprehenderit
                libero illum maxime voluptatum, dolorem consequuntur est officiis. Sit provident aut facere delectus
                itaque, doloremque, excepturi?</p>
            </div>
          </div>
        </div>
	</div>
              
            
!

CSS

              
                /* -------------------- tabbed content using CSS Grid

-- allows for unlimited tabs/content blocks without additional configuration

*/

.products-wrapper {
	margin: 20px;
	.tabs-wrapper {
		display: grid;
		grid-template-columns: repeat(auto-fill, minmax(auto, 1fr));
		grid-template-rows: minmax(max-content, min-content);
		justify-items: center;
		margin-bottom: 2rem;

		.tab-item {
			min-width: min-content;
			width: auto;
			height: auto;
			align-self: center;
			text-align: center;
			cursor: pointer;
			padding: 0 10px;

			img {
				height: auto;
				max-height: 128px;
				filter: drop-shadow(1px 1px 5px rgba(0, 0, 0, 0.5));
			}

			&:hover img {
				filter: drop-shadow(1px 1px 5px rgba(0, 0, 0, 0.2));
			}
		}

		@media screen and (min-width: 600px) {
			grid-template-columns: repeat(auto-fit, minmax(50%, 1fr));
		}

		@media screen and (min-width: 1200px) {
			grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
		}
	}

	.tabbed-content {
		height: min-content;
		// width: auto;
		// margin: auto;

		.item-content {
			width: 100%;
			display: none;
			grid-auto-rows: repeat(auto-fit, minmax(auto, max-content));
			grid-gap: 2rem;
			opacity: 0;
			transition: all 0.5s ease-out;

			&.active {
				display: grid;
				opacity: 1;
				transition: all 0.5s ease-out;
			}

			.highlights {
				padding: 1rem;

				&:hover,
				&:focus {
					background-color: rgba(blue, 0.2);
					border-radius: 2rem;
					transition: all 0.5s ease-out;
				}

				p {
					margin: auto;
				}
			}
		}

		@media screen and (min-width: 600px) {
			.item-content {
				grid-template-columns: repeat(2, 1fr);

				.highlights {
					// padding: 5rem;
				}
			}
		}
	}

	@media screen and (min-device-width: 768px) and (max-device-width: 1024px) and (orientation: portrait) {
		margin: 6rem;
	}

	@media screen and (min-device-width: 768px) and (max-device-width: 1024px) and (orientation: landscape) {
		margin: 5rem;
	}

	@media screen and (min-width: 1200px) {
		margin: 7rem;
	}

	@media screen and (min-width: 1800px) {
		margin: 10rem;
	}
}

              
            
!

JS

              
                /* -------------------- tabbed content info

-- only fires if tabsWrapper is found in page/view.
-- clears any accidental .active classes from the code block
-- starts with tab of choice (initialTab).
-- checks for correct number of tabs and content blocks
---- gives user feedback/code suggestion if tabs/content blocks don't match.
-- allows for unlimited tabs and/or content blocks (as desired)

*/

function contentTabs() {
	// set initial tab of choice
	const initialTab = 0;

	// -------------------------------------------------

	// declare vars
	let i;
	// check if container/wrapper exist
	const containerActive = document.getElementsByClassName('tabs-wrapper');
	// put all tab-items into a variable
	const tabButton = document.querySelectorAll('.tab-item');
	// put all item-contents into a variable
	const tabContent = document.querySelectorAll('.item-content');

	if (containerActive.length >= 1) {
		runTabs();
	}

	function runTabs() {
		/* maintenance mode, check amount of tab-items is same as item-content.
-- if isn't, suggest "warn" ways to ommit error messages. */
		function initChecks() {
			// clear all active classes
			clearActive();
			// check element numbers are correct
			if (tabButton.length < tabContent.length) {
				// if there are less buttons than content tabs
				console.warn(
					'You need to have the same amount of tab-item\'s as you have content-tab\'s'
				);
				console.group(
					'Paste this emmet shorthand inside the \'tabs-wrapper\' div and press enter/tab'
				);
				console.log('div.tab-item{tab-title}');
				console.groupEnd();
			} else if (tabContent.length < tabButton.length) {
				// if there are less content tabs than buttons
				console.warn(
					'You need to have the same amount of content-tab\'s as you have tab-items\'s'
				);
				console.group(
					'Paste this emmet shorthand inside the \'tabbed-content\' div and press enter/tab'
				);
				console.log(
					'div.item-content>div.hightlights*4>h4{some title}+p{some copy}'
				);
				console.groupEnd();
			} else {
				tabContent[initialTab].classList.add('active');
			}
		}
		initChecks();

		/* self calling function to clear all active classed from group of tabs
    -- if user has added active class for some wierd reason */
		function clearActive() {
			// cycle through all elements with class="tab-item" and remove "active".
			for (i = 0; i < tabContent.length; i++) {
				tabContent[i].classList.remove('active');
			}
		}

		// add event listeners to all elements with tab-item class and wait for click
		for (let tabIndex = 0; tabIndex < tabButton.length; tabIndex++) {
			tabButton[tabIndex].addEventListener('click', function() {
				// clear all active class's from the group of tabs.
				clearActive();
				// select item-content with the same index as the clicked tab-item and add an active class.
				tabContent[tabIndex].classList.toggle('active');
			});
		}
	}
}
contentTabs();

              
            
!
999px

Console