Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Bootstrap 4 By Example

You're reading from  Bootstrap 4 By Example

Product type Book
Published in Mar 2016
Publisher Packt
ISBN-13 9781785288876
Pages 324 pages
Edition 1st Edition
Languages

Table of Contents (18) Chapters

Bootstrap 4 By Example
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
1. Getting Started 2. Creating a Solid Scaffolding 3. Yes, You Should Go Mobile First 4. Applying the Bootstrap Style 5. Making It Fancy 6. Can You Build a Web App? 7. Of Course, You Can Build a Web App! 8. Working with JavaScript 9. Entering in the Advanced Mode 10. Bringing Components to Life 11. Making It Your Taste Index

Chapter 3. Yes, You Should Go Mobile First

You should be asking yourself, "I thought that we should first do the layout in mobile and then go to the desktop version. Why are we in the opposing way?"

Sorry, you are right! We should always go mobile-first. We went the opposite direction just for learning purposes and now we are going to fix it.

In the current chapter, we will focus on mobile design and site responsiveness with the help of the Bootstrap framework by learning how to change the page layout for different viewport, changing the content, and more. The key points of the chapter are as follows:

  • Mobile-first development

  • Debugging for any device

  • Bootstrap grid system for different resolutions

To figure out what, we will continue with the landing page that we developed in the last chapter.

Making it greater


Maybe you have asked yourself (or even searched for) the reason for the mobile-first paradigm trend. It is simple and makes complete sense for speeding up your development.

The main argument for the mobile-first paradigm is that it is easier to make it than to shrink it. In other words, if you make a desktop version of the web page (known as responsive design or mobile last) first and then adjust the website for mobile, it has a 99 percent probability of breaking the layout at some point and you will have to fix a lot of things.

On the other hand, if you create the mobile version first, naturally the website will use (or show) less content than the desktop version. So, it will be easier to just add the content, place the things in the right places, and create the fully responsiveness stack.

The following figure tries to illustrate this concept. Going mobile last, you will get a degraded, sharped, and crappy layout and you will get a progressively enhanced, future-friendly...

Bootstrap and the mobile-first design


In the beginning of Bootstrap, there was no concept of mobile-first. It was first used for responsive design web pages. With the Version 3 of the framework, the concept of mobile-first became very solid in the community.

The whole code of the scaffolding system was rewritten to become mobile-first from the start. They decided to reformulate how to set the grid instead of just adding mobile styles. This made a great impact in compatibility between versions older than v3, but was crucial for making the framework even more popular.

As we saw in the first chapter, to ensure the proper rendering of the page, set the correct viewport at the <head> tag:

<meta name="viewport" content="width=device-width, initial-scale=1">

How to debug different viewports at the browser


Let's see how to debug different viewports using the Google Chrome web browser. Even if you already know that you can skip this section, it is important to refresh the steps for doing that.

First of all, open the current landing page project that we will continue working with in this chapter in the Google Chrome browser. In the page, you need to select the Developer tools option. There are many ways to open this menu:

  • Right-click at any place on the page and click on the last option Element inspector

  • Go to the setting (the sandwich button at the top-right of the address bar), click on More tools, and select Developer tools

  • The shortcut to open it is Ctrl + Shift + I (cmd for OS X users)

  • F12 in Windows also works (this is an Internet Explorer legacy)

In the Developer tools, click in the mobile phone on the left of a magnifier, as shown in the following screenshot:

It will change the display of the viewport to a certain device and you can also set...

Cleaning up the mess


First, we will stop the line from breaking in the Ctrl + D text in the second row of our design. For fixing this issue, we will create our first line of CSS code. Add the <head> tag to a custom CSS file. Remember to place it below the bootstrap.css import line:

<link rel="stylesheet" href="css/base.css">

In the base.css file, create a helper class rule for .nowrap:

.nowrap {
    white-space: nowrap;
}

In the HTML file, add the created class to the <kbd> element (line 43):

<kbd class="nowrap"><kbd>ctrl</kbd> + <kbd>d</kbd></kbd>

Reload the page and you'll see that one problem is solved. Now, let's fix the horizontal scroll. Can you figure out what is making the unintended horizontal scroll? A tip, the problem is in the table!

Tip

What is the meaning of the white-space CSS property?

The white-space property specifies how whitespace is handled inside an element. The default is normal, where the line breaks will occur when...

Creating the landing page for different devices


Now that we have fixed everything and learned some things about media queries and CSS3 properties, let's play with our layout and change it a bit for different devices. We will be starting with mobile and go further until we reach large desktops.

To do so, we must apply the column class for the specific viewport, as we did for medium displays using the .col-md-* class. The following table was presented in the previous chapter to show the different classes and the resolutions applicable for specific classes:

Summary


We have completed another chapter. Here, we discussed why we should always go mobile-first if we want to make a web page for every viewport, from mobile to large desktop. Making things bigger is always easier and causes less issues, so start small with mobile devices and evolve the web page until it reaches large desktop resolutions.

We saw how to debug different devices using our browser and set the right classes for each viewport. We now have our example of landing page with full stack responsiveness, working well in any device.

We covered the grid options for various devices resolutions using the mobile-first methodology—starting with mobile and going further until the large desktop version.

The main lesson of this chapter was that we always should go mobile-first. We did not follow this approach at first and because of that, we faced some problems that we could have eliminated if we had started mobile-first.

It was not mentioned before, but going mobile-first helps the whole team...

lock icon The rest of the chapter is locked
You have been reading a chapter from
Bootstrap 4 By Example
Published in: Mar 2016 Publisher: Packt ISBN-13: 9781785288876
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}
 

Extra small devices (phones < 544px / 34em)

Small devices (tablets ≥ 544px / 34em and < 768px / 48em)

Medium devices (desktops ≥ 768px /48em < 900px / 62em)

Large devices (desktops ≥ 900px / 62em < 1200px 75em)

Extra-large devices (Desktops ≥ 1200px / 75em)

Grid behavior

Horizontal lines at all times

Collapse at start and fit column grid

Container fixed width

Auto

544px or 34rem

750px or 45rem

970px or 60rem...