Wednesday, 9 May 2018

023 Bootstrap Flex

Bootstrap Flex
Flexbox is layout pattern , it helps to alignment of items and
specification of the layout direction and specification of layout order of items.

To create a flexbox container and to transform direct children into flex items, use the "d-flex" class. 

Example


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
            <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
           <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
           <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<style>

.my-flex-item_1
   {
           background-color: Blue;
           border: 1px dotted grey;
           height: 48px;
           width:130px;
   }

.my-flex-item_2
   {
           background-color: #F18D00;
           border: 1px dotted grey;
          height: 48px;
          width:130px;
   }
     .my-flex-item_3
    {
          background-color: #4CAF50;
          border: 1px dotted grey;
          height: 48px;
          width:130px;
     }
</style>
<meta name="viewport" content="width = device-width, initial-scale = 1">
<body>
<div class="container">
           <div class="d-flex bg-secondary text-white">
           <div class="my-flex-item_1">
                     My Flex Item 1</div>
            <div class="my-flex-item_2">
             My Flex Item 2</div>
             <div class="my-flex-item_3">
            My Flex Item 3</div>
           </div>
    </div>
</body>
</html>

My Flex Item 1
My Flex Item 2
My Flex Item 3
You need to use .flex-row to set a horizontal direction or .flex-row-reverse to start the horizontal direction from the opposite side.

Example

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
          <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
          <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<style>
.my-flex-item_1
   {
        background-color: Blue;
        border: 1px dotted grey;
        height: 48px;
        width:130px;
}

.my-flex-item_2
{
       background-color: #F18D00;
       border: 1px dotted grey;
       height: 48px;
       width:130px;
}

.my-flex-item_3
{
      background-color: #4CAF50;
      border: 1px dotted grey;
      height: 48px;
      width:130px;
}
</style>

<meta name="viewport" content="width = device-width, initial-scale = 1">
<body>
<div class="container">
<div class="d-flex bg-secondary text-white flex-row">
         <div class="my-flex-item_1">
           My Flex Item 1</div>
         <div class="my-flex-item_2">
         My Flex Item 2</div>
         <div class="my-flex-item_3">
          My Flex Item 3</div>
</div>

<div class="d-flex bg-secondary text-white flex-row-reverse">
<div class="my-flex-item_1">
            My Flex Item 1</div>
 <div class="my-flex-item_2">
           My Flex Item 2</div>
<div class="my-flex-item_3">
              My Flex Item 3</div>
   </div>
</div>
</body>
</html>

Output:

My Flex Item 1
My Flex Item 2
My Flex Item 3
My Flex Item 1
My Flex Item 2
My Flex Item 3





Responsive Version of d-flex available
  • .d-flex
  • .d-sm-flex
  • .d-md-flex
  • .d-lg-flex
  • .d-xl-flex
  • .d-xl-inline-flex

Justify Content
Use the "justify-content-*" class to change the alignment of flex items.The following are the classes.



  • justify-content-start
  • justify-content-end
  • justify-content-center
  • justify-content-between
  • justify-content-around
 Example

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
.my-flex-item_1
{
background-color: Blue;
border: 1px dotted grey;
height: 48px;
width:130px;
}
.my-flex-item_2
{
background-color: #F18D00;
border: 1px dotted grey;
height: 48px;
width:130px;
}
.my-flex-item_3
{
background-color: #4CAF50;
border: 1px dotted grey;
height: 48px;
width:130px;
}
</style>
<meta name="viewport" content="width = device-width, initial-scale = 1">
<body>
<div class="container">
<div class="d-flex bg-secondary text-white flex-row justify-content-start">
<div class="my-flex-item_1">
My Flex Item 1</div>
<div class="my-flex-item_2">
My Flex Item 2</div>
<div class="my-flex-item_3">
My Flex Item 3</div>
</div>
<div class="d-flex bg-secondary text-white flex-row justify-content-end">
<div class="my-flex-item_1">
My Flex Item 1</div>
<div class="my-flex-item_2">
My Flex Item 2</div>
<div class="my-flex-item_3">
My Flex Item 3</div>
</div>
<div class="d-flex bg-secondary text-white flex-row justify-content-center">
<div class="my-flex-item_1">
My Flex Item 1</div>
<div class="my-flex-item_2">
My Flex Item 2</div>
<div class="my-flex-item_3">
My Flex Item 3</div>
</div>
<div class="d-flex bg-secondary text-white flex-row justify-content-between">
<div class="my-flex-item_1">
My Flex Item 1</div>
<div class="my-flex-item_2">
My Flex Item 2</div>
<div class="my-flex-item_3">
My Flex Item 3</div>
</div>
<div class="d-flex bg-secondary text-white flex-row justify-content-around">
<div class="my-flex-item_1">
My Flex Item 1</div>
<div class="my-flex-item_2">
My Flex Item 2</div>
<div class="my-flex-item_3">
My Flex Item 3</div>
</div>
</div>
</body>
</html>


Output
My Flex Item 1
My Flex Item 2
My Flex Item 3
My Flex Item 1
My Flex Item 2
My Flex Item 3
My Flex Item 1
My Flex Item 2
My Flex Item 3
My Flex Item 1
My Flex Item 2
My Flex Item 3
My Flex Item 1
My Flex Item 2
My Flex Item 3






Vertical Direction
You can use .flex-column or .flex-column-reverse to make flex vertical arrangement.


Example

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
.my-flex-item_1
{
background-color: Blue;
border: 1px dotted grey;
height: 48px;
width:130px;
}
.my-flex-item_2
{
background-color: #F18D00;
border: 1px dotted grey;
height: 48px;
width:130px;
}
.my-flex-item_3
{
background-color: #4CAF50;
border: 1px dotted grey;
height: 48px;
width:130px;
}
</style>
<meta name="viewport" content="width = device-width, initial-scale = 1">
<body>
<div class="container">
<div class="d-flex bg-secondary text-white flex-column">
<div class="my-flex-item_1">
My Flex Item 1</div>
<div class="my-flex-item_2">
My Flex Item 2</div>
<div class="my-flex-item_3">
My Flex Item 3</div>
</div>
<div class="d-flex bg-secondary text-white flex-column-reverse">
<div class="my-flex-item_1">
My Flex Item 1</div>
<div class="my-flex-item_2">
My Flex Item 2</div>
<div class="my-flex-item_3">
My Flex Item 3</div>
</div>
</div>
</body>
</html>


Output :

My Flex Item 1
My Flex Item 2
My Flex Item 3
My Flex Item 1
My Flex Item 2
My Flex Item 3



No comments:

Post a Comment

বাঙালির বেড়ানো সেরা চারটি ঠিকানা

  বাঙালি মানে ঘোড়া পাগল | দু একদিন ছুটি পেলো মানে বাঙালি চলল ঘুরতে | সে সমুদ্রই হোক , পাহাড়ি হোক বা নদী হোক। বাঙালির ...