How to use bootstrap for a WordPress blog. Installing bootstrap Connecting social networks in bootstrap 4

💖 Do you like it? Share the link with your friends

There are several ways to get started with Bootstrap, each of which is interesting depending on your level of experience and specific usage needs. See what works best for you.

Current version is v3.3.2.

Bootstrap CDN

$ bower install bootstrap

What's included

Bootstrap is available in two versions. One of them contains a compiled version, and the other a minimized version (reduced in volume). In both cases, directories and files are logically grouped.

Bootstrap 3 File Structure

After downloading, unzip the files. You will see something similar to this:

Bootstrap/ ├── css/ │ ├── bootstrap.css │ ├── bootstrap.min.css │ ├── bootstrap-theme.css │ └── bootstrap-theme.min.css ├── j s/ │ ├ ── bootstrap.js │ └── bootstrap.min.js └── fonts/ ├── glyphicons-halflings-regular.eot ├── glyphicons-halflings-regular.svg ├── glyphicons-halflings-regular.ttf └ ── glyphicons-halflings-regular.woff

This is the basic form of Bootstrap: compiled files are ready for quick use in any web project. CSS and JS assemblies (bootstrap.*) and a minified version (bootstrap.min.*) are provided. Glyphicons fonts are included as an additional option for Bootstrap.

Bootstrap 3 Source Code

The Bootstrap source code includes precompiled CSS, JavaScript, and fonts, along with the original Less, JavaScript, and documentation. For clarity, see the example below.

Bootstrap/ ├── less/ ├── js/ ├── fonts/ ├── dist/ │ ├── css/ │ ├── js/ │ └── fonts/ └── docs/ └── examples/

less/ , js/ , fonts/ with icons. The dist/ folder includes all the listed compiled files mentioned in the section above. The docs/ folder contains documentation and examples/ of using Bootstrap. In addition, there is information about licenses and development of previous versions.

Community

Stay up to date with Bootstrap developments. Reach out to the community for useful information.

