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>Styling Paginations with Float, Flexbox, and CSS Grid.</h1>
<p>There are three different ways to do pagination layout and that is using <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/float">Float</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout">Flexbox</a>, and <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout">CSS Grid</a>.</p>
<p>Ultimiately, there are <em>many</em> different ways to solve this issue. </p>
<p>Please use the web inspector or view the source code here on this pen to see the results</p>

<div class="pagination old-school-way cf">
	<h2>Float</h2>
	<p>From the Front End Devs of old, we did use this technique using floats and clears many times in the past&hellip;</p>
	<pre>
.cf::after { 
  content: "";
  display: block; 
  clear: both;
}

li:first-child {
  float: left;
}

li:last-child {
  float: right;
}
	</pre>
	<h3>Results - floats</h3>
	<ul>
		<li><a href="#">&laquo; previous post</a></li>
		<li><a href="#">&raquo; next post</a></li>
	</ul>
</div>

<div class="pagination flexbox-way cf">
	<h2>Flexbox</h2>
	<p>Then came along this gem, the code as it stands.</p>
	<pre>
ul {
  display: flex;
  justify-content: space-between;
}
	</pre>
	<h3>Results - Flexbox</h3>
	<ul>
		<li><a href="#">&laquo; previous post</a></li>
		<li><a href="#">&raquo; next post</a></li>
	</ul>
</div>

<div class="pagination cssgrid-way cf">
	<h2>CSS Grid way</h2>
	<p>The modern way of using grid.</p>
	<pre>
ul {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-gap: 2rem;
}

li {
  grid-column: span 1;
}
	</pre>
	<h3>Results - CSS Grid</h3>
	<ul>
		<li><a href="#">&laquo; previous post</a></li>
		<li><a href="#">&raquo; next post</a></li>
	</ul>
</div>
              
            
!

CSS

              
                body {
	background-color: #444;
	color: #fff;
	font-family: arial;
	padding: 1rem;
}

h1,
h2,
h3,
h4 {
	margin: 0;
}

a {
	color: lightblue;
}

.cf::after {
	content: "";
	display: block;
	clear: both;
}

.pagination {
	border: 1px solid lightblue;
	padding: 1rem;
	margin: 0 0 2rem;
	max-width: 30rem;

	pre {
		white-space: pre-wrap;
	}
	ul {
		list-style: none;
		padding: 0 1rem;

		li {
			display: inline-block;

			&:last-child {
				text-align: right;
			}

			a {
				color: #fff;
			}
		}
	}

	&.old-school-way {
		li:first-child {
			float: left;
		}

		li:last-child {
			float: right;
		}
	}

	&.flexbox-way {
		ul {
			display: flex;
			justify-content: space-between;
		}
	}

	&.cssgrid-way {
		ul {
			display: grid;
			grid-template-columns: repeat(2, 1fr);
			grid-gap: 2rem;
		}

		li {
			grid-column: span 1;
		}
	}
}

              
            
!

JS

              
                
              
            
!
999px

Console