{"id":10308,"date":"2018-06-04T15:46:13","date_gmt":"2018-06-04T21:46:13","guid":{"rendered":"http:\/\/www.mrc-productivity.com\/techblog\/?p=10308"},"modified":"2023-06-21T12:03:04","modified_gmt":"2023-06-21T18:03:04","slug":"bootstrap-basics","status":"publish","type":"ht_kb","link":"https:\/\/www.mrc-productivity.com\/techblog\/?ht_kb=bootstrap-basics","title":{"rendered":"Fun with Bootstrap"},"content":{"rendered":"\n<p>Recently I was able to use m-Power&#8217;s new industry standard Bootstrap templates for a customer project. The goal of the project was to modernize their online shopping portal and make the site mobile friendly. These objectives served as a perfect fit for the new Bootstrap themed templates. While building the project, I found myself repeatedly relying on a handful of the Bootstrap features and I wanted to share those with the m-Power community. Here are five (of many) basic bootstrap features:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"grid\">1. The Responsive Grid System<\/h3>\n\n\n\n<p>Bootstrap&#8217;s built-in responsiveness is extremely easy to grasp. The framework will attempt to maximize the screen size of the device being used. I often found the need to control the size of my elements depending on the screen size and would use different combinations of the column sizing to achieve that control. It may be common to see the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;div class=\"row\"&gt;<br>&lt;div class=\"col-md-10 col-xl-8\"&gt;&lt;\/div&gt;<br>&lt;\/div&gt;<\/code><\/pre>\n\n\n\n<p>The above code would render differently based on the device type (click to enlarge):<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"\/techblog\/images\/boot_basics\/grid1.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"\/techblog\/images\/boot_basics\/thumbgrid1.png\"\/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"\/techblog\/images\/boot_basics\/grid2.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"\/techblog\/images\/boot_basics\/thumbgrid2.png\"\/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"\/techblog\/images\/boot_basics\/grid3.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"\/techblog\/images\/boot_basics\/grid3.png\"\/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.mrc-productivity.com\/techblog\/\/images\/boot_basics\/grid4.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"\/techblog\/images\/boot_basics\/grid4.png\"\/><\/a><\/figure>\n<\/figure>\n\n\n\n<p><strong>Extra Small (col-*)<\/strong> &#8212; Smartphones in portrait mode (&lt;576px). This is the default and no size prefix is needed. When not specified, the width will default to the full 12 columns. Because I did not specify a column size, my element would use the full screen width on a smartphone.<br><strong>Small (col-sm-*)<\/strong> &#8212; Smartphones in landscape mode (\u2265576px). Bootstrap responsiveness assumes a greater-than-or-equal-to approach when using column sizes. Because I did not specify a width for this size, small (sm) screens (landscape smartphones) would inherit the previously set width (the default 12 columns).<br><strong>Medium (col-md-*)<\/strong> &#8212; Tablets in portrait mode (\u2265768px). Setting the column size to 10 for medium (md) devices would take up 10-of-12 sections.<br><strong>Large (col-lg-*)<\/strong> &#8212; Tablets in landscape mode (\u2265992px). Because I did not specify a size for large (lg) screens, the width will inherit the size from the previously set width (10 columns from medium).<br><strong>Extra Large (col-xl-*)<\/strong> &#8212; Desktops\/Laptops (\u22651200px). Setting the column size to 8 for extra large (xl) devices will use 8-of-12 sections.<\/p>\n\n\n\n<p>Please visit the Bootstrap documentation about the <a title=\"Bootstrap Grid\" href=\"https:\/\/getbootstrap.com\/docs\/4.1\/layout\/grid\">Grid System<\/a> for more details.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"spacing\">2. Spacing<\/h3>\n\n\n\n<p>While the Bootstrap templates come pre-styled, many of my new elements benefited from custom spacing. Bootstrap&#8217;s easy spacing classes for margin and padding made this a breeze.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/techblog\/images\/boot_basics\/spacing1.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>Because most smartphone devices will have elements stack vertically you may want extra spacing on xs screen sizes, but no spacing on all other sizes.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/techblog\/images\/boot_basics\/spacing2.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>Therefore, you may use the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;div class=\"mb-3 mb-sm-0\">&lt;\/div><\/code><\/pre>\n\n\n\n<p>The &#8216;mb-3&#8217; class results in a bottom (b) margin (m) of 3. The &#8216;mb-sm-0&#8217; class will have no bottom margin on screen widths small and up.<\/p>\n\n\n\n<p>Notice, the &#8216;mb-3&#8217; class does not specify a width size as no specification implies the default xs (smarthphone portrait) size. Also remember the responsive breakpoints assume a greater-than-or-equal-to relationship which is why I only need to specify the &#8216;sm&#8217; size in the &#8216;mb-sm-0&#8217; class. This means all devices above xs will have no bottom margin.<\/p>\n\n\n\n<p>Please visit the Bootstrap documentation for more details regarding <a title=\"spacing\" href=\"https:\/\/getbootstrap.com\/docs\/4.1\/utilities\/spacing\/\">spacing classes<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"justify\">3. Justifying and Aligning Content<\/h3>\n\n\n\n<p>Going right along with managing the spacing of my custom elements, I frequently needed to equally align my elements. Bootstrap made this possible by utilizing flexbox. Along with &#8216;d-flex&#8217;, the class &#8216;justify-content-center&#8217;, will automatically push the child elements to equal distances inside their container. By using the following code, I was able to equally justify the instruction text and the button of each row. Just as easy is the ability to vertically align the elements in each row with &#8216;align-items-*&#8217;.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;div class=\"d-flex justify-content-between align-items-center\">>&lt;\/div><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"\/techblog\/images\/boot_basics\/justify.png\"><img decoding=\"async\" src=\"\/techblog\/images\/boot_basics\/justify.png\" alt=\"justify content\"\/><\/a><\/figure>\n\n\n\n<p>Please visit the Bootstrap documentation over the <a href=\"https:\/\/getbootstrap.com\/docs\/4.0\/utilities\/flex\/#justify-content\">Justify Content<\/a> and <a href=\"https:\/\/getbootstrap.com\/docs\/4.0\/utilities\/flex\/#align-items\">Align Items<\/a> utilities for more details.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"visibility\">4. Hiding and Displaying<\/h3>\n\n\n\n<p>Another example of working with responsive breakpoints is the ability to conditionally display or hide elements based on screen size. Because you want to maximize your screen space, often you&#8217;ll hide elements on smaller devices and display them on larger screens. One instance I used this was the shopping cart amount in the header.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/techblog\/images\/boot_basics\/header1.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>There is not enough horizontal room on the header if I kept the &#8216;Current Cart&#8217; text. As you can see below, the element would wrap.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/techblog\/images\/boot_basics\/header2.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>Adding this code will hide the text on xs device widths and display on screen sizes medium and up.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;div class=\"d-none d-md-inline\">Current Cart&lt;\/div><\/code><\/pre>\n\n\n\n<p>The class &#8216;d-none&#8217; will be read as do not display on xs devices, whereas &#8216;d-md-inline&#8217; will display the element inline on screen sizes medium and greater.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/techblog\/images\/boot_basics\/header3.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>Notice I used the same method for other aspects of the header. The banner text on the left displays differently on a smartphone as well as the &#8216;Home&#8217; and &#8216;Sign Off&#8217; links on the right-side.<\/p>\n\n\n\n<p>Please visit the Bootstrap documentation for more details regarding <a title=\"Visibility Display\" href=\"https:\/\/getbootstrap.com\/docs\/4.0\/utilities\/display\/\">Displaying Elements<\/a> for more details.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"cards\">5. Card Panels<\/h3>\n\n\n\n<p>The card component is a simple, built-in method of organizing your data into elegant containers. Cards are a great way of separating unique data groups onto the page.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"\/techblog\/images\/boot_basics\/card.png\"><img decoding=\"async\" src=\"\/techblog\/images\/boot_basics\/card.png\" alt=\"Cards\"\/><\/a><\/figure>\n\n\n\n<p>m-Power has two approaches of inserting cards: Via the <a href=\"https:\/\/www.mrc-productivity.com\/docs\/bootstrap\/form-layout#formPanels\">Form Layout mode<\/a> or the <a href=\"https:\/\/www.mrc-productivity.com\/docs\/bootstrap\/element-window-in-m-painter#toolbar\">HTML toolbar<\/a> of the &#8216;insert element&#8217; feature in m-Painter.<\/p>\n\n\n\n<p>Please visit the Bootstrap documentation for more details regarding <a title=\"Visibility Display\" href=\"https:\/\/getbootstrap.com\/docs\/4.0\/components\/card\/\">Card Components<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"classes\">And many more&#8230;<\/h3>\n\n\n\n<p>The above are just a handful of the many Bootstrap features available. You can read the <a href=\"https:\/\/getbootstrap.com\/docs\/4.0\/layout\/overview\/\">full Bootstrap documentation<\/a> for all other built-in Bootstrap classes. Additionally, there are countless other online tutorials and videos discussing Bootstrap. One simple and basic crash course can be found on this <a href=\"https:\/\/medium.freecodecamp.org\/want-to-learn-bootstrap-4-heres-our-free-10-part-course-happy-easter-35c004dc45a4\">free 10 part guide on getting started with Bootstrap<\/a>.<\/p>\n\n\n\n<p>Please feel free to let us know of your favorite Bootstrap features and\/or tutorials.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I was able to use m-Power&#8217;s new industry standard Bootstrap templates for a customer project. The goal of the project was to modernize their online shopping portal and make the site mobile friendly. These objectives served as a perfect fit for the new Bootstrap themed templates. While building the&#8230;<\/p>\n","protected":false},"author":10,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[154],"ht-kb-tag":[],"class_list":["post-10308","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-bootstrap"],"_links":{"self":[{"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/ht-kb\/10308","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10308"}],"version-history":[{"count":66,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/ht-kb\/10308\/revisions"}],"predecessor-version":[{"id":11928,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/ht-kb\/10308\/revisions\/11928"}],"wp:attachment":[{"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10308"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=%2Fwp%2Fv2%2Fht-kb-category&post=10308"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=%2Fwp%2Fv2%2Fht-kb-tag&post=10308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}