<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>grid Archives - Michael Soriano</title>
	<atom:link href="https://michaelsoriano.com/tag/grid/feed/" rel="self" type="application/rss+xml" />
	<link>https://michaelsoriano.com/tag/grid/</link>
	<description>I turn code into captivating user experiences for the web</description>
	<lastBuildDate>Wed, 03 Aug 2022 15:17:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.4</generator>
	<item>
		<title>Create a Responsive Photo Gallery with this plugin and the Bootstrap Framework</title>
		<link>https://michaelsoriano.com/create-a-responsive-photo-gallery-with-bootstrap-framework/</link>
					<comments>https://michaelsoriano.com/create-a-responsive-photo-gallery-with-bootstrap-framework/#comments</comments>
		
		<dc:creator><![CDATA[Michael Soriano]]></dc:creator>
		<pubDate>Tue, 19 Nov 2013 04:45:05 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Bootstrap]]></category>
		<category><![CDATA[grid]]></category>
		<guid isPermaLink="false">http://fearlessflyer.com/?p=3789</guid>

					<description><![CDATA[<p>This is the original page for bootstrap-photo-gallery plugin. It started out as a tutorial, then I converted it into a plugin. The README in Github is now the official documentation for the plugin &#8211; with a more detailed change log as well as instructions on how to use + options. This page is now simply [&#8230;]</p>
<p>The post <a href="https://michaelsoriano.com/create-a-responsive-photo-gallery-with-bootstrap-framework/">Create a Responsive Photo Gallery with this plugin and the Bootstrap Framework</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>This is the original page for <strong>bootstrap-photo-gallery</strong> plugin. It started out as a tutorial, then I converted it into a plugin. The README in Github is now the official documentation for the plugin &#8211; with a more detailed change log as well as instructions on how to use + options.</p>



<p>This page is now simply an archive of the original tutorial. Note that I&#8217;ve been having issues with my syntax highlighter (<em>for the code in tutorial</em>) &#8211; so the code in the steps may not show in its entirety.</p>



<p><a class="viewdemo" href="http://demo.michaelsoriano.com/bootstrap-gallery/master/demo.html" rel="nofollow">View Demo</a><br><a class="" href="https://github.com/michaelsoriano/bootstrap-photo-gallery" target="_blank" rel="noopener">View in Github</a></p>



<p><img fetchpriority="high" decoding="async" width="920" height="669" class="alignnone size-full wp-image-6417" src="https://michaelsoriano.com/wp-content/uploads/2018/01/bs-gallery.gif" alt="bootstrap photo gallery"><br></p>



<p><strong>Update 1/7/2018: </strong> The plugin now uses Bootstrap 4 &#8211; which is entirely different from the previous version.<br><strong>Update 6/24/2016: </strong> Several enhancements have been made to the plugin. See the following list for the most recent changes:</p>



<p>1) The Modal box that opens is always going to be the large modal. Images will scale up to 100% to fill the entire modal box. You still have the option of having a small thumbnail and linking to a different image for the large size &#8211; mainly for performance purposes.</p>



<p>2) A new plugin option called &#8220;fullHeight&#8221; that allows you to have different heights in the thumbnails inside the grid. Most people want to see uniform heights, so I default this value to &#8220;true&#8221;. If you want to see dynamic heights, simply set this to &#8220;false&#8221;. Note that this doesn&#8217;t affect the modal images.</p>



<p>3) I&#8217;ve separated the styles into it&#8217;s own stylesheet. You now have to include this stylesheet in your document, or you can simply copy the contents into your own stylesheet. I tried making everything inline so you only have to include the JS file, but it&#8217;s been growing and having an external CSS is the only way to manage.</p>



<p>4) Added glyphicons for the &#8220;Next&#8221; and &#8220;Previous&#8221; links in the modal. This just looks better.</p>



<p><img decoding="async" width="750" height="466" class="alignnone size-full wp-image-5884" src="https://michaelsoriano.com/wp-content/uploads/2013/11/new-bsp-features.jpg" alt="" srcset="https://michaelsoriano.com/wp-content/uploads/2013/11/new-bsp-features.jpg 750w, https://michaelsoriano.com/wp-content/uploads/2013/11/new-bsp-features-300x186.jpg 300w" sizes="(max-width: 750px) 100vw, 750px" /></p>



<p>5) Images are required to have an alt tag, so I&#8217;m outputting the value of this into the modal as the title.</p>



