<?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>frameworks Archives - Michael Soriano</title>
	<atom:link href="https://michaelsoriano.com/tag/frameworks/feed/" rel="self" type="application/rss+xml" />
	<link>https://michaelsoriano.com/tag/frameworks/</link>
	<description>I turn code into captivating user experiences for the web</description>
	<lastBuildDate>Sun, 10 Jul 2022 17:56:00 +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>Let’s build a WordPress theme with React: Part 3 (The Loop)</title>
		<link>https://michaelsoriano.com/lets-build-a-wordpress-theme-with-react-part-3-the-loop/</link>
					<comments>https://michaelsoriano.com/lets-build-a-wordpress-theme-with-react-part-3-the-loop/#comments</comments>
		
		<dc:creator><![CDATA[Michael Soriano]]></dc:creator>
		<pubDate>Thu, 03 Oct 2019 21:24:06 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[React]]></category>
		<guid isPermaLink="false">http://michaelsoriano.com/?p=6985</guid>

					<description><![CDATA[<p>Okay its been a while since I last posted. Let&#8217;s continue with Barebones React WP theme. The last time we left off, we introduced the concept of &#8220;The Loop&#8220;. But we really didn&#8217;t get into what its all about. Let&#8217;s describe what this piece is doing. In WordPress themes &#8211; there is the &#8220;The Loop&#8220;, [&#8230;]</p>
<p>The post <a href="https://michaelsoriano.com/lets-build-a-wordpress-theme-with-react-part-3-the-loop/">Let’s build a WordPress theme with React: Part 3 (The Loop)</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Okay its been a while since I last posted. Let&#8217;s continue with Barebones React WP theme. The last time we left off, we introduced the concept of &#8220;<strong>The Loop</strong>&#8220;. But we really didn&#8217;t get into what its all about. Let&#8217;s describe what this piece is doing. </p>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="700" height="400" src="https://michaelsoriano.com/wp-content/uploads/2019/05/react-wp.jpg" alt="react wordpress" class="wp-image-6940" srcset="https://michaelsoriano.com/wp-content/uploads/2019/05/react-wp.jpg 700w, https://michaelsoriano.com/wp-content/uploads/2019/05/react-wp-300x171.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></figure>



<p>In WordPress themes &#8211; there is the &#8220;<a href="https://codex.wordpress.org/the_loop">The Loop</a>&#8220;, where it&#8217;s a &#8220;catch all&#8221; for all of the post content at a given query. This may be a page, a post or a series of posts. It all goes to &#8220;<strong>The Loop</strong>&#8220;, where inside that loop &#8211; are methods that make retrieving post data easy. Inside the loop, we can do something like &#8220;<em>get_the_ID()</em>&#8221; or &#8220;<em>the_title()</em>&#8221; &#8211; which will output the post id or its title. </p>



<p>We&#8217;re trying to achieve the same thing in Barebones. We have &#8220;TheLoop&#8221; component &#8211; which we&#8217;ll be adding in our &#8220;partials&#8221; directory. This component will be used everywhere &#8211; in single posts, pages or archive pages such as search etc. </p>



<p>Previously, we were just outputting the slug in TheLoop. The modified version is shown below. </p>



<pre class="wp-block-code"><code lang="jsx" class="language-jsx line-numbers">import React from 'react';
import WithConsumer from '../context/WithConsumer';
import ThePost from './ThePost';
const TheLoop = ({ context }) =&gt; {
    const posts = () =&gt; context.posts;
    const pos = posts();
    let results = '';
    if(context.appError){
      results = &lt;div className="app-error"&gt;{context.appError}&lt;/div&gt;;
    }else{
      if(pos.length === 0){
        results = &lt;div className="no-results"&gt;no results&lt;/div&gt;;
      }else{
        results = pos.map(function(item,i){
             return &lt;ThePost key={i} index={i}&gt;&lt;/ThePost&gt;
           })
      }
    }
    return (results);
};
export default WithConsumer(TheLoop);</code></pre>



<p>There&#8217;s really not a lot going on. We are simply isolating the &#8220;loop&#8221; logic in this component. So we don&#8217;t have to do the same elsewhere. But the key points to see is we&#8217;re getting the results from our Context. And depending on the count of the result, if there&#8217;s more than 0, we &#8211; return the &#8220;<strong>ThePost</strong>&#8221; component (more on this later).</p>



<p>If there&#8217;s no results &#8211; we simply return a div with the text &#8220;no results&#8221;. </p>



<p>If  there&#8217;s an error &#8211; return the error message. </p>



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



<p>ThePost component has all of the methods necessary to output the post data. This resembles WP&#8217;s &#8220;<strong>the_post()</strong>&#8221; in PHP. In here, we have access to the context.posts, filtered by the index. The index is a prop that we pass coming from TheLoop. So now, each <strong>item</strong> is a post:</p>



<pre title="ThePost" class="wp-block-code"><code lang="jsx" class="language-jsx line-numbers">const ThePost = ({index,context}) =&gt; {
    const posts = () =&gt; context.posts;
    const item = posts()[index];
    let linkPrefix = item.type === 'page' ? '/page/' : '/post/';
    let theContent = '';
    switch(context.route){
        case '/': //if homepage,
        case '/search/:term': //or if search
        case '/category/:catid': //or if search
            theContent = item.excerpt.rendered; //show excerpt only
        break;
        default: //for single, pages - show entire content
            theContent = item.content.rendered;
        break;
    }
    return (
        &lt;div id={'post-id-'+item.id} className={'post-item'}&gt;
            &lt;h1&gt;&lt;Link to={linkPrefix+item.slug}&gt;{item.title.rendered}&lt;/Link&gt;&lt;/h1&gt;
            &lt;PostMeta index={index}&gt;&lt;/PostMeta&gt;
            &lt;div className="post-content" dangerouslySetInnerHTML={{__html:theContent}}&gt;&lt;/div&gt;
        &lt;/div&gt;);
};</code></pre>



<p>We have to determine if its a &#8220;post&#8221; or a &#8220;page&#8221; (line 6). This will match with the post/page route in our <em>index.js</em>.  </p>



<p>Then we have a switch statement, that checks the route. If its an archive page (like search, category) &#8211; let&#8217;s output only the content excerpt. Otherwise &#8211; if its a single, let&#8217;s output the entire thing. </p>



<p>The PostMeta component is also a new component that we haven&#8217;t built yet. Let&#8217;s add that in a little bit. For now, let&#8217;s grab the data.</p>



<h3 class="wp-block-heading"><strong>Context</strong>.js</h3>



<p>Now there are a few things we need to do to our Context component for the loop to work. Remember in our loop, we&#8217;ve setup up the links using &#8220;Link to&#8221;. We need to map these links to right REST url endpoint &#8211; so we can get the right data and put it in the right data store. </p>



<p>Remember, all of the data is inside this one file. May it be posts, comments &#8211; even methods that manipulate this data is in this component. So this file is extremely important. </p>



<p>Let&#8217;s start by adding the containers for our state. In the constructor, add the following:</p>



<pre class="wp-block-code"><code lang="jsx" class="language-jsx">constructor(props) {
    super(props);
    let restType = this.getRestType(props.router.match.path);
    let route = props.router.match.path;
    let slug = props.router.match.params.slug ? props.router.match.params.slug : '';
    this.state = {
      slug : slug,
      restType : restType,
      route : route,
      posts : []
    };
  }</code></pre>



<p>Our state now has the necessary containers for the data we need. Primarily the &#8220;posts&#8221; array is what we aim to fill. Let&#8217;s add some actions in our lifecycle hook: componentDidMount:</p>



<pre class="wp-block-code"><code lang="jsx" class="language-jsx">componentDidMount(){
    this.getPosts(this.buildUrl());
}</code></pre>



<p>Let&#8217;s build a couple of functions &#8211; one to build the REST url endpoint, and the other to fetch the posts: </p>



<pre class="wp-block-code"><code lang="jsx" class="language-jsx line-numbers">buildUrl(){
    let url = '/wp-json/wp/v2/';
    switch(this.state.restType){
      case 'page':
        url += 'pages/?slug=' + this.state.slug
      break;
      case 'post':
      default:
        url += 'posts/?slug=' + this.state.slug ;
        break;
    }
    return url;
  }
 getPosts (url){
    let self = this;
    Axios.get(url).then((response)=&gt;{
      self.setState({
        posts : response.data
    }).catch(function(error){
      console.log(error);
      self.appError = 'An unexpected error occurred';
    });
  }
</code></pre>



<p>That should set our post and page endpoints, bringing back data from the API.  Make sure that TheLoop is in your Archive and Single components. </p>



<p>And if all is good, we should have something like below: </p>



<figure class="wp-block-image border"><img decoding="async" width="700" height="527" src="https://michaelsoriano.com/wp-content/uploads/2019/06/post-page.gif" alt="" class="wp-image-6986"/></figure>



<p>Remember that we have to change our permalinks in WordPress to match our route. </p>



<h3 class="wp-block-heading">Add Paging</h3>



<p>Paging is necessary especially for archive pages. You only want to see the latest X number of posts, then show the next X &#8211; and so on. </p>



<p>In <strong>Archive.js</strong> &#8211; simply add the pager component (that we still have to build), right underneath the loop:</p>



<pre class="wp-block-code"><code lang="jsx" class="language-jsx"> &lt;TheLoop&gt;&lt;/TheLoop&gt;
 &lt;Pager&gt;&lt;/Pager&gt;</code></pre>



<p>Now let&#8217;s create a file in our partials folder &#8211; call it <strong>Pager.js</strong>. </p>



<pre title="Pager.js" class="wp-block-code"><code lang="jsx" class="language-jsx line-numbers">import React, { useEffect } from 'react';
import WithConsumer from '../context/WithConsumer';
const Pager = function ({context}){
    let prevBtn =  React.createRef();
    let nextBtn =  React.createRef();
    let curPage = () =&gt; context.currentPage;
    let totalPages = () =&gt; context.totalPages;
    useEffect(() =&gt; {
        prevBtn.current.disabled = true;
        // eslint-disable-next-line react-hooks/exhaustive-deps
    },[]);
    function nextClicked(){
        context.nextClicked();
        if(parseInt(totalPages()) === parseInt(curPage() + 1) ){
            nextBtn.current.disabled = true;
        }
        prevBtn.current.disabled = false;
    }
    function previousClicked(){
        context.previousClicked();
        if(parseInt(curPage()-1) === 1 ){
            prevBtn.current.disabled = true;
        }
        nextBtn.current.disabled = false;
    }
    function pagerClass(){
        let cls = 'Pager';
        if(parseInt(totalPages()) &lt;=1 ||
            context.appError){
            cls = 'Pager hidden';
        }
        return cls;
    }
    return (
        &lt;div className={pagerClass()}&gt;
        &lt;button ref={prevBtn} onClick={previousClicked}&gt;Previous&lt;/button&gt;
        &lt;button ref={nextBtn} onClick={nextClicked}&gt;Next&lt;/button&gt;
        &lt;div className="PagerText"&gt;Page
            &lt;span dangerouslySetInnerHTML={{__html: curPage()}}&gt;&lt;/span&gt; of
            &lt;span dangerouslySetInnerHTML={{__html: totalPages()}}&gt;&lt;/span&gt;&lt;/div&gt;
        &lt;/div&gt;
    )
}
export default WithConsumer(Pager);</code></pre>



<p>Now the pager logic is a little more involved. Above simply outputs our &#8220;Next&#8221; and &#8220;Previous&#8221; buttons &#8211; depending on the number of pages. Fortunately, WordPress&#8217;s API makes this easy for us. We have 2 important header properties from each response called &#8221; X-WP-Total&#8221; and &#8221; X-WP-TotalPages&#8221;. From this we can determine the logic needed for our paging.</p>



<p>Going back to context, we need to modify our state, add some methods that modify that state, as well as modify our rest calls.</p>



<pre class="wp-block-code"><code lang="jsx" class="language-jsx">//ADD THIS TO this.state IN THE CONSTRUCTOR
currentPage : 1,
totalPages : 0,
nextClicked : this.nextClicked.bind(this),
previousClicked : this.previousClicked.bind(this), </code></pre>



<p>Above shows our new state. Note that currentPage always starts at 1. Totalpages &#8211; we update on every call, then we bind 2 methods to &#8220;this&#8221;. </p>



<p>Next, let&#8217;s add modify our <strong>buildUrl()</strong> method to have the page parameters from our state. </p>



<pre class="wp-block-code"><code lang="jsx" class="language-jsx"> case 'post':
      default:
        url += this.state.slug ? 'posts/?slug=' + this.state.slug : 'posts/?page=' + this.state.currentPage;
        break;    </code></pre>



<p>Above simply appends the current page to the url endpoint. In our <strong>getPosts()</strong> method, we update our totalPages in state with each response: </p>



<pre class="wp-block-code"><code lang="jsx" class="language-jsx">Axios.get(url).then((response)=&gt;{
      self.setState({
        posts : response.data,
        totalPages : response.headers['x-wp-totalpages']
      }</code></pre>



<p>Now all we need to do is create two functions &#8211; which correspond to which button was clicked: </p>



<pre class="wp-block-code"><code lang="jsx" class="language-jsx line-numbers">  nextClicked (){
    let newPage = this.state.currentPage + 1;
    this.setState({
      currentPage : newPage
    },function(){
      this.getPosts(this.buildUrl());
    })
  }
  previousClicked (){
    let newPage = this.state.currentPage - 1;
    this.setState({
      currentPage : newPage
    },function(){
      this.getPosts(this.buildUrl());
    })
  }</code></pre>



<p>Both of these methods are called from our Pager component &#8211; which we access by doing <em>context.XXXClicked()</em>. Pretty neat right? </p>



<p>We also let the front end decide whether to show or hide the respective buttons. So if all goes well, we have something like below: </p>



<figure class="wp-block-image border"><img decoding="async" width="700" height="572" src="https://michaelsoriano.com/wp-content/uploads/2019/06/paging.gif" alt="" class="wp-image-6988"/></figure>



<p>Okay that should be it for this round. A lot going on above. I suggest you download the <a href="https://github.com/michaelsoriano/barebones">code</a> and run it yourself &#8211; along with following the steps. Note there are a lot of omitted code above. Only the important steps are outlined &#8211; the rest is up to you.</p>
<p>The post <a href="https://michaelsoriano.com/lets-build-a-wordpress-theme-with-react-part-3-the-loop/">Let’s build a WordPress theme with React: Part 3 (The Loop)</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://michaelsoriano.com/lets-build-a-wordpress-theme-with-react-part-3-the-loop/feed/</wfw:commentRss>
			<slash:comments>10</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>
	</channel>
</rss>
