I had previously ran a WordPress site that hosted an example of bootstrap. I messed around with bootstrap when creating a custom WordPress theme from scratch using HTML, CSS, and PHP. Linking bootstrap to my project allowed me to create a theme that was responsive to the size of the view port. This enabled the website to resize and show / hide elements accordingly when the browser window was resized or otherwise manipulated.
Being a bit of a data hoarder, I still had the WordPress database laying around and recently recovered it along with some old content within. Though these are outdated and no longer being worked on, they are neat to look back on. Not only is the bootstrap example found below old, but the writing is identical to the post I made back in 2016. For this reason, though I’m writing this short explanation now in 2020, this post is dated according to the original post date.
October 20, 2016
Bootstrap is one of the many CSS frameworks available to make the common tasks in CSS easier to achieve, saving you time in rewriting various CSS rules and selectors. To use Bootstrap, you will have to include some files in your workspace, and link them accordingly so they will be recognized across your entire project. There are a few ways to do this, the easiest way is to include the CSS within the ‘Head’ of your website. There are, however, a few other ways to do this that could be considered healthier for your web page. For the sake of simplicity and to save you any headaches during what I’m assuming is your learning process, we will stick to the basics.
So, after you’ve included this into your HTML document, it should look something like this…
Ok, so we’ve included Bootstrap into our HTML project, but how do we use it?
Bootstrap is a CSS frameworks, which consists of classes you can apply to your HTML. If you’re completely new to Bootstrap, Hacker Themes provides a great reference of all the classes bootstrap contains. Looking at this can be a bit overwhelming at first, but it’s not so bad once you get into it. We won’t get into most the classes here, we’re just going to reference the Grid section for now. A grid must be created inside a container, which contains columns inside of rows. Bootstrap 4.0 uses a 12 column layout. What this means is you can control the placement of content with 12 responsive columns across any size device.
Each tier of classes scales up, meaning if you plan on setting the same widths for xs and sm, you only need to specify xs. You’ll notice in the example above that each row has a set of columns that add up to be 12, following the 12 column layout that we know Bootstrap 4.0 utilizes. If you throw this code together, you’ll end up with this responsive layout. This is awful looking in its current state, I’ve applied some simple CSS to make it easier for you to see what’s happening while you resize the window or rotate your mobile device, but this does little for the overall appearance of the layout. Once you add some content, and a little more CSS to style the page, you have a responsive web page! From this point on, just tackle the layout one section at a time. Bootstrap contains many useful tools, aside from the grid classes, that allow you to create buttons, navigation menus, carousels, and much more. You can use these classes together to create not only a great looking web page, but a responsive web page that will display according to the viewport of the visitor. This prevents from content appearing in an undesirable way, often times making it difficult or impossible to navigate. Knowing this, with a little effort I was able to create the WordPress theme you’re viewing. In the future, I’ll return to elaborate on using Bootstrap and some of its many tools, but the subject is too large to fit into one post.
Very basic example of how Bootstrap can be utilized to create scaling web pages. You can view the html code by inspecting the following page within your browser.
Alternatively, without bootstrap, the same HTML would look like this example