<p>6) You can have additional text underneath the grid thumbnails by having a &#8220;p&#8221; tag with a class of &#8220;text&#8221;. I grab this value and put it in the modal as well.</p>



<p><strong>Update 12/13/2015: </strong> I&#8217;ve updated the plugin to support linking to a different image when shown in the modal box. Continue reading below for instructions.</p>



<p><strong>Update 11/14/2015: </strong>This code for this tutorial have been converted into a jQuery plugin. This means that it&#8217;s now easier to create a responsive photo gallery. The original tutorial is still available below (where is says &#8220;Original Tutorial&#8221;). Note that you don&#8217;t need to follow it if you&#8217;re using the plugin. But it&#8217;s good to know the inner workings of Bootstrap regardless.</p>



<h3 class="wp-block-heading">How to use the Plugin:</h3>



<p>Download the files from <a href="https://github.com/michaelsoriano/bootstrap-photo-gallery">Github</a>. Note that you will need to have jQuery and Bootstrap (CSS and JS) in your pages for the plugin to work effectively. It has been tested it with jQuery 1.10.2 and Bootstrap 3.3.5. Then add the plugin file (<strong>jquery.bsPhotoGallery.js</strong>) right below jQuery.</p>



<p>Please see README in Github for more details.</p>



<p>Then it&#8217;s time to initialize our plugin and pass in the options.</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">$(document).ready(function(){
  $('ul.first').bsPhotoGallery({
    "classes" : "col-lg-2 col-md-4 col-sm-3 col-xs-4 col-xxs-12",
    "hasModal" : true
  });
});</code></pre>



<p>Explanation: We are wrapping the code in a document.ready function so jQuery is available throughout. The selector $(ul.first) is the markup for our images, and .bsPhotoGallery is our plugin.</p>



<p>We need to pass in our Bootstrap classes into the &#8220;classes&#8221; argument so it&#8217;s important to know how the <a href="https://michaelsoriano.com/exploring-the-bootstrap-3-0-grid-system/">Bootstrap Grid system</a> works. And if you want to have a &#8220;modal box&#8221; appear with your image when clicked, you simply add the &#8220;<strong>hasModal</strong>&#8221; : true agrument.</p>



<h3 class="wp-block-heading">Benefits of using this Plugin</h3>



<p>By using this plugin, you don&#8217;t need to manually add the Bootstrap classes to each of the list item that you create. This just gets added dynamically as soon as the plugin kicks in. It also adds the Bootstrap helpers for clearing different heights of images OR if you have some kind of caption underneath (like the <a href="http://demo.michaelsoriano.com/bootstrap-gallery/master/demo.html">demo</a>)</p>



<p>Moreover, the plugin has the &#8220;modal&#8221; functionality which requires some Javascript to write anyway. So we might as well bundle them all up to one complete plugin.</p>



<h3 class="wp-block-heading">Linking to a different image in the Modal</h3>



<p>In a some cases you want to show an entirely different image when the modal box is shown. Simply add an extra attribute to the image called &#8220;<strong>data-bsp-large-src</strong>&#8220;, and the value being the path to the image desired.</p>



<p><strong>Below is the old tutorial</strong> &#8211; if you choose to follow it instead to using the plugin.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h3 class="wp-block-heading">The Original Tutorial Starts Here:</h3>



<p><strong>Remember:</strong> You don&#8217;t have to follow these steps if you&#8217;ve gone through the steps above in using the plugin. But if you want to build your own, then the tutorial below is good.</p>



<p>So you&#8217;ve been tasked with creating a photo gallery for you website. One that looks good on a desktop, a phone &#8211; even a tablet. One that has a grid of thumbnails, plus a modal functionality when the thumbnails are clicked.</p>



<p>This is part one of two series. Part two is where we add &#8220;previous&#8221; and &#8220;next&#8221; links to our modal box, click <a title="Let’s Add Next and Previous Buttons to our Bootstrap Photo Gallery" href="https://michaelsoriano.com/next-and-previous-buttons-bootstrap-photo-gallery/">here</a> to view it.</p>



<p>Well you&#8217;re in luck. Not only that we&#8217;ll show you how to code it &#8211; but we&#8217;ll show you using the most advanced front end framework yet! It&#8217;s called Bootstrap. For those of you living under a rock and have never heard of it &#8211; here&#8217;s a <a href="http://getbootstrap.com/">good start</a>.</p>



