Open In App

.pull-left and .pull-right classes in Bootstrap 4

Improve
Improve
Like Article
Like
Save
Share
Report

The .pull-left and .pull-right classes have been replaced with the .float-left and .float-right classes in Bootstrap 4. These utility classes are used to float an element to the left or right on the various viewport sizes based on the Bootstrap Grid. It works using the CSS float property.

Using .pull-left and .pull-right classes
These classes help to float the elements:

  • The .pull-left class is used to float the element to the left.
  • The .pull-right class is used to float the element to the right.

Example:




<!DOCTYPE html>
<html>
  
<head>
    <title>Bootstrap Floating utility class</title>
  
    <!-- Include Bootstrap CSS -->
    <link rel="stylesheet" 
          href=
</head>
  
<body>
    <div class="container">
        <h1 style="color:green">
          GeeksforGeeks
      </h1>
        <b>Bootstrap Floating utility class</b>
        <br>
  
        <div class="pull-left">
          This div floats to the left.
      </div>
        <br>
        <div class="pull-right">
          This div floats to the right.
      </div>
        <br>
    </div>
</body>
  
</html>


Output:
pull-left-right

Base Classes
There are three classes which help in floating the elements:

  • The .float-left class is used to float the element to the left.
  • The .float-right class is used to float the element to the right.
  • The .float-none class is used to disable the floating.

These classes will work on all viewport sizes unless specified using their responsive versions.

Example:




<!DOCTYPE html>
<html>
  
<head>
    <title>
      Bootstrap 4 Floating utility class
  </title>
  
    <!-- Include Bootstrap CSS -->
    <link rel="stylesheet"
          href=
</head>
  
<body>
  
    <div class="container">
        <h1 style="color:green">
          GeeksforGeeks
      </h1>
        <b>Bootstrap 4 Floating utility class</b>
        <br>
  
        <div class="float-left">
          This div floats to the left.
      </div>
        <br>
        <div class="float-right">
          This div floats to the right.
      </div>
        <br>
        <div class="float-none">
          This div does not float.
      </div>
    </div>
</body>
  
</html>


Output:
base-floats

Responsive floating based on viewport sizes
The responsive variations of the base classes can be used to apply the floating only on specified viewport sizes. There are four viewport size variations available to be used.

  • sm: This is the small breakpoint. All classes using this will float on viewports sized small or wider.
  • md: This is the medium breakpoint. All classes using this will float on viewports sized medium or wider.
  • lg: This is the large breakpoint. All classes using this will float on viewports sized large or wider.
  • xl: This is the extra-large breakpoint. All classes using this will float on viewports sized extra-large or wider.

Example:




<!DOCTYPE html>
<html>
  
<head>
    <title>Responsive variations
      with float</title>
  
    <!-- Include Bootstrap CSS -->
    <link rel="stylesheet" 
          href=
</head>
  
<body>
  
    <div class="container">
        <h1 style="color:green">GeeksforGeeks</h1>
        <b>Responsive variations with float</b>
        <br>
  
        <div class="float-sm-left">
          This div floats to the left on small or wider viewports.
      </div>
        <br>
        <div class="float-sm-right">
          This div floats to the right on small or wider viewports.
      </div>
        <br>
        <div class="float-sm-none">
          This div does not float on small or wider viewports.
      </div>
  
        <div class="float-md-left">
          This div floats to the left on medium or wider viewports.
      </div>
        <br>
        <div class="float-md-right">
          This div floats to the right on medium or wider viewports.
      </div>
        <br>
        <div class="float-md-none">
          This div does not float on medium or wider viewports.
      </div>
  
        <div class="float-lg-left">
          This div floats to the left on large or wider viewports.
      </div>
        <br>
        <div class="float-lg-right">
          This div floats to the right on large or wider viewports.
      </div>
        <br>
        <div class="float-lg-none">
          This div does not float on large or wider viewports.
      </div>
  
        <div class="float-xl-left">
          This div floats to the left on extra large or wider viewports.
      </div>
        <br>
        <div class="float-xl-right">
          This div floats to the right on extra large or wider viewports.
      </div>
        <br>
        <div class="float-xl-none">
          This div does not float on extra large or wider viewports.
      </div>
    </div>
</body>
  
</html>


Output:
responsive



Last Updated : 30 Aug, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads