Posts

How to style second last items in a list?

Please use following CSS syntax to style the second last element in a list or group.

<style>
  .list-number-123 {
    list-style: none;
  }

  .list-number-123 li:nth-last-child(2) {
    background: #edeaea;
    color: #30a960;
    font-weight: 700;
    padding: 10px;
  }
</style>

<ul class="list-number-123">
  <li>Item 1</li>
  <li>Item 2</li>
  <li>Item 3</li>
  <li>Item 4</li>
  <li>Item 5</li>
  <li>Item 6</li>
  <li>Item 7</li>
</ul>
  • Item 1
  • Item 2
  • Item 3
  • Item 4
  • Item 5
  • Item 6
  • Item 7

How to extend number of DIVI columns (more than 6)?

Step 01: Include the below CSS to theme options

/* Custom Columns */
.ten-columns .et_pb_module {width: 10%; float: left;}
.nine-columns .et_pb_module {width: 11.11%; float: left;}
.eight-columns .et_pb_module {width: 12.5%; float: left;}
.seven-columns .et_pb_module {width: 14.28%; float: left;}
.six-columns .et_pb_module {width: 16.66%; float: left;}
.five-columns .et_pb_module {width: 20%; float: left;}
.four-columns .et_pb_module {width: 25%; float: left;}
.three-columns .et_pb_module {width: 33.33%; float: left;}
.two-columns .et_pb_module {width: 50%; float: left;}

@media (max-width: 980px){
  .ten-columns .et_pb_module {width: 20%;}
  .nine-columns .et_pb_module {width: 33.3%;}
  .eight-columns .et_pb_module {width: 25%;}
  .seven-columns .et_pb_module {width: 33.33%;}
  .six-columns .et_pb_module {width: 33.3%;}
  .five-columns .et_pb_module {width: 33.3%;}
  .four-columns .et_pb_module {width: 50%;}
  .three-columns .et_pb_module {width: 33.33%;}
  .two-columns .et_pb_module {width: 50%;}
}
 
@media all and (max-width: 767px) {
  .ten-columns .et_pb_module {width: 25%;}
  .nine-columns .et_pb_module {width: 33.33%;}
  .eight-columns .et_pb_module {width: 25%;}
  .seven-columns .et_pb_module {width: 33.33%;}
  .six-columns .et_pb_module {width: 50%;}
  .five-columns .et_pb_module {width: 33.33%;}
  .four-columns .et_pb_module {width: 50%;}
  .three-columns .et_pb_module {width: 33.33%;}
  .two-columns .et_pb_module {width: 50%;}
}

@media only screen and (max-width: 479px) {
  .ten-columns .et_pb_module {width: 50%;}
  .nine-columns .et_pb_module {width: 50%;}
  .eight-columns .et_pb_module {width: 50%;}
  .seven-columns .et_pb_module {width: 50%;}
  .six-columns .et_pb_module {width: 50%;}
  .five-columns .et_pb_module {width: 50%;}
  .four-columns .et_pb_module {width: 100%;}
  .three-columns .et_pb_module {width: 100%;}
  .two-columns .et_pb_module {width: 50%;}
}

Step 02: Add the relevant class to your row, depending on the number of columns needed.

Step 03: Remember to only keep one column in the DIVI row settings and use DIVI modules as columns. That’s it Happy Coding!

How to center a div vertically and horizontally using CSS?

Centered DIV element

Please use following method to align any content vertically and horizontally centered..

<title>Vertical and horizontal center align div</title>
<style>
  .container-box {
    background: #efefef;
    max-width: 1080px;
    min-height: 500px;
  }

  .centered-div {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;     
  }

  .box {
    background: #ccc;
    text-align: center;
    padding: 50px;
  }
</style>
  <div class="container-box centered-div">
    <div class="box">
        This element is horizontally and vertically aligned to center!
    </div>
  </div>
Vertical and horizontal center align div
This element is horizontally and vertically aligned to center!

How align an absolute positioned div relative to the max-width of contents?

The following CSS code will align the absolute positioned div inside a container.

Note: This will only work depending on the max-width of the container. Need to adjust for mobile devices.

