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 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

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

              
                <!doctype html>
<html lang="en">
	

	<head>

		<meta charset="utf-8">


		<!--
			The <meta> element below is important to help change the size of our browser window to reflect the size of the device. It works as follows:

				name="viewport" - this clarifies that we are declaring something about the viewport (aka browser window)
				'width=device-width' - this specifies that the width of the viewport should be equal to the width of our device (important for mobile devices)
				'initial-scale=1' - this ensures that our website renders not zoomed-in or zoomed-out, as we have designed it to be responsive.

			If you would like more information on why we set this, I recommend reading this article - https://developer.mozilla.org/en-US/docs/Mozilla/Mobile/Viewport_meta_tag
		-->
		<meta name="viewport" content="width=device-width, initial-scale=1">

		<title>My Less Hideous Page</title>


		<link rel="stylesheet" href="css/normalize.css"> 
		<!-- 
			Here we are linking up a separate stylesheet to manage our grid structures.
		-->
		<link rel="stylesheet" href="css/grid.css">
		<link rel="stylesheet" href="css/main.css">


	</head>
	<body>


		<header>
			<h1>My Less Hideous Page</h1>
			<nav>
				<!--
					Below we have added a <div> element to act as a non-semantic HTML element to apply our grid styling to. Note that we have assigned three separate CSS classes to our element by separating them with spaces. In this case our <div> below has the CSS classes of: .grid and .four-column and .add-gutters
				-->
				<div class="grid four-column add-gutters">
					
					<!-- 
						In the case of our grid, the child elements of the grid - in this case the <a> below that are the children of the <div class="grid ..."> - are what form each 'cell' of the grid. If you need to place more than just a single element in a cell, then they need to be wrapped inside of another element. A good example of this is available below at line 75.
					-->
					<a href="#introduction" class="nav-main-item">An introduction</a>
					<a href="#kittens" class="nav-main-item">To the kittens</a>
					<a href="#puppies" class="nav-main-item">But puppies are cuter</a>
					<a href="http://www.placekitten.com" class="nav-main-item">placekitten.com</a>
				</div>
			</nav>


		</header>



		<section id="introduction">

			<h2>An introduction</h2>

			<p>
				<strong>Very exciting things are happening</strong>. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
			</p>

		</section>

		
		<!--
			Below we have added a <div> element to act as a non-semantic HTML element to apply our grid styling to. Note that we have assigned three separate CSS classes to our element by separating them with spaces. In this case our <div> below has the CSS classes of: .grid and .two-column and .add-gutters
		-->
		<div class="grid two-column add-gutters">

			<!-- 
				In the case of our grid, the child elements of the grid - in this case the <section> elements below that are the children of the <div class="grid ..."> - are what form each 'cell' of the grid. In the example below all the content that is inside of each <section> element will fill one cell of our grid.
			-->
			<section id="kittens">

				<h2>Kittens are da cutest!</h2>

				<figure>

					<img src="https://andrewh.ca/teaches/information_design/tutorials/03/explanation/img/kitten.jpg" alt="A photo of a sad looking kitten with a zoom focusing our attention on the kitten" width="1200" height="627">
	
					<figcaption>
						It's a bundle of cute, cuddly, danger! 
						<a href="http://placekitten.com">Photo from placekitten</a>
					</figcaption>
	
				</figure>
	
				
				<ol>
					<li>The <em>first</em> reason why kittens are dangerous.</li>
					<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
					<li>Aliquam tincidunt mauris eu risus.</li>
				</ol>

			</section>


			<section id="puppies">

				<h2>But puppies are cuter!</h2>
				<figure>
					<img src="https://andrewh.ca/teaches/information_design/tutorials/03/explanation/img/puppy.jpg" alt="A corgy wearing a bird mask" width="599" height="472">
					<figcaption>
						A dog can only be made cuter using a bird mask.
					</figcaption>
				</figure>

				<p>Consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis feugiat vitae, ultricies ege.</p>

			</section>
		</div>


	</body>
</html>

              
            
!

CSS

              
                /* ALL THIS CONTENT APPEARS IN THE GRIDS.CSS FILE */

/*
	With the asterisk (*) selector, we are specifying that all objects use the border-box model (not the content-box model)
*/
* {
	box-sizing: border-box;
}





/*
	A reminder that here we are defining our own 'class' which we can then apply repeatedly to our HTML elements. In this case, in our HTML if we apply <... class="grid"> to an element, it will have all the styling applied to it as defined inside of .grid {...} below.
*/
.grid {
	/*
		By setting the 'display' property to a value of 'grid', we are setting the container to use CSS grid system for its layout.
	*/
	display: grid;
}





