Display Flex Online Tutorial

“Display: flex” is a powerful CSS property used to create flexible, responsive layouts. When you apply display: flex to a container, it makes its child elements (known as flex items) flexible and aligns them in a row or column, depending on the flex-direction property.

Key Flexbox Properties
Container Properties:
display: flex; – Defines a flex container.
flex-direction – Defines the direction of the flex items (e.g., row, column).
justify-content – Aligns items along the main axis (e.g., flex-start, center, space-between).
align-items – Aligns items along the cross axis (e.g., flex-start, center, stretch).
flex-wrap – Controls whether items should wrap onto multiple lines (e.g., nowrap, wrap).
align-content – Aligns flex lines within the flex container (e.g., flex-start, space-between).

Item Properties:
flex – Shorthand for flex-grow, flex-shrink, and flex-basis (e.g., 1 makes the item grow to fill available space).
align-self – Allows the flex item to override the container’s align-items property for its own alignment.

Html

<div class="flaxbox4">
   <div class="item">
      <span class="clr-1">Travel Agency in India</span>
      <h1>50%<small>/OFF</small></h1>
      <p>www.orioleholiday.com</p>
   </div>
   <div class="item">
      <span class="clr-1">Travel Agency in India</span>
      <h1>50%<small>/OFF</small></h1>
      <p>www.orioleholiday.com</p>
   </div>
   <div class="item">
      <span class="clr-1">Travel Agency in India</span>
      <h1>50%<small>/OFF</small></h1>
      <p>www.orioleholiday.com</p>
   </div>
   <div class="item">
      <span class="clr-1">Travel Agency in India</span>
      <h1>50%<small>/OFF</small></h1>
      <p>www.orioleholiday.com</p>
   </div>
</div>
<div style="clear: both;"></div>
<div class="flaxbox3">
   <div class="item">
      <span class="clr-1">Travel Agency in India</span>
      <h1>50%<small>/OFF</small></h1>
      <p>www.orioleholiday.com</p>
   </div>
   <div class="item">
      <span class="clr-1">Travel Agency in India</span>
      <h1>50%<small>/OFF</small></h1>
      <p>www.orioleholiday.com</p>
   </div>
   <div class="item">
      <span class="clr-1">Travel Agency in India</span>
      <h1>50%<small>/OFF</small></h1>
      <p>www.orioleholiday.com</p>
   </div>
</div>
<div class="flaxbox2">
   <div class="item">
      <span class="clr-1">Travel Agency in India</span>
      <h1>50%<small>/OFF</small></h1>
      <p>www.orioleholiday.com</p>
   </div>
   <div class="item">
      <span class="clr-1">Travel Agency in India</span>
      <h1>50%<small>/OFF</small></h1>
      <p>www.orioleholiday.com</p>
   </div>
</div>
<div class="flaxbox">
   <div class="item">
      <div class="alert alert-success">
         <strong>Success!</strong> Indicates a successful or positive action.
      </div>
   </div>
</div>

Css

.flaxbox4 {
display: flex;
padding: 10px;
gap: 10px; /* Space between items */
flex-wrap: wrap;
}
.flaxbox4 .item {
border:1px solid #4CAF50;
color: black;
padding: 20px;
text-align: center;
flex: 1; /* Items will grow to fill the container */
}
.flaxbox3 {
display: flex;
justify-content: center;
align-items: center;
padding: 10px;
gap: 10px; /* Space between items */
flex-wrap: wrap;
}
.flaxbox3 .item {
border: 1px solid #4CAF50;
color: black;
padding: 20px;
text-align: center;
width: calc(33% - 100px);
}
.flaxbox2 {
display: flex;
justify-content: center;
align-items: center;
padding: 10px;
gap: 10px; /* Space between items */
flex-wrap: wrap;
}
.flaxbox2 .item {
border: 1px solid #4CAF50;
color: black;
padding: 20px;
text-align: center;
width: calc(33% - 100px);
}
.flaxbox {
display: flex;
justify-content: center;
align-items: center;
padding: 10px;
gap: 10px; /* Space between items */
flex-wrap: wrap;
}
.flaxbox .item {
color: black;
text-align: center;
width: calc(100% - 534px);
}

For Responsive

@media (min-width: 1281px) {
//CSS
}
/*
##Device = Laptops, Desktops
##Screen = B/w 1025px to 1280px
*/
@media (min-width: 1025px) and (max-width: 1280px) {
//CSS
}
/*
##Device = Tablets, Ipads (portrait)
##Screen = B/w 768px to 1024px
*/
@media (min-width: 768px) and (max-width: 1024px) {
.flaxbox3{
flex-wrap: inherit;
}
.flaxbox3 .item{
width: calc(33% - 0px);
}
.flaxbox2{
flex-wrap: inherit;
}
.flaxbox2 .item{
width: calc(50% - 0px);
}
.flaxbox .item{
width: calc(100% - 0px);
}
}
/*
##Device = Tablets, Ipads (landscape)
##Screen = B/w 768px to 1024px
*/
@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
.flaxbox3{
flex-wrap: inherit;
}
.flaxbox3 .item{
width: calc(33% - 0px);
}
.flaxbox2{
flex-wrap: inherit;
}
.flaxbox2 .item{
width: calc(50% - 0px);
}
.flaxbox .item{
width: calc(100% - 0px);
}
}
/*
##Device = Low Resolution Tablets, Mobiles (Landscape)
##Screen = B/w 481px to 767px
*/
@media (min-width: 481px) and (max-width: 767px) {
.flaxbox3{
flex-wrap: inherit;
}
.flaxbox3 .item{
width: calc(33% - 0px);
}
.flaxbox2{
flex-wrap: inherit;
}
.flaxbox2 .item{
width: calc(50% - 0px);
}
.flaxbox .item{
width: calc(100% - 0px);
}
}
/*
##Device = Most of the Smartphones Mobiles (Portrait)
##Screen = B/w 320px to 479px
*/
@media (min-width: 320px) and (max-width: 480px) {
.flaxbox3 .item{
width: calc(100% - 0px);
}
.flaxbox2 .item{
width: calc(100% - 0px);
}
.flaxbox .item{
width: calc(100% - 0px);
}
}

administrator

Leave a Reply

Your email address will not be published. Required fields are marked *