<p>Before we begin, make sure you read our <a href="https://michaelsoriano.com/exploring-the-bootstrap-3-0-grid-system/">in-depth look of Bootstrap&#8217;s grid system</a>. This will make you familiar of the classes we need to make the gallery. Also, if you haven&#8217;t seen the demo, below is a preview of what we&#8217;re building. See how the grid responds when we shrink the page?</p>



<p>So ready to start? Let&#8217;s code:</p>



<h3 class="wp-block-heading">Create the Markup</h3>



<p>Assuming that you&#8217;ve downloaded and linked to Bootstrap&#8217;s files, let&#8217;s create our .container div, along with an un-ordered list. Each list item will contain your images.</p>



<p>Save it and we should have something like below:</p>



<p><img decoding="async" width="650" height="628" class="alignnone noborder size-full wp-image-3791" src="https://michaelsoriano.com/wp-content/uploads/2013/11/tut1.jpg" alt="tut1"><br>Nothing magical here, just an un-ordered list of images with no styles. Now let&#8217;s apply the Bootstrap classes. First, add a &#8220;row&#8221; to the ul tag. Second, add classes &#8220;col-lg-2&#8221;, &#8220;col-md-2&#8221;, &#8220;col-sm-3&#8221; and &#8220;col-xs-4&#8221; to each list item.</p>



<p>Save and view it in the browser:</p>



<p><img decoding="async" width="650" height="310" class="alignnone size-full wp-image-3792" src="https://michaelsoriano.com/wp-content/uploads/2013/11/tut2.jpg" alt="tut2"></p>



<p>Believe it or not, we&#8217;re halfway done. Didn&#8217;t we say Bootstrap makes front end development faster? Try re-sizing your browser, and see how the thumbnails and the grid behave.</p>



<p><img decoding="async" width="630" height="350" class="alignnone size-full wp-image-3793" src="https://michaelsoriano.com/wp-content/uploads/2013/11/resp-photo-gallery2.gif" alt="resp-photo-gallery2"><br></p>



<pre class="wp-block-code"><code lang="css" class="language-css">ul {
  padding:0 0 0 0;
  margin:0 0 0 0;
}
ul li {
  list-style:none;
  margin-bottom:25px;
}
ul li img {
  cursor: pointer;
}</code></pre>



<p>Add a few CSS styles just to get rid of the list styles and unnecessary padding and margins.</p>



<h3 class="wp-block-heading">Different Heights for the Images</h3>



<p>In cases where you need to show images with different orientations, additional text or simply just different sizes. The grid naturally breaks with this pattern. To resolve this, basically you need to add an element that will clear the items. Bootstrap has a class for this called &#8220;clearfix&#8221;.</p>



<p>The element needs to be added where you want them to clear. For example, if you&#8217;re using &#8220;col-lg-2&#8221; (which means 6 columns), right after the 6th image, you add the element. </p>



<p>In addition, you have to add helper classes to only make them appear at certain viewports, such as &#8220;visible-lg-block&#8221;. So the element will have classes like below:</p>



<p><strong>&#8220;clearfix visible-lg-block&#8221;</strong><br></p>



<p>So if you look closely at our markup, there are list items that are inserted just for this purpose:</p>



<p><br><img decoding="async" width="650" height="349" class="alignnone size-full wp-image-5302" src="https://michaelsoriano.com/wp-content/uploads/2013/11/variable-height.jpg" alt="variable-height" srcset="https://michaelsoriano.com/wp-content/uploads/2013/11/variable-height.jpg 650w, https://michaelsoriano.com/wp-content/uploads/2013/11/variable-height-300x161.jpg 300w" sizes="(max-width: 650px) 100vw, 650px" /></p>



<p>This should solve the variable height issues with the grid. Now we&#8217;re ready to move on to the next part.</p>



<h3 class="wp-block-heading">Create the Light Box (Modal)</h3>



<p>So we want the large version of the image be shown in a lightbox as soon as we click on the thumbnail. Bootstrap&#8217;s got a pre-built Javascript Modal that makes this easy as well. Add the following to your markup:</p>



<pre class="wp-block-code"><code lang="markup" class="language-markup">&lt;div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
&lt;div class="modal-dialog">&lt;!-- /.modal-content -->&lt;/div>
&lt;p>&lt;!-- /.modal-dialog -->&lt;/p>
&lt;/div></code></pre>