/*
	Below the selector we have is specified as '.grid.add-gutters'. This means that to have this styling applied in our HTML, we have to select an element that has the classes of BOTH 'grid' and 'add-gutters'. This might look like the following in our HTML:

	<div class="grid add-gutters"> - This would have the styling below applied to it.
	<div class="add-gutters"> - This would NOT have the styling below applied to it.

	While we could have our .grid class specify the gutters, we may in some cases want a grid structure that does not included gutters. By having a separate class specifically for adding gutters we can apply (or not) this styling easily in our HTML.
*/
.grid.add-gutters {
	
	/*
		To add gutters between the columns and rows of our grid structure we have the 'grid-column-gap' and 'grid-row-gap' properties. These will add space between columns or rows of our grid as you specify. In this case, we are adding 1rem of spacing between columns and 0.25rem of spacing between rows.
	*/
	grid-column-gap: 1rem;
	grid-row-gap: 0.25rem;
}






/*
	Based on resizing the window and watching when the content could re-organize, we can determine when to add media queries (@media) to adjust the page layout accordingly. In this case, we measured that around 820 pixels was a good point at which to switch our two-column content to be placed next to one another. Because we want to ensure that the page responds to changes in font-size (and applies media queries accordingly), we use the base font size of 16 pixels to calculate our rem units in this case: 820/16px = 51.25rem

	The 'min-width' condition for our media query states that when the width of the browser window is at or larger than 51.25rem, apply the specified styling. Any styling that appears in a @media statement will ONLY apply when the condition is met.
*/
@media (min-width: 51.25rem) {
	

	/*
		We are applying the same styling to both our two and four-column grids as we know at this media query this is enough room for two columns across, but not yet four.
	*/
	.grid.two-column, .grid.four-column {
		/*
			The CSS Grid system allows us to define both columns and rows for our 'template' to follow. For this we use the 'grid-template-columns' and 'grid-template-rows' properties with the 'fr' unit to assign the structure of our grid. The 'fr' unit refers to a 'fraction'. Because we want a three-column grid we assign the following:

			grid-template-columns: 1fr 1fr; - Here the two values - '1fr 1fr' - indicate that we want two columns, each equal in width - 1 fraction (fr) of 2. The browser will automatically determine what the actual width of these columns are.

			grid-template-rows: auto; - Because we don't necessarily know how many rows our grid structure will be in this case, we are not assigning a specific number of rows to our grid structure.
		*/
		grid-template-columns: 1fr 1fr;
		grid-template-rows: auto;
		
		/*
			The 'grid-auto-flow' property allows us to have the browser automatically place items to fill in our grid structure as necessary. In this case by specifying the value of 'row' we are telling the browser to fill-in the rows of our grid and add new rows as necessary.
		*/
		grid-auto-flow: row;
	}

}



/*
	In this case, we measured that around 1120 pixels was a good point at which to switch our four-column items to be placed next to one another instead of on top of one another. The calculation in this case is 1120/16px = 70rem

	The 'min-width' condition for our media query states that when the width of the browser window is at or larger than 70rem, apply the specified styling. Any styling that appears in a @media statement will ONLY apply when the condition is met.
*/
@media (min-width: 70rem) {
	
	.grid.four-column {
		/*
			grid-template-columns: 1fr 1fr 1fr 1fr; - Here the four values - '1fr 1fr 1fr 1fr' - indicate that we want four columns, each equal in width - 1 fraction (fr) of 4. The browser will automatically determine what the actual width of these columns are.

			grid-template-rows: auto; - Because we don't necessarily know how many rows our grid structure will be in this case, we are not assigning a specific number of rows to our grid structure.
		*/
		grid-template-columns: 1fr 1fr 1fr 1fr;
	}
}










/* ALL THIS CONTENT APPEARS IN THE MAIN.CSS FILE */
/*
	Welcome to CSS styling! This is how we style our HTML pages. It is important to note how we select and change the styling for an element:

	selector {
		property: value;
		property2: value2;
	}

	selector - The item we are selecting to be restyled. This can be an element name such as h1 or img, or the name of an id or class (#robots, .item-class)
	property - A CSS property that we want to restyle the element with, such as font-size or color.
	value - The value we want to set the property to, such as 16px or blue.

	Make sure to separate different property/value statements with a colon between property: value, and a semicolon at the end of the property: value; statement. 
*/