Bootstrap support in Russian Steps to block responsive browsing
  • Do not create with the name viewport as stated in the CSS description
  • Override width , .container for each layout level of a specific width, like this: width: 970px !important; Make sure this code comes after including the main Bootstrap CSS code. If desired, you can avoid!important with media queries or with a special selector.
  • If you are using a navigation menu, remove any menus that can collapse/expand.
  • For markup layout, use .col-xs-* classes in addition to or instead of medium/large classes. Markup with the xs (extra small) class scales for all monitor sizes.
  • You'll need Respond.js for IE8 (since media queries exist and need to be handled). This will block Bootstrap's "site mobility" property.

    Bootstrap template with responsiveness locked

    We have used these steps as an example. View the source code to see the differences.

    Migration from v2.x to v3.x

    See the documentation about migrating from an older version of Bootstrap to v3.x? Check out the transition guide.

    Browsers and device support

    Bootstrap is designed to work best in new browsers, meaning older browsers may not always render styles correctly despite being fully functional in rendering certain components

    Browser support

    In particular, we support the latest versions from the following browsers and platforms. On the Windows platform, we support Internet Explorer 8-11. More specific support information is provided below.

    Chrome Firefox Internet Explorer Opera SafariAndroid iOS Mac OS X Windows
    Supported Not supported N/A Not supported N/A
    Supported N/A Not supported Supported
    Supported Supported Supported Supported
    Supported Supported Supported Supported Not supported

    Bootstrap should look and behave reasonably well in Chromium and Chrome for Linux, Firefox for Linux, and Internet Explorer 7, although they are not officially supported.

    Internet Explorer 8 and 9

    Internet Explorer 8 and 9 are also supported, but be aware that some CSS3 properties and HTML5 elements are not fully supported in these browsers. Additionally, Internet Explorer 8 requires the use of Respond.js to enable support for media queries.

    Property Internet Explorer 8 Internet Explorer 9border-radius box-shadow transform transition placeholder
    Not supported Supported
    Not supported Supported
    Not supported Supported with -ms prefix
    Not supported
    Not supported

    To get your attention, we've included these as examples in the Bootstrap documentation.

    Percentage rounding in Safari

    In Safari v6.1 for OS X and Safari for iOS v7.0.1, when using the .col-*-1 markup class, the Safari engine has some issues with the number of decimal places. That is, if you have 12 separate columns of layout, you will notice that they will be shorter compared to other rows of columns. You can change () a bit here, but you have a few options:

    • Add .pull-right to your last column in the layout to get a hard right alignment.
    • Change percentages manually to get perfect rounding for Safari (more difficult than first option)

    We will keep an eye on this issue and if there is a simpler solution we will update our code.

    Modal, navbars, and virtual keyboards Overflow and scrolling

    Support for overflow: hidden on an element is quite limited in iOS and Android. In the browser of these devices, when you scroll beyond the top or bottom modal, the content in .

    Virtual keyboard

    Please note - if you use an input form in a modal window or navigation, iOS has a display bug due to which the position of fixed elements is not updated when the virtual keyboard is called. There are some workarounds for this, including transforming elements to position: absolute , or calling a timer when the element has focus and trying to fix it manually. Bootstrap doesn't handle such errors, so you'll need to figure it out yourself.

    Navbar Dropdowns

    The .dropdown-backdrop element is not used in navigation on iOS due to z-index difficulties. Thus, to close dropdown menus, you simply need to click the dropdown element (or any other element that will generate a click event in iOS).

    Browser scaling

    When changing the page size, some elements inevitably display incorrectly: this applies to Bootstrap and the rest of the web document. Depending on the specific case, we can fix this (if necessary, you can open the corresponding request, but first you need to search for similar requests). However, we generally ignore them because they often have no direct solution other than creating hacky workarounds.

    Printer outputs

    Even in some modern browsers, printing can be dodgy. Specifically, as of Chrome v32, and regardless of margin settings, Chrome significantly uses the viewport width narrower than the physical paper size when resolving media queries while printing a web page. This may cause Bootstrap's extra-small markup to activate unexpectedly when printing. Suggested workarounds:

    • Apply extra-small markup and make sure your page looks good.
    • Setting the value of @screen-* Less variables so that your printer paper is considered more than extra-small.
    • Add custom queries to resize breakpoint markup for print media only.
    Android stock browser

    Out of the box, Android 4.1 (and even some newer releases apparently) ship with the Browser app as the default web browser of choice (as opposed to Chrome). Unfortunately, the Browser app has lots of bugs and inconsistencies with CSS in general.

    Select menu

    On elements, the Android stock browser will not display the side controls if there is a border-radius and/or border applied. Use the snippet of code below to remove the offending CSS and render the as an unstyled element on the Android stock browser. The user agent sniffing avoids interference with Chrome, Safari, and Mozilla browsers.

    var nua = navigator . userAgent var isAndroid = (nua . indexOf ( "Mozilla/5.0" ) > - 1 && nua . indexOf ( "Android " ) > - 1 && nua . indexOf ( "AppleWebKit" ) > - 1 && nua . indexOf ( "Chrome" ) === - 1 ) if (isAndroid ) ( $ ( "select.form-control" ). removeClass ( "form-control" ). css ( "width" , "100%" ) )

    Third party support

    Although we do not officially support third-party plugins or add-ons, we do offer some useful tips to help you avoid potential problems in your projects.

    Block size

    Depending on the context, you can override box-sizing only where necessary (Option 1), or reset it for entire areas (Option 2).

    /* Box-sizing resets * * Reset individual elements or override regions to avoid conflicts due to * global box model settings of Bootstrap. Two options, individual overrides and * region resets, are available as plain CSS and uncompiled Less formats. */ /* Option 1A: Override a single element"s box model via CSS */ .element ( -webkit-box-sizing : content - box ; -moz-box-sizing : content - box ; box-sizing : content - box ; ) /* Option 1B: Override a single element"s box model by using a Bootstrap Less mixin */ .element ( .box-sizing (content-box); ) /* Option 2A: Reset an entire region via CSS * / .reset-box-sizing , .reset-box-sizing *, .reset-box-sizing * :before , .reset-box-sizing * :after ( -webkit-box-sizing : content - box ; -moz- box-sizing : content - box ; box-sizing : content - box ) /* Option 2B: Reset an entire region with a custom Less mixin */ .reset-box-sizing ( & , *, * :before , * : after ( .box-sizing (content-box ); ) .element ( .reset-box-sizing (); )

    Availability

    Bootstrap follows common web standards, and—with minimal additional effort—can be used to create AT accessible sites.

    Skip navigation

    If your navigation menu has many links and is located before the main content in the DOM, add a Go to main content link directly after the tag.

    Skip to main content The main page content.

    Nested Headers

    When nesting headings ( - ), your document title proper must be . The following headers must be logically specified using - so that the program that reads the headers can construct the contents of the page.

    Additional resources It allows you to: It does not require:
    • Include the Bootstrap source code itself, or of any modifications you may have made to it, in any redistribution you may assemble that includes it
    • Submit changes you've made to Bootstrap for demonstration in the Bootstrap project (though feedback is welcome)

    The full version of the Bootstrap license is posted in the repository project in more detail.

    Bootstrap setup

    Bootstrap is best served when the development environment separates each dependency on it into separate versions. By following this rule, upgrading to a new version of Bootstrap in the future will be easy.

    Once you have downloaded and included Bootstrap styles and scripts, you can customize their components. To do this, simply create a new style sheet (LESS if you prefer, or just CSS).

    Simple assembly or minimized?

    And in the future, include any Bootstrap and HTML components to create page templates for your site.

    Setting up composites

    You can customize components to varying degrees, but most fall into two categories: easy setup And complete restructuring. There are many different examples from third parties that allow you to implement both categories.

    We define easy setup like superficial changes such as color and font changes for existing Bootstrap components. An example of easy setup is

    Greetings to all readers of the current publication. Very often, novice web developers have a question: “How is Bootstrap connected to a CMS?” Therefore, in order to provide answers to such questions, I decided to write this article.

    I will tell you in detail how to connect the framework to WordPress and Joomla!, I will explain what customization is and why it is needed. Well, let's get started!

    Connecting Bootstrap to Joomla

    In fact, connecting the framework to engines is quite simple. And in the situation with Joomla, Bootstrap is already included in the assembly and is connected automatically. So, it is used in the engine admin panels.

    However, there is one BUT. The version of the framework used in this CMS is outdated. Therefore, it is advisable for you to connect the latest version of Bootstrap. And here it is important not to replace the old one with a new one, since the admin panel can fly, but to use them together (there will be no conflict).

    In order for the framework elements to work, you need to perform several actions:

  • Download on the official website
  • Copy all framework files with the css extension to the css directory of the selected CMS Joomla layout;
  • Copy all files with the js extension to the js directory of the selected engine template;
  • Copy all files from the fonts directory of the downloaded framework to the fonts folder of the selected Joomla layout;
  • In the main index.php file of your project in the header, add the following lines:
  • 1

    If you also need to add a jQuery library script, then add it before the specified scripts.

    That's all the necessary steps. I have given one of the simplest and most effective methods, which does not require a huge number of settings and steps. In principle, the framework can be connected to any known engine in approximately the same way.

    Connecting Bootstrap to WordPress

    In order not to duplicate the previous option for connecting Bootstrap, I will tell you how to use online storage. As you probably already know, it is not necessary to download the files of the described tool. Sometimes it is enough to use links to a CDN.

    To do this, in the header of the file called index.php, you need to follow the same rules as in the previous version (style description, js and jQuery scripts, Bootstrap scripts), insert the lines:

    1

    There is another way for CMS WordPress:

  • Download the latest available version of Bootstrap from the official website http://getbootstrap.com/;
  • Copy all framework files with the css extension to the css directory of the active WordPress layout;
  • Copy all files with the js extension to the js directory of the active engine template;
  • Copy all files from the fonts directory to the fonts folder of the active WordPress template;
  • In the root directory of this layout, find the functions.php file and open it;
  • Enter the code into the text of the open document:
    1 2 3 4 function add_bootstrap())( wp_enqueue_script('my_bootstrap_js', get_template_directory_uri().'/js/bootstrap.js'); wp_enqueue_style('my_bootstrap_css', get_template_directory_uri().'/css/bootstrap.css'); )

    function add_bootstrap())( wp_enqueue_script('my_bootstrap_js', get_template_directory_uri().'/js/bootstrap.js'); wp_enqueue_style('my_bootstrap_css', get_template_directory_uri().'/css/bootstrap.css'); )

  • After the function, add the line add_action ('wp_enqueue_scripts', 'add_bootstrap'); which will start processing the newly created function.
  • A few words about Customize

    In the case when you know exactly which elements of the framework you need and which you don’t use at all, or when you initially want to change the basic values ​​of the parameters, you should use Customize (http://getbootstrap.com/customize/).

    With its help, you can select a list of components, utilities, plugins, css settings and other elements from Less files. For example, you can disable icons and symbols known as Glyphicons (if you don't know what they look like, look it up on Google or this link).

    In addition, in separate dialog boxes you can set other values ​​for colors, fonts, indents, etc., which will subsequently become the default settings.
    This concludes my article. Subscribe to my educational blog updates and tell your friends about it. I wish you good luck! Bye bye!

    Best regards, Roman Chueshov

    From the author: I salute you. In this article, I will once again talk about how to install Bootstrap, but this time we will pay more attention to customizing the framework for yourself. The article will be quite lengthy, so if you are interested in customization, please be patient and read in full. The article will be divided into 2 parts: changing Bootstrap settings and components and theming, that is, changing the appearance.

    Standard framework installation

    I have already said a lot about the standard installation in previous articles. Everything is simple here. We go to the official website getbootstrap.com, click on Getting Started and select the very first option. Thus, we download the full version of bootstrap with all js and css components.

    Bootstrap CDN is an opportunity to connect the framework from a CDN storage without downloading its files to your computer. Naturally, in this case there can be no talk of any customization.

    Framework customization

    But the fact is that bootstrap contains many components by default, and some of them simply may not be useful to you when developing a specific site. For example, you are designing an online store. You may not need modals and tooltips, and you may not need many of the css components. In this case, it would be wise not to include these components in the framework.

    Or you are creating a simple blog. Let's say you don't really need anything there at all, so you can leave only the mesh and a couple of the most important components.

    Choosing only what you need is a professional approach to creating websites and using Bootstrap. By default, the uncompressed version of the framework's CSS styles in the latest version weighs 143 kilobytes. And scripts are more than 60 kilobytes. Yes, if you compress the code, you can reduce the weight by 20-40%, but still the files will not be the lightest.

    If, for example, you disable all components and leave only the grid (this is very often done), then the weight of the css will be only 15-20 kilobytes, and in compressed form another couple of kilobytes less. This way you will achieve maximum speed and optimization of your project.

    Okay, that was just a theory. To customize the framework, visit the same official website and go to the Customize item.

    Selecting the necessary components

    The first step here is to configure which components you want to include in your version of Bootstrap. Let's start with the CSS:

    Print Media Styles – media queries for printing. If you do not plan to print site pages, you can disable it.

    Typography, code, tables, forms and buttons are all things that you can style in CSS yourself if you really want. Of course, this will take time, but if the design of your elements is very different from what the framework offers by default, you can disable all these CSS styles and write them yourself.

    Grid System is actually a grid. I don’t see any point in ever disabling it, because this is the main power of the framework. It is thanks to the grid that you can easily adapt templates to any device, and today in the age of mobile traffic this is extremely important. We do not turn it off under any circumstances.

    Responsive utilities – adaptive utilities, I also recommend never disabling them. We will talk about adaptive utilities in the next article, where we will look at the grid system in detail. These are classes that allow you to hide an element or make it visible at a certain screen width. Very convenient and useful.

    These are, for example, things like list groups, button bars, icons, panels, alerts, pagination, breadcrumbs, etc. You can also disable the icon font. This is worth doing in the case when you do not need icons on the site at all, or you are connecting another set. Actually, you should sit and think about what you need from all the components presented and what you don’t. Each individual site will have its own set, because each site has a different design and functionality.

    Javascript components

    These are drop-down menus, tooltips, modal windows, and sliders. If you don't need any of this, turn it off. In some cases, all components can really come in handy when your site has a drop-down menu, a slider on the main page, and modal windows. In some cases, at most 1-2 components may be useful, then there is no need to lengthen the code, disable unnecessary components.

    Jquery plugins

    Here you can disable jquery library plugins that help javascript components work correctly. Accordingly, if you do not use a slider on your site, then you do not need a plugin for creating carousels, if you do not need tooltips, then disable tooltips.js, etc.

    The scrollspy plugin monitors the position of the text and, depending on this, highlights one or another menu item. Usually such a feature is needed on landing pages; I have practically never seen it on regular sites. And so on. Take a good look at what you need and what you don't.

    Less variables

    Next, a huge item will open in front of you, in which there will be a lot of sub-items with settings for Less variables. Here you can change almost everything: colors, font sizes, breakpoints, number of columns in the grid, indents, etc.

    Of course, to do this you must know at least the basics of Less or at least intuitively navigate these forms.

    For example, if you see the @font-family-base variable, then you need to at least intuitively understand that it is responsible for the name of the font, which is the base font on the site. Well, the @font-size-base variable sets the base font size. By default in bootstrap it is 14 pixels.

    You can edit all these fields. Just change 14 to 20 and now you can download a framework in which the default font size is 20 pixels. Accordingly, you can immediately adjust the size of the headings, etc.

    Setting up the grid

    The settings of the grid system are also very interesting for us, here they are:

    As you can see, you can change the number of columns and the width of the indents between them in a few seconds. The grid-float-breakpoint variable sets the point at which the mobile menu collapses into an icon.

    Bootstrap 4 framework. Quick start

    Learn the basics of Bootstrap 4 with a practical example of designing a blog from scratch

    If you change the value, for example, to @screen-md-min, then at a width of 991 pixels or less, collapsing will occur. You can also remove this variable and write the value in pixels. For example, 520 pixels. Then collapsing the menu will only occur on smartphones and mobile phones.

    Actually, the Bootstrap customization page has a lot of settings, but in general this method of customization (using the Customize page on the official website) is not the fastest and most convenient. Next I will show you the fastest way.

    Use the Customize page when you need to make 2-10 changes to the framework, or simply disable the necessary components. If you are going to change many more values, you need to use a different method.

    Actually, when you set up your version of the framework, click on the big button at the very bottom of the page. It will compile a version of Bootstrap for you and download it to your computer. Then all you have to do is connect and use. I have already talked about connection in previous articles (including how to do it on WordPress).

    Downloading Less sources and editing them

    As I already said, if you need to make a lot of edits to the source code of the framework and you want to see the changes instantly, then you will need less sources. You can download them in the same place as the full version of the framework - in the Getting Started section.

    To work with Less sources and edit them you need:

    At least some knowledge of css and less or another preprocessor

    Less compiler (can be downloaded for free)

    Actually, I will not dwell in detail on customization through less sources, but this is the best method, because you will not need to go to the Customize page 100 times and compile more and more new versions of the framework.

    You can see more details about working with less source codes in our paid one, created by Andrey Kudlay. There, working with the framework is discussed in more detail.

    Bootstrap theming or changing the appearance of elements

    By default, in the full version of the framework, you can also find the bootstrap-theme.css file in the css folder. It is not necessary to connect it to the site. What functions does it perform? The file is needed solely to, if necessary, change the styles for the elements you need.

    This same role can be fulfilled by your own style.css, in which you can also override styles. Bootstrap-theme is not a required file, it is used rather for order. For example, you have 3 files:

    bootstrap.css – of course, this is the code of the framework itself;

    bootstrap-theme.css – here you override styles for bootstrap elements;

    style.css – write styles for your elements in this file.

    Then you will have order in your code and in your project structure. But no one forbids you to perform all operations in a single file - style.css and not to use the theme file at all.

    The most important thing is to include the theme file and your own css in the html markup later than the file with the framework code, so that the styles are successfully overridden.

    An example of how theming works

    As I already said, by default Bootstrap includes the bootstrap-theme. Try connecting it. I note, connect after the main file.

    By default, buttons in Bootstrap look like this:

    And this is how their appearance changes after connecting the file with the theme:

    As you can see, a slight gradient appears. Accordingly, you can rewrite the code in the bootstrap-theme file and get your own styles for the buttons. But you may ask, why not make these changes directly in bootstrap.css? Well, the fact is that new versions of the framework are constantly being released, and if you decide to upgrade, it will be difficult to implement your changes into the new version. It is considered good form for a developer not to touch the source code when you can create a separate file and describe the changes there. It's much smarter and more convenient.

    How to install new Bootstrap themes downloaded from the Internet?

    There are quite a lot of sites, mostly foreign, where you can download a bunch of themes and templates for free. To avoid confusion, let's consider a website designed using Bootstrap as a template, and a theme as a set of CSS rules that override the standard appearance of elements.

    Such themes can be downloaded, for example, from bootswatch.com/, and using a search engine you can find dozens of others.

    The general principle of installing such themes depends on the site where you download them. If you can download it in bootstrap-theme format, great, download it and connect it. On bootswatch, for example, you need to download bootstrap.css and replace your standard framework style file with it. There is also an option with less sources.

    Bottom line

    Well, today we looked at how to install and customize Bootstrap. I hope this information was useful to you. Above, I already provided a link to a course on adaptive layout using this framework. Using Bootstrap you can build websites 3-4 times faster, and the result will be just as good, or even better, because when you write CSS styles yourself, you can always leave something out and mess up somewhere.

    In general, if you want to communicate with Bootstrap on a first-name basis, definitely purchase the course and start learning it. In fact, you can finish it in a couple of days and during this time you will get a lot of practice. It can be said that many months of reading articles and books on Bootstrap will benefit you less than a couple of days of actual practice developing complex templates. Okay, this is where I end the article and wish you a quick learning of the framework.

    Bootstrap 4 framework. Quick start

    Learn the basics of Bootstrap 4 with a practical example of designing a blog from scratch

    The advantage of using CSS frameworks is that the layout designer does not need to think about many layout nuances that the creators of the frameworks have already thought through for him. Such nuances include cross-browser compatibility, support for different screen resolutions, and much more. The layout designer only indicates what, how and when to show, the rest is done by the framework itself. This approach can greatly speed up website layout. The advantages of Bootstrap include its popularity. This means that it will be easier for another code designer to maintain your code.

    The disadvantage of using frameworks is that the page will have to carry the entire framework's extra styles, even if it only uses a small part of them. The framework is an excellent tool for prototyping and creating pages for which design is secondary, such as admin pages. If you have a very specific design, then laying it out using a framework may be more difficult than using native tools. However, this is also possible.

    About using Bootstrap Currently, there are several ways to work with Bootstrap styles. Without using LESS For beginners, Bootstrap itself recommends the following approach: you need to download compiled Bootstrap from the site and put it in your project without changing anything. Then you need to create your own empty CSS file and include it after bootstrap.css.


    After that, in order to change the Bootstrap styles you need to change them in your styles.css something like this:

    A ( color: #beceda; )
    The obvious disadvantage of this approach is that you will have to manually search for the necessary styles that you want to interrupt, and this will not always be trivial, because Some Bootstrap options apply to many selectors in modified form, such as through formulas. The Customize tool can be of some help here; it will help compile your changes correctly, but only once. If in the future you want to change some parameter, you will have to re-enter the changed values ​​for all fields in order to compile your styles.

    Using LESS This method assumes that all Bootstrap variables are stored in .less files. The developer works with these variables and, if necessary, manually or automatically compiles them into CSS files, and the HTML itself includes only the compiled CSS files. It is this option that will be considered in the article as the most flexible.

    There are a large number of ways to compile LESS files and Bootstrap leaves this up to the discretion of the developer. Bootstrap itself uses Grunt for compilation, you may prefer a plugin for JetBrains products, and we, since the article is aimed at beginners, will look towards simpler solutions. Such solutions are WinLess for Windows, SimpLESS for Mac or Koala for Linux. All these programs do approximately the same thing: they receive a folder with LESS files as input and listen for changes in them. As soon as you make changes to any file, it is immediately compiled into the specified CSS file. This way you don't need to run manual compilation after every change. You change the LESS file, save it and immediately see the changes on the site in an already compiled, compressed form.

    Creating a Project The first step is to create a simple file structure for our project.
    Preliminary inspection After creating the file structure, open the psd file in Photoshop. It is important to carefully examine the template and evaluate it. We need to understand the following things:
    • How will the images be cut?
    • What components will be used?
    • What will be the main styles?
    • What page layout will we get?
    Only after you mentally answer these questions for yourself, you can move on to layout. Let's look at these questions in order. General images At this stage, you need to cut and save only general images that will be on all pages of the site and do not relate to the content. In our case, this will be a light gray page background, a header background, a map image, two logos, and social media buttons.

    Save the map image:

    Let's save the logos as follows:

    Images/logo.png
    images/footer-logo.png

    Repeating background images must be cut out in a small piece sufficient to form a complete image by repeating vertically and horizontally.

    /images/bg.png
    /images/h1-bg.png

    It is convenient to save social network icons with the same sizes into one file and use them as sprites for faster loading. More details about gluing images are described in the first part. The result will be two files:

    /images/social.png
    /images/social-small.png

    Components The main difference between layout using Bootstrap and layout using native means is that Bootstrap introduces the concept of components. Components are frequently used ready-made HTML blocks with predefined styles. Sometimes components use JavaScript. The layout designer can use either a ready-made component or define his own appearance for it. To do this, you often just need to change the value of variables in Bootstrap. If more flexible changes are needed, the layout designer can always change the HTML and CSS at his discretion.

    If you take a look at our template, you can see that we will need the following components:

  • For layout with columns - grid system (row, col)
  • For search – inline form (form-inline), grouped controls (input-group), button (btn)
  • For navigation - the navigation bar (navbar) and the navigation itself (nav)
  • To display submenus – grouped list (list-group)
  • For the map block – visual panel (panel)
  • To display a large central block - jumbotron
  • To display photo frames - thumbnails
  • We will look at each component in more detail when we encounter it in the layout. Basic styles In Bootstrap, all default styles are already set, we only need to customize them if they differ from our design. Let's do this in the file src/less/variables.css.

    First of all, you need to add variables that are not in the Bootstrap settings so that you can use them in the future. For us this is only a specific design font.

    @brand-font: "Oswald",sans-serif;
    If you want to use a template for Russian sites, then you can try replacing the Oswald font with the closest Cuprum, which supports Cyrillic.

    Now let’s replace the Bootstrap settings with our own:

    Now that we're done with the variables, let's start styling our design in the styles.less file. First, let's connect Bootstrap itself and our variables:

    @import "bootstrap/bootstrap.less"; @import "variables.less";
    Not all Bootstrap's default styles can be changed using variables, so let's do it manually:

    P ( margin: 20px 0; ) .form-control ( box-shadow: none; ) .btn ( font-family: @brand-font; )
    Here we have removed the shadow from the form elements, and given the text in the buttons a specific page font.

    Then we will describe the page background and the top bar:

    Body ( border-top: 5px solid #7e7e7e; background-image: url(../images/bg.png); )
    Further in the text it will not be indicated in which file the styles are written. Just remember that we save all the variables in the file variables.less, and the CSS styles will be stored in styles.less.

    HTML framework We traditionally start the website layout with an HTML framework. We paste the code of the simplest template from the Getting started page into the index.html file, having previously removed all unnecessary things:

    Whitesquare
    This block creates an HTML5 document structure. In the title we indicate the name of our page – Whitesquare. With the viewport meta tag we indicate that the page width on mobile devices will be equal to the screen width and the initial scale will be 100%. Then the styles file is included. And for versions of Internet Explorer less than the ninth, we include scripts that allow us to display our layout correctly.

    Layout In this case, we see that the site consists of two parts: the main container with content, which is centered on the screen, and a stretching footer. The main container consists of two columns: main content and sidebar. Above them is the header, navigation (nav) and page title (.heading).

    Let's add the following code to body:


    Here we come across the first Bootstrap component - columns. The parent element of the columns is given the class "row", and the column classes start with the prefix "col-", then the screen size (xs, sm, md, lg), and end with the relative width of the column.

    A column can be assigned simultaneously different classes with values ​​for screens, for example class="col-xs-12 col-md-8". These classes simply set the column width as a percentage for a specific screen size. If the column is not given a specific screen class, then the class for the minimum specific screen will be applied, and if it is not specified, then no width will be applied and the block will take up the maximum possible width.

    Our classes “col-md-7” and “col-md-17” indicate that the blocks are columns with a width of 7 and 17 relative to the parent container. By default, the sum of column widths in Bootstrap is 12, but we doubled this number to achieve the flexibility we needed.

    Body ( … .wrapper ( padding: 0 0 50px 0; ) header ( padding: 20px 0; ) )
    We placed this structure inside the body. The LESS syntax allows you to nest rules within each other, which are then compiled into the following constructs:

    Body .wrapper (…) body header (…)
    This approach allows you to see the HTML structure right inside the CSS and gives some “scope” to the rules.

    Logo

    Insert the logo into the header tag:

    No additional styles required.

    Search

    In order to create a search, we will need the following Bootstrap components: inline form, grouped controls and button.
    In the header tag we create an inline form, aligned to the right. The fields of such a form must have a “form-control” class and a label.

    We place the “grouped controls” component into the form. Grouping controls allows you to remove the space between the text input and the button and, as it were, merge them into a single element.
    It is a div with the “input-group” class and fields, and the button of such a component is placed in a block with the “input-group-btn” class.

    Since we don’t need to show the label for the search field, we’ll hide it with the “sr-only” class. This is needed for dedicated screen readers.

    The class “btn-primary” is added to the button, meaning that this is the primary button of this form.

    …Search GO
    All we have left is to set the width of the search form in the styles.

    Body ( … .wrapper ( … header ( … .form-search ( width: 200px; ) ) ) )

    Menu

    To display the menu, take the “navigation panel” component and place in it the “navigation” component, which is a list with links. For navigation, a class "navbar-nav" is added, which applies special navigation styles within the navbar.


    In order to bring this menu to our design, we will set the following values ​​for the variables:

    /*navbar height*/ @navbar-height: 37px; /*set more horizontal padding*/ @nav-link-padding: 10px 30px; /*background for menu items*/ @navbar-default-bg: @panel-bg; /*text color in menu items*/ @navbar-default-link-color: #b2b2b2; /*and when hovering the mouse - the same*/ @navbar-default-link-hover-color: @navbar-default-link-color; /*background of the active menu item is our specific blue color*/ @navbar-default-link-active-bg: @brand-primary; /*text color of the active menu item*/ @navbar-default-link-active-color: #fff;
    In addition to customizable parameters, we will describe additional ones in styles - this is uppercase text and our specific font:

    Body ( … .wrapper ( … .navbar a ( text-transform: uppercase; font: 14px @brand-font; ) ) )

    Page title

    The page title is placed in a div with the "heading" class.

    About us
    And has the following styles:

    Body ( … .wrapper ( … .heading ( height: 40px; background: transparent url(../images/h1-bg.png); margin: 30px 0; padding-left: 20px; h1 ( display: inline-block; color: #7e7e7e; font: normal 40px/40px "Oswald", sans-serif; background: url(../images/bg.png); padding: 0 10px; ) )
    Here we draw a gray stripe as the background on the div, and insert an inline h1 into it with the desired font and page color background to create the impression of a transparent background for the h1.

    Submenu

    When creating a submenu, we will not use the “navigation” component, since it is not very suitable for us in style; the “grouped list” component is much more suitable for us. Each element of such a component has a class “list-group-item”.

    The submenu should be placed in the aside tag. We create a list of links in the same way as the main menu.


    In the component settings, we indicate that all grouped lists should be shown with the background and frame of the “panel” component:

    @list-group-bg: @panel-bg; @list-group-border: @panel-inner-border;
    And apply the following styles to the submenu:

    Body ( … .wrapper ( … .submenu ( margin-bottom: 30px; li ( display: list-item; font: 300 14px @brand-font; list-style-position: inside; list-style-type: square; padding : 10px; text-transform: uppercase; &.active ( color: @brand-primary; ) a ( color: @text-color; text-decoration: none; &:hover ( color: @text-color; ) ) ) ) )
    First, we return the standard styles to the list elements, since Bootstrap replaced them with its own. Add a padding at the bottom. Submenus use thinner fonts and square markers. And for links we set colors, upper case and remove underlining. The ampersand in the "&.active" code will be replaced by the parent selector at compile time using LESS syntax: ".submenu li.active".

    Sidebar content In addition to the submenu, the sidebar content also contains an image with the location of the offices.

    To display it, we will use the “panel” component, or rather its variation “panel-primary” for coloring the title. This component contains a header block (panel-heading) and a panel content block (panel-body). We add the “img-responsive” class to the map image, which will allow the image to shrink when the screen width is small.

    … Our offices
    In Bootstrap variables we have already set the color for the background of the panel (panel-bg), and now we will specify that the “primary” panel will have the default panel’s gray border, rather than the default blue one:

    @panel-primary-border: @panel-inner-border;
    Now in the site styles you need to change the standard panel settings, which are not changed through variables:

    Panel ( box-shadow: none; .panel-heading ( font: 14px @brand-font; text-transform: uppercase; padding: 10px; ) .panel-body ( padding: 10px; ) )
    Here we removed the shadow from the panels, added our own indents and set our own heading font.

    Quote Let's start laying out the content by adding a quote.

    This page element is most similar to the Jumbotron component. Let's add it to the content column:

    “Quisque in enim velit, at dignissim est.” nulla ul corper, dolor ac pellentesque placerat, justo tellus gravida erat, vel porttitor libero erat.”

    John Doe, Lorem Ipsum
    Using variables for the jumbotron component, we will set the text color to white and the branded blue background:

    @jumbotron-bg: @brand-primary; @jumbotron-color: #fff;
    And let's describe our styles:

    Body ( … .wrapper ( … .jumbotron ( border-radius: 0; padding: 0; margin: 0; blockquote ( border-left: none; p ( font: 300 italic 33px @brand-font; text-transform: uppercase; margin-bottom: 0; ) small ( text-align: right; color: #1D8EA6; font: 300 20px @brand-font; &:before ( content: ""; ) ) ) ) )
    In them, we remove the corner rounding, component padding, and quote decorations that are set by Bootstrap by default. We will also add styles for our fonts.

    Content

    Lorem ipsum dolor sit amet…

    Donec vel nisl nibh…

    Donec vel nisl nibh…


    The next step is to add two images that are at the end of the content text. This is done using two columns:


    The "thumbnail" class turns images into a "thumbnail" component. He will do all the work of stylizing the images for us. The only thing left for us is to set our padding and border color in the variables for this component:

    @thumbnail-padding: 1px; @thumbnail-border: #c9c9c9;

    Block "Our team"

    When laying out this block, let’s first add a title:

    Our team
    with style:

    Body ( … .wrapper ( … h2 ( background: none repeat scroll 0 0 #29C5E6; color: #fff; font: 300 30px @brand-font; padding: 0 10px; text-transform: uppercase; ) ) )
    And then we’ll add a block with the “team” class, which consists of two lines containing employee cards. Each card is a column. The card has a width equal to four columns of our grid. All cards except the first one in the line have a left indent, which is created by the “col-md-offset-1” class. The card content consists of an image and a description (.caption)

    John Doe Saundra Pittsley

    team leader

    Ericka Nobriga

    art director

    Cody Rousselle

    senior ui designer


    After creating the markup, let's give these elements the following styles:

    Body ( … .wrapper ( … .team ( .row ( margin-top: 20px; .col ( white-space: nowrap; .thumbnail ( margin-bottom: 5px; ) ) .col-md-offset-1 ( margin- left: 3.7%; ) .caption ( h3 ( font: 300 16px @brand-font; margin: 0; ) p ( font: 300 14px @brand-font; color: @brand-primary; margin: 0; ) ) ) ) )
    In addition to the indents and font styles that are set here, we changed the “col-md-offset-1” class. He had to set the indent to 3.7% because... the standard indentation was too large.

    Footer The footer consists of four large blocks: Twitter feed, site map, social links and logo with copyright.

    First, let's create a footer container with these blocks:


    And apply the design to it:

    Footer ( background: #7e7e7e; color: #dbdbdb; font-size: 11px; .container ( height: 110px; padding: 10px 0; ) )
    The footer tag defines a gray area across the entire width of the screen, and the container inside it displays a centered area on larger screens and specifies the height and padding of the footer. We use columns to align blocks within the footer.

    Twitter feed Layout the contents of the Twitter feed:

    Twitter feed Oct 23

    In ultricies pellentesque massa a porta. Aliquam ipsum enim, hendrerit ut porta nec, ullamcorper et nulla. In eget mi dui, sit amet scelerisque nunc. Aenean aug


    Styles:

    Body ( ... footer ( ... .container ( ... h3 ( border-bottom: 1px solid #919191; color: #ffffff; font-size: 14px; line-height: 21px; font-family: @brand-font; margin: 0 0 10px; text-transform: uppercase; ) p ( margin: 5px 0; ) .twitter ( p ( padding-right: 15px; ) time a ( color: #b4aeae; text-decoration: underline; ) ) )
    For all footer headings, we set fonts and indents, and also create an underline through the bottom frame. For paragraphs, indicate the indentation. For the link displaying the date, set the color and underline.

    Sitemap The sitemap consists of two equal columns with links:

    Sitemap Home About Services Partners Support Contact
    We set the links to color, font and space between them.

    Body ( ... footer ( ... .container ( ... a ( color: #dbdbdb; ) .sitemap a ( display: block; font-size: 12px; margin-bottom: 5px; ) ) ) )

    Social links

    We insert a set of links into a block with the “social” class.

    Social networks
    And let's style them:

    Body ( … footer ( … .container ( … .social ( .social-icon ( width: 30px; height: 30px; background: url(../images/social.png) no-repeat; display: inline-block; margin -right: 10px; .social-icon-small ( width: 16px; height: 16px; background: url(../images/social-small.png) no-repeat; display: inline-block; margin: 5px 6px 0 0; ) .twitter ( background-position: 0 0; ) .facebook ( background-position: -30px 0; ) .google-plus ( background-position: -60px 0; ) .vimeo ( background-position: 0 0 ; ) .youtube ( background-position: -16px 0; ) .flickr ( background-position: -32px 0; ) .instagram ( background-position: -48px 0; ) .rss ( background-position: -64px 0; ) ) ) ) )
    Here we used the sprite technique - when one image file is used for different pictures. All links are divided into large icons (.social-icon) and small ones (.social-icon-small). We set these classes to display as an inline block with fixed dimensions and the same background. And then using CSS we moved this background so that the corresponding image was displayed on each link.

    Copyright A block with copyright and logo is a picture with a link and a paragraph with text underneath it.

    Copyright 2012 Whitesquare. A pcklab creation


    Styles are done similarly to the previous blocks, with the only difference being that the block is nailed to the right edge and the alignment inside it is also to the right:

    Body ( … .footer ( … .container ( … .footer-logo ( float: right; margin-top: 20px; font-size: 10px; text-align: right; a ( text-decoration: underline; ) ) ) ) )

    This completes the layout. The finished project can be downloaded

    Guys, I think Bootstrap is a very cool thing. I will try to explain why this is so in this article. Well, let's go. I immediately apologize for the fact that almost the entire first half of the article is written without pictures, there is only a theory, an explanation of how the grid works. But this is very important! Anyone of you who needs it will take it into his hands, read it, and, I hope, understand. The second half of the article is already perceived more simply, there are more examples with screenshots.

    Bootstrap - what is it?

    So let's start with an important question. Bootstrap is a CSS and JS framework, essentially a set of files with ready-made written code. The goal of developers of almost any framework is to simplify website development for themselves and others who will have access to the tool. In the case of Bootstrap, it is completely free, so you can use it in any way, edit the source code and customize the framework in any way you want. That's great.

    Installing Bootstrap

    If you just need to connect the framework files to an HTML document (for example, for practice), just download the framework from the official website getbootstrap.com, copy its files into the project and connect the ones you need. Let me give a brief overview of these files:

  • bootstrap.css and bootstrap.min.css - uncompressed and compressed versions of the framework's CSS code. It is recommended to include a compressed file with your working project, this way you will slightly improve the loading speed. But if you plan to view the code in a file, connect the uncompressed version.
  • bootstrap.js and bootstrap.min.js - file with scripts
  • the fonts folder and the glyphicons files in it are the Bootstrap icon font. It has about 200 icons. For most cases you will have enough of them, sometimes you need to connect others. We'll talk about the icon font later.
  • This is the standard set of the framework. In fact, you can easily customize it and change it to suit you. For example, do not use scripts at all or connect only one grid. In general, we will also talk about this.

    Russian Bootstrap documentation

    When you visit getbootstrap, you probably noticed that everything here is in English. We could use Russian help on the framework. It's easy to find. To do this, go from the main page to the Getting Started section. Scroll to the very bottom, there will be a link to translations. Look for Russian there and click on it. That's it, now you are on the Russian version of the site. True, not everything has been translated here, but somewhere around 70-80% is accurate, so you’ll understand everything.

    Bootstrap grid

    Whatever one may say, the main element of Bootstrap is the responsive grid. In general, without it, the framework would lose almost all its value, because it is thanks to the grid that you can quickly create adaptive templates. At the same time, you may not be familiar with media queries at all; you don’t need them, because the framework takes care of the implementation of adaptability; you just need to assign the correct classes to the blocks.

    What are these classes? Let's go to the documentation, it will help us a lot. Go to the CSS - Grid System section. The general rules for working with a grid are simple; I’ll list them now.

    How to work with a grid?

    Think of it as an html table. If you've ever written HTML code for tables, you know that all the content is placed in the table tag, one row is placed in the tr tag, and then the cells are placed in it - td .

    So, everything is similar in the grid. The container class serves as a general container for the grid. There are 2 options for the bootstrap grid - completely rubber and still having a finite maximum width. So, when the general block is given the container class, the site will have a maximum width of 1170 pixels. It will not expand any further. Naturally, the content will be centered.

    If you set the container-fluid class, then the mesh will be completely rubber, that is, there will be no size restrictions. For example, if a person opens a website on a 1920 pixel wide monitor, he will see it in full width.

    Accordingly, the first thing when developing a website is to decide what the template will be like - completely rubber, or its width still needs to be limited.

    Great, a grid row should be placed in the container block. You need to place all the blocks that are on the same line in it. That is, if we take the most typical template: header, main part, right column and footer, then there are 3 columns. The first will have only the header, the second will have the content and sidebar, and the last will have the footer. The markup for such a site would be something like this:

    Header Content... and Footer sidebar

    But for now this is the wrong markup, because it's missing... what? That's right, cells! In the case of Bootstrap, they are also called columns. The bootstrap grid consists of 12 columns. It can be embedded in any block of any width, at least 1200 pixels, at least 100. All this is because the width of the columns is specified not in pixels, but in percentages.

    How does this 12-column system work?

    So, we come to the most important issue related to the framework. Believe me, if you understand this, everything else is nonsense. The main thing is to understand how the grid works, and the path to fast adaptive layout will be open to you.

    To do this, scroll through the documentation just below, there you will find a table that contains important grid properties.

    By the way, the columns themselves are marked in Bootstrap with the col- class, but this is a composite class, so they never simply write col-. Bootstrap has 4 special classes that are designed to control the size of blocks at different widths, here they are:

  • ld - for large screens, more than 1200 pixels wide (desktop computers);
  • md - for medium screens, width from 992 to 1199 (computers, netbooks);
  • sm - for small screens, width from 768 to 991 pixels (tablets);
  • xs - extra-small screens, width less than 768px.
  • These are the 4 classes, but to control the size of the elements, numbers from 1 to 12 are used, because, as you remember, there are exactly 12 columns in the grid.

    Header Content Sidebar Footer

    It's quite easy to understand. First of all, we create a header; it doesn’t have to be placed in the grid at all, since it will in any case occupy 100% of the width (usually). But we'll put it in anyway. What is this class col-md-12? As I already told you, no one writes simply col-, with this class we essentially tell the browser:
    This is a cell | column
    On medium devices (md class), its width should be 12 columns out of 12, that is, 100% of the row width.
    But what about the width on other devices? On large (lg) screens it will also be 100%, because the values ​​for large screens are inherited, but for smaller ones they are not. It's simple: if you wrote col-xs-4 , then the column width would be 33% on all devices, and if col-lg-4 , then only on large ones. This is the feature, remember it.

    Well, if the width value is not saved on smaller screens, then what happens? It is reset. Here's how it happens:
    col-sm-4 - on small screens the block will occupy 33% of the width, it will be the same on md and lg screens, but on xs, that is, the smallest ones, the width will be reset to 100%. So, remember one more simple rule: If nothing is specified for smaller screens, then on them the block will be displayed at 100% width.

    Content Sidebar

    Essentially we are telling the browser:
    Let the content block be 8 out of 12 columns wide and this situation will be on small, medium and large screens (it is enough to specify for small, for large screens, as you remember, the value is inherited). But on the smallest screens the block will be occupied 100%. This is correct; usually, on mobile devices, sites appear in 1 column.
    Let the side column be one-third the width of the row on the same small, medium and large screens. Well, on the smallest ones, as you already understood, its width is also reset to 100%. It's that simple.

    Well, there’s nothing to deal with the footer. Well, we’ve covered the basic principles of how the grid works, but we still need to see how it works...

    Bootstrap Nested Grid

    The fact is that now we have divided the template only into main blocks, but inside they can also be divided into columns. For example, the content may display products in several columns. What should I do? It’s very simple - we create exactly the same grid inside. It will be nested, but also contains 12 columns. If we summarize all this, then we come to this conclusion:
    There can be an unlimited number of grids inside any block. For example, in a block with products there is a grid for separating products; in the block with one product itself, you can create another grid, for example, to separate prices, availability information and additional information. information.

    Now we will try to make another grid inside the content block to arrange products in 3 columns. So, let's take the block in which we have content:

    Content

    And we write in it:

    Product catalog: Product name

    Product Description

    As you can see, we created a new grid inside the content - we put a row inside, and in the row there will already be 3 blocks with products. Just copy the col-sm-4 block with the product card and paste it 2 more times, this is what you get (you can take any product picture, I took a large one):

    I missed another important point: in order for the images to adapt to the blocks in which they are located, each of them needs to be given the img-responsive class. If you, like me, think that doing this is inconvenient, then just write in your own style.css like this:

    Img( max-width: 100%; height: auto; display: block; )

    That's it, save this code and connect your css file to the project. Now the images will be adaptive by default.

    Well, did it turn out quite smoothly? Yes, but without bootstrap you would have to suffer longer. The only thing is that when creating a grid inside any block, you no longer need to create a block with the container class in it. Why is this not necessary? Yes, because the block in which the grid is created serves as a container.

    Thus, you can create as many columns as you like in any block and make a template of any complexity. And all this is much faster than without Bootstrap, because you have to write all the css from scratch.

    Responsive utilities

    This is another great feature of bootstrap. It consists in the fact that you can hide or make visible any blocks at the width you need. For example, completely hide the side column on narrow screens, add some new elements on mobile devices, add a column on wide screens, etc.

    There are a lot of application options, but I didn’t tell you about the most important thing: how to use these utilities? To do this, just add classes to the desired block. If you need to hide it, just specify the following class:

    Footer

    What will the hidden-xs class do in this case? It will hide the footer on extra small devices. On all others the block will be visible.

    If, on the contrary, you need to show it only on the smallest screens, you need to use the visible-xs-block class. In this case, the block will be hidden on all but the narrowest screens. So, adaptive utility classes are written like this:

  • The word hidden or visible, depending on what you need
  • An abbreviation xs, sm, md or lg indicating on which screens to hide or show the block.
  • For visible you also need to add one of three values: block - display the element as a block element, inline-block - as an inline-block element, inline - inline.
  • Well, a couple of examples to make it clear:

  • hidden-xs hidden-lg - will hide the element on the smallest and largest screens. As you can see, you can specify multiple classes separated by a space.
  • visible-xs-inline visible-md-block - on small and large screens the element will not be displayed at all. On extra-small ones it will be lowercase, and on medium ones it will be a block.
  • visible-lg-block - the element will be visible only on the largest screens, on all others it will be hidden
  • This is how it all works. That's exactly it and no other way. I hope you understand this. Let's put it into practice. We have a test template, albeit a very primitive one.

    Task: to make the side column disappear on small screens, and also one product on the smallest screens. And so that on xs devices the products are already in 2 columns, not 3.

    Try to do it yourself, editing only the html code. What needs to be done? First, let's look at the column, to hide it on sm screens, you just need to add the hidden-sm class to it.

    Great, now the third product needs to add the hidden-xs class and it will disappear on the smallest screens. Well, the classes of the remaining two goods will be as follows:

    That is, on medium devices the block will occupy 4 columns out of 12, which can be translated into 33.33% of the width, and on extra-small devices - 50%. And since one block with a product will disappear at this width, both blocks with products will be neatly arranged in 1 row, like this:

    Great! Having understood this, you can already manipulate the blocks on a web page in almost any way you like. Try to come up with tasks for yourself and implement them.

    Move me all the way

    Next I will show you another very good trick - the ability to move a block to the right or left. Let’s say we have not 3 products in a row, but 1. And it does not occupy the entire width. And your task is to align it in the center. This is easy to do if you keep in mind that you are working with a 12-column system.

    Let's leave one block with the product:

    It is enough to make simple calculations to understand how much you need to move the block in order to center it. It needs to be moved 4 columns to the left on medium and large screens, and 3 columns on small ones. This is what it looks like:

    The class col-md-offset-4 says: on medium and large screens, offset the block to the left by 33% of the width of the parent container (1/3 left padding, 1/3 block width, ⅓ right padding, resulting in centering).
    Class col-xs-offset-6: On extra-small and small screens, shift left by 25% (¼ padding left, ½ block width, ¼ padding right).

    I hope you understand the gist and use these classes if necessary.

    Bootstrap components and examples of their use

    I congratulate you. We have just covered the most important topic related to the framework. It is the grid and working with it that is important. Working with components already means that you simply go to the documentation, copy the code of the desired component there and, if necessary, change it to suit your needs. But I will still give below some examples of how to use the components.

    Fast floats and wrap cancellation

    The pull-left and pull-right classes allow you to quickly make any block float by sending it to the left or right. Do not forget about canceling the flow. You can use the clearfix class for this.

    Bootstrap: Horizontal Responsive (Mobile) Menu

    We will add the following components directly to the template, so if you want to work with the code and not just read, follow all the steps after me.

    Actually, with Bootstrap you can very easily make not just an adaptive menu, but a so-called mobile one, which is completely collapsed on small screens and hidden under one button. This technique can be seen in many responsive templates and is actually very easy to implement. The example mobile menu code is in the documentation, I'll take it from there and redo it a little.

    So, the first thing I will do is remove the block with the header, because our menu, in fact, will be the header in the case of my template. The menu code must be placed before all site content, even before the container block. Why? Yes, you will now see for yourself that the grid is already built into the navigation bar. So here's the code:

    Switch Button Logo/Name

    Search

    Don't be alarmed by the fact that there is a lot of code. This is what the site looks like now:

    But if your menu does not take up the entire width of the screen, it makes sense to center it. To do this, you should then create an additional wrapper block for the menu, which should be placed after the block with the container-fluid class. Don't forget to close this block. I gave it the navbar-wrap class. Here are the styles for it:

    That is, you can simply limit the width and center it. Or initially replace container-fluid with container .

    As you can see, we added a logo, two simple items, a drop-down item, and a search form to the menu. That is, there were many elements. You can easily customize the menu for yourself by adding your own classes to it. But for now my goal is simply to show you this component.

    This is how the menu will look on devices with a screen width of less than 768 pixels:

    As you can see, the menu has collapsed. It opens when you click on the button in the upper right corner. Only the logo remained on the screen.

    Dropdown menu

    At the same time, from the example above you can understand how a drop-down menu item is created in Bootstrap; let’s extract this code for a more detailed look:

    So, the container for a drop-down item is a regular list item with the dropdown class. Inside it is the main link, clicking on which opens a drop-down menu. It is very important to assign it a data attribute, which you see in the code; without it, nothing will work. You should also make sure that the bootstrap.js file is connected to the web pages.

    A span with the caret class is nothing more than an arrow, thanks to which you can understand that the item is a drop-down item, and below the menu itself is formed using a standard bulleted list. That's it, everything is quite simple, you can use this code to implement drop-down items.

    Adding Breadcrumbs (Breadcrumbs) Using Bootstrap

    In many stores you can find a so-called block of bread crumbs, which contains the full path to the current page. This is also easy to do using the framework, see the code:

  • Home
  • Catalog
  • Goods
  • In fact, it is enough to specify the breadcrumb class for a numbered list, and enter the usual list items into it. By the way, I’ll center the second-level headings in the template (this needs to be written in the css):

    H2( text-align: center; )

    If you want to somehow change the appearance of breadcrumbs, just use the .breadcrumb selector in CSS. For example, this is how you can remove the background color:

    Breadcrumb( background: transparent; )

    This is what the site looks like now:

    Bootstrap tables

    By default, the table will stretch across the entire window, so wrap it in a box with a limited width to limit the dimensions. By default it looks terrible, but if you add the table class to the table tag, everything will be much nicer:

    Note that in this version, the cells have clear borders only at the bottom; if you want borders on all four sides, you need to add another class:

    In principle, these are all the possibilities of tables. I already wrote a separate article about how to make an adaptive table, so I won’t repeat it. The only thing is that you can also add classes such as info, success, warning and others to the rows and cells of the table to paint them in the desired color.

    Naturally, you can easily write your own classes in style.css and use them.

    Bottom line

    I hope the article was useful and you were able to understand the most important things. You can ask any questions using comments.



    Tell friends