TimesCoding

Learn, Practice, and Excel with our Coding Tutorials!

Creating a Stylish Button with Bootstrap 5.3.0

June 13, 2023 2 Min read BOOTSTRAP CSS

Hello, we will create a stylish button using Bootstrap 5.3.0. We’ll incorporate a 2px border, reduce the space around the text, and add a captivating moving border effect. Let’s dive into the step-by-step process.

Step 1: Firstly, we need to include the Bootstrap 5.3.0 CSS and JavaScript files in our HTML document. You can use these files after downloading or use a content delivery network (CDN). Here’s an example of including Bootstrap from a CDN:

<!DOCTYPE html>
<html>
<head>
  <title>Creating a Stylish Button with Bootstrap 5.3.0</title>
  <!-- Include Bootstrap CSS -->
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
  <!-- Content goes here -->
  
  <!-- Include Bootstrap JS -->
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

Step 2: Creating the Stylish Button Within the <body> tag, let’s create a button using the Bootstrap classes and add our custom styles:


<div class="container mt-5">
  <a href="#" class="btn btn-stylish"> Button </a>
</div>

Step 3: Adding Custom Styles Next, let’s define the custom styles for our stylish button. We’ll reduce the space around the text, set a 2px border with a different color, and include the moving border effect.

<!-- CSS -->
<style>
  .btn-stylish {
    position: relative;
    display: inline-block;
    padding: 0.5rem 1rem; /* Adjust the padding values as desired */
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.5;
    text-align: center;
    text-transform: uppercase;
    text-decoration: none;
    white-space: nowrap;
    border: 2px solid #ff6347; /* Set the border color as desired */
    border-radius: 0.25rem;
    overflow: hidden;
    cursor: pointer;
    background-color: #007bff;
    color: #fff;
    transition: background-color 0.3s ease, color 0.3s ease;
    z-index: 1;
  }

  .btn-stylish::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 2px solid #ff6347; /* Set the border color as desired */
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: -1;
  }

  .btn-stylish:hover {
    background-color: transparent;
    color: #007bff;
  }

  .btn-stylish:hover::before {
    transform: translateX(0);
  }
</style>

By following these simple steps, we have successfully created a stylish button using Bootstrap 5.3.0. We incorporated a 2px border, reduced the space around the text, and added a captivating moving border effect. Feel free to experiment with different colors, padding values, and other styles to customize the button according

Related Post:
What are CSS Margins and Padding − CSS Margins and padding are two of the most important CSS (Cascading Style Sheets) properties for controlling the space between elements on a web page..
CSS Selectors, Properties, and Values − CSS (Cascading Style Sheets) is a style sheet language used for describing the presentation of a document written in HTML or XML. CSS allows developers.