/*
	Below we have selected the body element - aka <body> - and are setting some styling for it. Generally it is a good idea to only select entire sets of elements to set default stylings. Aim to use classes when styling elements more specifically.
*/
body {
	/*
		Font family works by stating a series of fonts in order from most to least specific. The reason is to ensure that if the first font is not available, that we have fall-backs that the browser can load up if needed.
	*/
	font-family: Helvetica, Verdana, sans-serif;

	/*
		Margin sets the spacing outside of the borders of an element's box. Because we are only setting one value below, it makes it the margin value for all sides of our box, which in this case is all sides of our body element.
	*/
	margin: 1rem;

	/*
		Setting a default font size for all elements who are children of the body tag. How 'rems' work are explained in the next comment.
	*/
	font-size: 1.25rem;
}



/*
	With the selection of the different heading elements below, we are using 'rem' units to establish a default hierarchy for their font sizes. Rem units refer to 'root-em' which are a multiple of the base font-size set by the browser. As a result, rem units are particularly useful for establishing hierarchies in type.
*/
h1 {
	font-size: 3rem;
	/*
		We can be more specific than just 'margin' with our property and specify 'margin-bottom' instead. In this case, because we are setting a value of 0, there is no need to add a unit to the value.
	*/

	margin-bottom: 0;
}

h2 {
	font-size: 2.25rem;
	margin-bottom: 0;
}

h3 {
	font-size: 1.6rem;
	margin-bottom: 0;
}



/*
	Below we are setting defaults for a series of selectors. The comma allows us to select a combination of elements.
*/
p, ol, ul {

	/*
		max-width is a property which easily allows us to ensure something does not extend past a certain point in width. In this case, we can use it to make line-lengths more manageable in our text.
	*/
	max-width: 40rem;
}



img {
	/* 
		We are saying we want the img to adjust its height accordingly when the width changes.
	*/
	height: auto; 

	/* 
		Then we tell it we don't want it to exceed 100% of the parent element. In this case it resizes with the 'body' tag (the browser window).
	*/
	max-width: 100%;

	/* 
		The three statements below allow us to set a border around our images, in order they set the width, the style (dashed, solid, etc), and then the color of the border.
	*/
	border-width: 1px;
	border-style: solid;
	border-color: black; 
}


/*
	Because the figure element has a margin set on it by default, if we do not want it to have a margin we have to set the margin to zero.
*/
figure {
	margin: 0;
}

figcaption {
	font-style: italic;
}



a {
	/*
		Setting colours for elements can be done in a variety of ways. You can use just the colour name 'blue', you can use a HEX value '#00AAFF', you can specify an rgb value 'rgb(0,200,255)', and you can specify an rgb value with alpha (or opacity) using 'rgba(0,200,255,0.8)' (80%).
	*/
	color: rgb(200,0,0);

	/*
		The transition property makes it very easy to create smooth transitions for different CSS properties. In this case, with the two statements below we are specifying that we want to transition the 'color' property over 0.5 seconds. Note that you have to have another state for the element - example below in a:hover - for it to actually make use of the transition.
	*/
	transition-property: color;
	transition-duration: 0.5s;
}



/* 
	The :hover and :focus are pseudo-states for elements. In this case, we are saying when the anchor tag is the 'hover' (being hovered over) and 'focus' (selected by keyboard, i.e. tab) states it should apply the styling specified.
*/
a:hover, a:focus {
	color: rgb(50,0,0); 
	/*
		The text-decoration property allows us to add or remove underlining. In this case we are removing it.
	*/
	text-decoration: none;
}



/*
	Here we are selecting the elements with the .button class that are inside of the nav tag
*/
.nav-main-item {
	display: inline-block;
	color: white;
	background-color: rgb(250,100,75);
	font-size: 1.5rem;
	
	/*
		By setting two values for padding below, we are now specifying different values for the top/bottom and the left/right in that order. This compound declaration can also be used to set different padding values for each of the sides of a box in top, right, bottom, left order. Example:

		padding: top right bottom left; would be 
		padding: 10rem 5rem 2rem 12rem;
	*/
	padding: 0.5rem 0.75rem;

	/*
		Because our anchor tags have an underline by default, we end up having to remove them for our buttons (by default).
	*/
	text-decoration: none;

	/*
		Unlike our prior transition statement, here we are also adding a type of easing to the transition.
	*/
	transition-property: background-color;
	transition-duration: 0.5s;
	transition-timing-function: ease-out;
}


.nav-main-item:active, .nav-main-item:hover, .nav-main-item:focus {
	color: white;
	background-color: rgb(50,50,50);
}


              
            
!

JS

              
                
              
            
!
999px

Console