<!Doctype html>
<html>
<head>
  <style>
    .page-body {
       max-width: 800px;
       background: #ccc;
       position: relative;
       display: flex;
       flex-direction: column;
       align-items: center;
       padding: 100px;
     }
    .page-container {
       max-width: 500px;
       background: #eee;
       display: block;
       padding: 20px;
    }
    .abs-position {
       position: absolute;
       top: 50px;
       right: calc((100% - 500px)/2 + 0px);
       padding: 20px;
       text-align: center;
       border: 1px solid #ccc;
       border-radius: 10px;
       background: #a5f6c0;
       width: 200px;
    }
  </style>
</head>
<body>
  <div class="page-body">
    <div class="page-container">
      <h1>Page title</h1>
      <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
    </div>
    <div class="abs-position">I am positioned absolute!</div>
  </div>
</body>
</html>

Page title

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

I am positioned absolute!

How to create load more function with jQuery

Step 1: Create the html containers that needed to be used for the load more function.

HTML

<!DOCTYPE html>
<html>

<head>
    <title>CSS with Superpowers</title>
    <link rel="stylesheet" href="public/css/style.css">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
</head>

<body>
    <header>
        <h1>JQuery Load more</h1>
    </header>

    <div class="box-group">
        <div class="box box-1">Card 1</div>
        <div class="box box-2">Card 2</div>

        <div class="box box-3">Card 3</div>
    </div>

    <div class="box-group">
        <div class="box box-4">card 4</div>

        <div class="box box-5">Card 5</div>

        <div class="box box-6">Card 6</div>
    </div>

    <div class="box-group">
        <div class="box box-1">Card 7</div>

        <div class="box box-2">Card 8</div>

        <div class="box box-3">Card 9</div>
    </div>

    <div class="box-group">
        <div class="box box-4">card 10</div>

        <div class="box box-5">Card 11</div>

        <div class="box box-6">Card 12</div>
    </div>
</body>

</html>

CSS

* {
  margin: 0;
  padding: 0;
}

body {
  font-family: Arial, Helvetica, sans-serif;
}

header h1 {
  text-align: center;
}

/* 
* 
* call to action boxes 
*
*/
.box-group {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
}

.box-group .box {
  padding: 50px;
  margin: 10px;
  width: 100%;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -ms-flex-wrap: wrap;
      flex-wrap: wrap;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  color: #ffffff;
  font-size: 24px;
  text-transform: uppercase;
  -webkit-box-shadow: 5px 5px 5px #ccc;
          box-shadow: 5px 5px 5px #ccc;
  font-weight: 700;
}

.box-group .box-1 {
  background-color: #CCCCCC;
}

.box-group .box-2 {
  background-color: #FB8C00;
}

.box-group .box-3 {
  background-color: #F46524;
}

.box-group .box-4 {
  background-color: #6AA84F;
}

.box-group .box-5 {
  background-color: #6D9EEB;
}

.box-group .box-6 {
  background-color: #8E7CC3;
}

.load-more-container button {
  padding: 15px 10px;
  width: 200px;
  border: none;
  -webkit-box-shadow: 0px 0px 5px #ccc;
          box-shadow: 0px 0px 5px #ccc;
  display: block;
  margin: 15px auto;
  background-color: #F46524;
  color: #ffffff;
  text-transform: uppercase;
  -webkit-transition: 0.2s;
  transition: 0.2s;
}

.load-more-container button:hover {
  background-color: #ffffff;
  color: #F46524;
  cursor: pointer;
  -webkit-transition: 0.2s;
  transition: 0.2s;
}

Preview

Step 2: Make sure the containers have a wrapper to such as below mentioned example.

    <div class="load-more-container">
        <div class="box-group">
            <div class="box box-1">Card 1</div>

            <div class="box box-2">Card 2</div>

            <div class="box box-3">Card 3</div>
        </div>
    </div>

Step 3: Connect jQuery CDN and a JS file to run the load script.

<head>
    <title>CSS with Superpowers</title>
    <link rel="stylesheet" href="public/css/style.css">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
    <script src="app.js"></script>
</head>

Step 4: Write the below script in the app.js file.
jQuery slice function is used to hide and show the containers. Here in this script the limit is set to 2. It can vary depending on the number of containers.

jQuery

$(function() {
    /* Store page load more functions */
    $(".box-group").hide();
    $(".box-group").slice(0, 2).show();

    $(".load-more-container").append('<p id="load-more-button-container"><button type="button" id="load-more-button">Load More</button></p>');

    $("#load-more-button").click(function() {
        $(".box-group").show(500);
        $("#load-more-button-container").hide();
    });
});

Preview

HTML preview after connecting the load more script