In this write-up, we will learn about Bootstrap 4 utility classes or helper classes. Utility classes are useful to add style quickly without writing any CSS class. By using utility classes, we can add and remove styles quickly and make the elements responsive.
In this article, we will discuss the following classes.
- Border Classes
- Float Classes
Border Classes
These classes are useful to add and remove border styles to an element,
- .border
Adds a border to an element. - .border border -0
Removes a border from an element. - .border border-right-0
Removes border from the right side of an element. - .border border-left-0
Removes the border from the left side of an element.
Open Visual Studio and create a new project. Rename it to Bootstrap4 and add the reference of Bootstrap 4 file into the head section of the page.
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" />
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
Now, let us add some style.
- <style>
- .div {
- display: inline-block;
- width: 100px;
- height: 100px;
- margin: 10px;
- }
- </style>
Add some div in the Body section and apply these classes.
- <div class="div border">Border Utility Classes</div>
- <div class="div border border-0 ">Border Utility Classes</div>
- <div class="div border border-right-0">Border Utility Classes</div>
- <div class="div border border-bottom-0">Border Utility Classes</div>
- <div class="div border border-left-0">Border Utility Classes</div>
Complete Code
- <!DOCTYPE html>
-
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>Bootstrap 4 </title>
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" />
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
- <style>
- .div {
- display: inline-block;
- width: 100px;
- height: 100px;
- margin: 10px;
- }
- </style>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <div class="div border">Border Utility Classes</div>
- <div class="div border border-0 ">Border Utility Classes</div>
- <div class="div border border-right-0">Border Utility Classes</div>
- <div class="div border border-bottom-0">Border Utility Classes</div>
- <div class="div border border-left-0">Border Utility Classes</div>
-
- </div>
- </form>
- </body>
- </html>
Run the code and check result.
Border Radius classes
These classes are used to change the border radius,
- .rounded
By using this class, we can round all the corners of an element. - .rounded-right
Rounds the right side border corners - .rounded-left
Rounds the left side border corner - .rounded-0
Removes the border radius - .rounder-circle
Creates a circle
Complete Code
- <!DOCTYPE html>
-
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>Bootstrap 4 </title>
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" />
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
- <style>
- .div {
- display: inline-block;
- width: 100px;
- width: 100px;
- height: 100px;
- margin: 10px;
- }
- </style>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <div class="div border rounded"></div>
- <div class="div border rounded-right "></div>
- <div class="div border rounded-left"></div>
- <div class="div border rounded-circle"> </div>
- <div class="div border rounded-0"></div>
-
- </div>
- </form>
- </body>
- </html>
Run the project and check the result.
Border color classes
These classes are used to add the border color.
- .border-info
- .border-primary
- .border-danger
- .border-dark
- .border-success
Complete Code
- <!DOCTYPE html>
-
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>Bootstrap 4 </title>
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" />
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
- <style>
- .div {
- display: inline-block;
- width: 100px;
- width: 100px;
- height: 100px;
- margin: 10px;
- }
- </style>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <div class="div border border-info"></div>
- <div class="div border border-primary"></div>
- <div class="div border border-danger"></div>
- <div class="div border border-dark"> </div>
- </div>
- </form>
- </body>
- </html>
Run the project and check the result
Float Classes
These classes are useful to set float attribute of an element,
- .float-right – float to the right
- .float-left – float to the left
- .float-none – no float
- .float-sm-right-– float to the right on small screen (screens size greater than 576px)
- .float-md-right- float to the right on medium screen(screens size greater than 768px)
- .float-lg-right- float to the right on large screen(screens size greater than 992px)
- .float-xl-right- float to the right on extra large screen(screens size greater than 1200px)
Add three divs and apply these classes on the div.
- <div class="float-right ">Bootstarp 4 float right Class</div><br />
- <div class="float-left">Bootstarp 4 Float Left Class</div><br />
- <div class="float-none">Bootstarp 4 Float None Class</div><br />
Complete Code
- <!DOCTYPE html>
-
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>Bootstrap 4 </title>
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" />
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
- </head>
- <body>
- <form id="form1" runat="server">
- <div class="container">
- <div class="float-right ">Bootstarp 4 float right Class</div><br />
- <div class="float-left">Bootstarp 4 Float Left Class</div><br />
- <div class="float-none">Bootstarp 4 Float None Class</div><br />
- </div>
- </form>
- </body>
- </html>
Run the project and check the result.
Summary
In this blog, we learned about Bootstrap 4 border classes and float classes.