<p><br>The above code is what makes up the modal pop up box. Now let&#8217;s add some Javascript to make our images happen. Make sure you&#8217;ve linked to the Bootstrap.js file, as well as the jQuery library.</p>



<p>Then add a new set of script tags, plus the code below:</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">$(document).ready(function(){
   $('li img').on('click',function(){
        var src = $(this).attr('src');
        var img = '';
        $('#myModal').modal();
        $('#myModal').on('shown.bs.modal', function(){
            $('#myModal .modal-body').html(img);
        });
        $('#myModal').on('hidden.bs.modal', function(){
            $('#myModal .modal-body').html('');
        });
   });
})</code></pre>



<p>The above code simply calls the .modal() function as soon as we click a thumbnail. The contents of the modal box is grabbed from the 2 variables we created (src, img) which is the image tag and original src of the image clicked.</p>



<p>Now test your code by clicking on an image. To close the modal, click anywhere outside the popup.</p>



<p><img decoding="async" width="630" height="350" class="alignnone size-full wp-image-3794" src="https://michaelsoriano.com/wp-content/uploads/2013/11/resp-photo-gallery3.gif" alt="resp-photo-gallery3"><br>And guess what? I believe that&#8217;s it! It would be good to have a previous and next button on the large image so we can cycle through the images. Maybe even add a &#8220;swipe&#8221; functionality as well. </p>



<p>Let&#8217;s tackle that in <a title="Let’s Add Next and Previous Buttons to our Bootstrap Photo Gallery" href="https://michaelsoriano.com/next-and-previous-buttons-bootstrap-photo-gallery/">part two</a> of this session so stay tuned.</p>



<h3 class="wp-block-heading">Conclusion</h3>



<p>As you can see, we didn&#8217;t do much code at all to create our responsive photo gallery. Imagine all the steps we have to take if it weren&#8217;t for our amazing Bootstrap framework. Think of all the manual calculations, measurements, css code etc. Thank you Bootstrap!</p>



<p>Let us know what you think in the comments below. We will have a download for this project when we finish <a title="Let’s Add Next and Previous Buttons to our Bootstrap Photo Gallery" href="https://michaelsoriano.com/next-and-previous-buttons-bootstrap-photo-gallery/">part 2</a> of the series.</p>
<p>The post <a href="https://michaelsoriano.com/create-a-responsive-photo-gallery-with-bootstrap-framework/">Create a Responsive Photo Gallery with this plugin and the Bootstrap Framework</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://michaelsoriano.com/create-a-responsive-photo-gallery-with-bootstrap-framework/feed/</wfw:commentRss>
			<slash:comments>124</slash:comments>
		
		
			</item>
		<item>
		<title>Exploring the Bootstrap 3.0 Grid System</title>
		<link>https://michaelsoriano.com/exploring-the-bootstrap-3-0-grid-system/</link>
					<comments>https://michaelsoriano.com/exploring-the-bootstrap-3-0-grid-system/#comments</comments>
		
		<dc:creator><![CDATA[Michael Soriano]]></dc:creator>
		<pubDate>Thu, 14 Nov 2013 03:57:06 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Bootstrap]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[Responsive Design]]></category>
		<guid isPermaLink="false">http://fearlessflyer.com/?p=3767</guid>

					<description><![CDATA[<p>Understanding what this framework can do for your next responsive site The idea of a grid system has been around since the 960.gs framework days. Web designers from all over the world began realizing the importance of pixel perfect alignment, gutter spacing and the rule of thirds. Gone are the days of grid-less web pages. [&#8230;]</p>
<p>The post <a href="https://michaelsoriano.com/exploring-the-bootstrap-3-0-grid-system/">Exploring the Bootstrap 3.0 Grid System</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Understanding what this framework can do for your next responsive site<br />
The idea of a grid system has been around since the <a href="http://960.gs/">960.gs</a> framework days. Web designers from all over the world began realizing the importance of pixel perfect alignment, gutter spacing and the rule of thirds. Gone are the days of grid-less web pages. And yes, things were great. Up until recently. <strong>Responsive web design</strong> was born.<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2013/11/bstrap.jpg" alt="bstrap" width="600" height="392" class="alignnone size-full wp-image-3768" /><br />
The problem was 960.gs, along with older frameworks had static page widths. Since we are now designing for multiple screen sizes, web frameworks had to adapt quickly.<br />
Enter Zurb <a href="http://foundation.zurb.com/">Foundation</a>. The first responsive framework that had web designers pee in their pants. Big sites such as <a href="http://www.esquire.co.uk/">Esquire UK</a>, <a href="http://upmagazine-tap.com/">Up Magazine</a> and <a href="http://thenextweb.com/">The Next Web</a> redesigned and we kept resizing our browsers in awe. We were simply amazed on how elements of the pages shifted gracefully. Horizontal scrollbars were a thing of the past and modern web design became &#8211; well, more modern.<br />
Now we have the latest and the greatest Bootstrap 3. Despite their awesome <a href="http://getbootstrap.com/css/">documentation</a>, my focus is to elaborate on just the heart of the framework &#8211; the grid system.<br />
Let&#8217;s dive in and see what Bootstrap&#8217;s grid system is all about.</p>
<h3>The Basic .col-xx-xx Classes</h3>
<p>Bootstraps column classes are what makes up the individual columns of the grid. It&#8217;s main purpose is to align your components into &#8211; you guessed it, columns. They&#8217;re designed to have 3 sections:<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2013/11/col-classes.jpg" alt="col-classes" width="557" height="223" class="noborder alignnone size-full wp-image-3769" /><br />
The prefix part &#8220;col&#8221; &#8211; just organizes all the col classes together, sort of like a namespace. And if you&#8217;ve worked with other frameworks in the past, the 3rd section &#8220;12&#8221; just tells us to occupy 12 columns out of the maximum 12. Pretty basic right?<br />
But what about the 2nd part? In our example, it&#8217;s the &#8220;lg&#8221;. This tells the browser to primarily use this for large screens only (default is 1170 pixels and above). Meaning, since we can use multiple classes on any element, <strong>we can <u>now</u> design for multiple sizes of the screen</strong>. Pretty powerful eh?<br />
<strong><u>So how does it do that?</u></strong><br />
So if you investigate the css, and look for that particular class (.col-lg-12), you will see that it&#8217;s enclosed in a media query:</p>
<pre>
@media (min-width: 1200px) {
.col-lg-12 {
    width: 100%;
  }
}
</pre>
<p>As a matter of fact, ALL of the &#8220;lg&#8221; classes are inside this media query. So the rule only applies to a specific screen resolution. The rest of the sizes (md for 970px, sm for 768px and xs for less than 768px) contains the rules for its respective classes. Pretty forward thinking right?<br />
<strong><u>Show me an example of its usefulness:</u></strong><br />
A common scenario is a two-column layout, with content on the left and sidebar on the right. With just a single class applied to both areas: red div has a class of <strong>col-lg-9</strong> and green div has <strong>col-lg-3</strong>.<br />
But most of the time &#8211; your sidebar&#8217;s content is not ready for a full page width in medium and small view ports. So you wish the sidebar doesn&#8217;t snap to the bottom right away right?<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2013/11/example1.gif" alt="example1" width="650" height="384" class="alignnone size-full wp-image-3770" /><br />
<strong>The solution:</strong> apply multiple .col classes into the same divs (one for each of the view port sizes). Take a look at the next example &#8211; where we apply a different column number ONLY on the extra small (<strong>.col-xs-12</strong>).<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2013/11/example2.gif" alt="example2" width="650" height="384" class="alignnone size-full wp-image-3771" /><br />
You see how the divs retained their 2 column layout all the way until the extra small view port is reached. Only then, did our sidebar snap to the bottom at full width. So you see how <strong>useful</strong> this is yet?</p>
<h3>Classes &#8220;row&#8221; and &#8220;container&#8221;</h3>
<p>Let&#8217;s jump out of the columns and look at the classes that wrap them. We have two important classes that do just that.<br />
<strong><u>.row</u></strong><br />
Just as the word describes &#8211; a row is something that is on one horizontal layer. Similar to a &#8220;record&#8221; in a database, or a &#8220;row&#8221; in a table. In Bootstrap, if you want elements to be in one horizontal layer &#8211; use a class <strong>.row</strong>.<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2013/11/example3.gif" alt="example3" width="650" height="384" class="alignnone size-full wp-image-3772" /><br />
The dark grey divs both have a class &#8220;.row&#8221;. A <strong>row</strong> basically acts as a traditional div tag, but instead can be applied as a class. I&#8217;ve used class .row on a header or footer tag &#8211; and it works really well.<br />
<strong><u>.container</u></strong><br />
Ideally, you add your HTML elements that need to be grouped together inside a class .container. The &#8220;max-width&#8221; properties for each break point (the media queries) are defined in this class. It is a very important class. One that is required to make things work the way they do.<br />
According to Bootstrap&#8217;s docs, containers are:</p>
<blockquote><p>
Easily center a page&#8217;s contents by wrapping its contents in a .container. Containers set max-width at various media query breakpoints to match our grid system.
</p></blockquote>
<p>Containers also follow the default padding rule of 15 pixels on each side. So the contents are automatically flushed together with just the right amount of gutter space all the time.</p>
<h3>How does Nesting work?</h3>
<p>Nesting means adding more .col classes inside of existing .col classes. Most of the time, you would need to add a .row class first &#8211; before nesting your .col divs inside in order to see desired results.<br />
<strong>So when do you need to nest?</strong><br />
All the time! If you inspect most HTML documents &#8211; it&#8217;s already a series of nested DOM elements so nesting your .col classes is already expected behavior. Although in Bootstrap, nesting will save you a lot of work calculating and deciding how wide a column has to be.<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2013/11/example4.gif" alt="example4" width="650" height="384" class="alignnone size-full wp-image-3773" /><br />
See both green divs have that have .col-lg-6 classes? These are nested inside the red div (the parent div).  Also, notice that a nested .col-lg-6 class takes up 50% of the parent div&#8217;s width. In other words, all you really need to remember is the 12 grid rule &#8211; no matter how deep the nesting goes.<br />
Note that I also applied the multiple classes technique (discussed above) to the child classes shown in the screenshot above. This is so that when resized, both div&#8217;s retain it&#8217;s 6 column width &#8211; until the last view port kicks in.</p>
<h3>Pushing, Pulling and Offsetting</h3>
<p>For even deeper customization of the grid elements, Bootstrap allows you to shift the columns around. Push and pull classes allow you to move the column # times to the left (also know as pull), or # times to the right (push).<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2013/11/ordering.jpg" alt="ordering" width="475" height="228" class="noborder alignnone size-full wp-image-3775" /><br />
So consider the markup below. Even though the green div is written right above the red div, the push and pull classes allows us to order them as if they were otherwise.</p>
<pre>
<div class="col-md-4 col-md-push-4"><p>green pushed 4</p></div>
<div class="col-md-4 col-md-pull-4"><p>red pulled 4</p></div>
</pre>
<p>The code above makes it so the divs appear in the browser in a different order.<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2013/11/push-pull.png" alt="push-pull" width="600" height="226" class="alignnone size-full wp-image-3776" /><br />
<strong><u>What makes it work?</u></strong><br />
If you inspect the push and pull classes, it utilizes the right and left property respectively &#8211; in percents. Since everything in Bootstrap is positioned relatively, using left and right will automatically just work.</p>
<pre>
@media (min-width: 992px)
   .col-md-pull-4 {
      right: 33.33333333333333%;
   }
   .col-md-push-4 {
      left: 33.33333333333333%;
   }
}
</pre>
<p><strong><u>Offsets</u></strong><br />
Offsetting classes is similar to push and pull classes &#8211; except for the &#8220;offset&#8221; keyword in the class name. Also similar to push and pull, the number in the class tells the browser how many columns to offset the element.<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2013/11/offsetting.jpg" alt="offsetting" width="525" height="235" class="alignnone noborder size-full wp-image-3774" /><br />
The difference with offsetting is that it uses the margin left property. So if your element is right next to another element &#8211; it will simply push itself against it by the designated percentage. See the code below for a <strong>.col-md-offset-4</strong> class:</p>
<pre>
@media (min-width: 992px)
 .col-md-offset-4 {
    margin-left: 33.33333333333333%;
 }
</pre>
<p>You see how this can be useful? You can simply apply this class to whichever you want to offset and still retain the responsive margins effectively. Pretty good right?</p>
<h3>Visibility Classes</h3>
<p>Although this has nothing to do with the grid, I thought it is worth a mention. We&#8217;ve all worked with a system that has a default class for a &#8220;display:none&#8221;. Well not only does Bootstrap have this (it&#8217;s called .hidden), but they&#8217;ve taken it an extra step. I like to call them the &#8220;visibility&#8221; classes.<br />
These classes do just that &#8211; controls the visibility of elements &#8211; across multiple views. Now, when designing your web site, you just now have to pick which elements to show, hide in large, medium and small views &#8211; then simply apply the visibility classes. The table below (taken from Bootstrap&#8217;s website) explains what the classes do in specific view ports.</p>
<style>
.is-visible {
color: #468847;
background-color: #dff0d8 !important;
}
</style>
<table class="table table-bordered table-striped responsive-utilities" style="margin-top:35px; margin-bottom:45px;">
<thead>
<tr>
<th></th>
<th>
              Extra small devices<br />
              <small>Phones (&lt;768px)</small>
            </th>
<th>
              Small devices<br />
              <small>Tablets (≥768px)</small>
            </th>
<th class="hidden-xs">
              Medium devices<br />
              <small>Desktops (≥992px)</small>
            </th>
<th class="hidden-xs">
              Large devices<br />
              <small>Desktops (≥1200px)</small>
            </th>
</tr>
</thead>
<tbody>
<tr>
<th><code>.visible-xs</code></th>
<td class="is-visible">Visible</td>
<td class="is-hidden">Hidden</td>
<td class="is-hidden hidden-xs">Hidden</td>
<td class="is-hidden hidden-xs">Hidden</td>
</tr>
<tr>
<th><code>.visible-sm</code></th>
<td class="is-hidden">Hidden</td>
<td class="is-visible">Visible</td>
<td class="is-hidden hidden-xs">Hidden</td>
<td class="is-hidden hidden-xs">Hidden</td>
</tr>
<tr>
<th><code>.visible-md</code></th>
<td class="is-hidden">Hidden</td>
<td class="is-hidden">Hidden</td>
<td class="is-visible hidden-xs">Visible</td>
<td class="is-hidden hidden-xs">Hidden</td>
</tr>
<tr>
<th><code>.visible-lg</code></th>
<td class="is-hidden">Hidden</td>
<td class="is-hidden">Hidden</td>
<td class="is-hidden hidden-xs">Hidden</td>
<td class="is-visible hidden-xs">Visible</td>
</tr>
</tbody>
<tbody>
<tr>
<th><code>.hidden-xs</code></th>
<td class="is-hidden">Hidden</td>
<td class="is-visible">Visible</td>
<td class="is-visible hidden-xs">Visible</td>
<td class="is-visible hidden-xs">Visible</td>
</tr>
<tr>
<th><code>.hidden-sm</code></th>
<td class="is-visible">Visible</td>
<td class="is-hidden">Hidden</td>
<td class="is-visible hidden-xs">Visible</td>
<td class="is-visible hidden-xs">Visible</td>
</tr>
<tr>
<th><code>.hidden-md</code></th>
<td class="is-visible">Visible</td>
<td class="is-visible">Visible</td>
<td class="is-hidden hidden-xs">Hidden</td>
<td class="is-visible hidden-xs">Visible</td>
</tr>
<tr>
<th><code>.hidden-lg</code></th>
<td class="is-visible">Visible</td>
<td class="is-visible">Visible</td>
<td class="is-visible hidden-xs">Visible</td>
<td class="is-hidden hidden-xs">Hidden</td>
</tr>
</tbody>
</table>
<h3>Conclusion</h3>
<p>I believe we&#8217;ve looked at the core classes that will get you up and running with Bootstrap&#8217;s grid system. This alone, if used properly &#8211; will save you countless hours of development time. Don&#8217;t forget to read up on the rest of Bootstrap&#8217;s many features such as the built-in components, Javascript plugins and of course, the rest of the styles. Good luck and have fun coding!<br />
Last of all, I would like to keep this an open discussion. If there&#8217;s anything that you would like to add, please leave a comment. I will be more than happy to answer questions or append to the article.</p>
<p>The post <a href="https://michaelsoriano.com/exploring-the-bootstrap-3-0-grid-system/">Exploring the Bootstrap 3.0 Grid System</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://michaelsoriano.com/exploring-the-bootstrap-3-0-grid-system/feed/</wfw:commentRss>
			<slash:comments>21</slash:comments>
		
		
			</item>
		<item>
		<title>Taming the Grid – Align your WordPress posts perfectly using PHP and CSS</title>
		<link>https://michaelsoriano.com/taming-the-grid-align-your-wordpress-posts-perfectly-using-php-and-css/</link>
					<comments>https://michaelsoriano.com/taming-the-grid-align-your-wordpress-posts-perfectly-using-php-and-css/#comments</comments>
		
		<dc:creator><![CDATA[Michael Soriano]]></dc:creator>
		<pubDate>Sat, 03 Oct 2009 23:39:12 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[grid]]></category>
		<guid isPermaLink="false">http://fearlessflyer.com/?p=750</guid>

					<description><![CDATA[<p>Grid based web design is becoming an art that each web developer must master. News portals, magazine layouts as well as showcase websites all adhere to the intricacies of the grid – which when mastered, is definitely a good addition to your web skill arsenal. We all know that a typical grid design uses some [&#8230;]</p>
<p>The post <a href="https://michaelsoriano.com/taming-the-grid-align-your-wordpress-posts-perfectly-using-php-and-css/">Taming the Grid – Align your WordPress posts perfectly using PHP and CSS</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Grid based web design is becoming an art that each web developer must master. News portals, magazine layouts as well as showcase websites all adhere to the intricacies of the grid – which when mastered, is definitely a good addition to your web skill arsenal.<br />
We all know that a typical grid design uses some kind of block containers to house content. This block container may be DIV or list that span a couple, three or four times across inside a parent DIV. Now with CSS – we simply apply the proper left or right margins to all the containers except the last one in the pattern:<br />
<img decoding="async" class="alignnone size-full wp-image-751" style="border: 0;" title="children DIVs with different margin settings" src="https://michaelsoriano.com/wp-content/uploads/2009/10/illustration1.png" alt="illustration1" width="576" height="222" /><br />
The result is the children containers line up perfectly inside the parent DIV. To achieve this effect we apply the same class to all the children DIVs, and append a unique class to the last one like below:<br />
<strong>HTML</strong><br />
<script src="https://gist.github.com/michaelsoriano/26d793203ac0f2947151.js"></script><br />
<strong>CSS</strong><br />
<script src="https://gist.github.com/michaelsoriano/7dbda292f2f1622cc458.js"></script></p>
<h3>The Challenge:</h3>
<p>Since content inside these containers are typically coded using a form of recursive technique such as “the Loop” in Wordress; how are we to designate that unique class to that second, third or fourth child DIV?<br />
For instance, if we were to house our posts inside one of these children DIVs, the PHP would look something like below:<br />
<script src="https://gist.github.com/michaelsoriano/c798775234fe5255febc.js"></script><br />
This block of code inside the parent DIV will just keep repeating for all posts with the same “child” class. We need to a way to select just the second, third or fourth child to not have that extra margin.</p>
<h3>The Trick</h3>
<p>A not so popular arithmetic operator known as the modulus &#8211; represented by a (%) symbol is what we’ll use to do the trick. The modulus operator is the same as division &#8211; but returns the remainder instead. Since we’re only targeting every “nth” div or child item, all we need to create is a pattern that has a multiple of some value in order to apply our special class. Take a look at the code below:<br />
<script src="https://gist.github.com/michaelsoriano/eae51d611bac408562ed.js"></script><br />
First we create a variable $r_count and initialize its value at 1 right before the loop starts. Right after the call for the posts, we add a conditional statement with the modulus operator for 3 is equal to 0 (since we want every 3rd element to have that unique “last” class), everything else returns empty. Lastly, we increment $r_count by one.<br />
In our HTML, we call the regular “child” class, then we echo our special $r_class. The end result will be an alternating call of styles depending on what we define for our modulus operator:<br />
<img decoding="async" class="alignnone size-full wp-image-753" style="border: 0;" title="A view of the source code of our finished product. Notice the additional class for the DIVs" src="https://michaelsoriano.com/wp-content/uploads/2009/10/illustration2.png" alt="illustration2" width="576" height="500" /><br />
Of course &#8211; depending on the number of columns you would like to display &#8211; all you have to do is change the modulus operand and you should get the same effect.</p>
<p>The post <a href="https://michaelsoriano.com/taming-the-grid-align-your-wordpress-posts-perfectly-using-php-and-css/">Taming the Grid – Align your WordPress posts perfectly using PHP and CSS</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://michaelsoriano.com/taming-the-grid-align-your-wordpress-posts-perfectly-using-php-and-css/feed/</wfw:commentRss>
			<slash:comments>13</slash:comments>
		
		
			</item>
	</channel>
</rss>
