What's the best way to add click functionality to a bootstrap 5 card

I am currently learning Bootstrap 5, html, and CSS. I am using these technologies to develop a website and implementing Bootstrap 5 to create cards. I wanted to make these cards clickable so that they can redirect users to another page on the website. However, even after adding anchor tags, the cards remain unclickable.

Test.html

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<title>Home |</title>

<meta name="description" content="Write an awesome description for your new site here. It will appear in your document head meta (for Google search results) and in your feed.xml site description." />

<link rel="stylesheet" href="/_bridgetown/static/css/main.c7d4dd3f1984a290e9be.css" />
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8defe2e2f9fef9ffecfdcdb8a3bea3bd">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" 
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link rel="stylesheet" 
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link rel="stylesheet" href="../css/index.css" />
<link
          rel="stylesheet"
          data-purpose="Layout StyleSheet"
          title="Default"
    disabled
          href="/css/app-937c1ff7d52fd6f78dd9322599e2b5d4.css?vsn=d"
        >
...

Test.css

@import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap');

body {
    background: hsl(233, 47%, 96%);
    font-family: 'Poppins', sans-serif;
}

hr {
    border: 1.5px solid hsl(216, 90%, 44%)
}

.crd {
    background: hsl(233, 47%, 96%);
    transition: all;
}

.crd:hover {
    background: hsl(216, 90%, 44%);
    color: #fff;
    transition: 0.5s;
}

...

@import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap');

body {
    background: hsl(233, 47%, 96%);
    font-family: 'Poppins', sans-serif;
}

hr {
    border: 1.5px solid hsl(216, 90%, 44%)
}

.crd {
    background: hsl(233, 47%, 96%);
    transition: all;
}

.crd:hover {
    background: hsl(216, 90%, 44%);
    color: #fff;
    transition: 0.5s;
}

...
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<title>Home |</title>

<meta name="description" content="Write an awesome description for your new site here. It will appear in your document head meta (for Google search results) and in your feed.xml site description." />

<link rel="stylesheet" href="/_bridgetown/static/css/main.c7d4dd3f1984a290e9be.css" />
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dbb9b4b4afa8afa9baab9beef5e8f5eb">[email protected]</a>/dist/css/bootstrap...

Answer №1

Utilizing the stretched-link class in Bootstrap can provide a convenient solution. By simply adding this class to a link within your card, you can make the entire card clickable.

<div class="col-lg-4 col-md-6">
  <div class="card text-center p-4 mb-2 crd">
    <i class="fa-solid fa-camera-cctv fa-3x"></i>
    <h4>CCTV Services</h4>
    <p class="p-2">
      <b>CCTV Services</b> are a crucial aspect
          of any business. CCTV offers real-time
          monitoring of multiple locations; the security
          it provides is invaluable, enabling
          businesses to have peace of mind knowing that...
    </p>
    <a href="/about.html" class="stretched-link"></a>
  </div>
</div>

source : https://getbootstrap.com/docs/4.4/utilities/stretched-link/

Answer №2

   <div class="col-lg-4 col-md-6">
      <a href="/services/cctv.html" class="nav-link" style="pointer:cursor">
        <div class="card text-center p-4 mb-2 crd">
          <i class="fa-solid fa-camera-cctv fa-3x"></i>
          <h4>CCTV Installation</h4>
          <p class="p-2">
            <b>CCTV installation services</b> are crucial for the safety and security of any business. CCTV systems offer real-time monitoring of
            various areas, providing peace of mind to business owners by ensuring the protection of their premises.
          </p>
        </div>
      </a>
    </div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The content in the flex box item with horizontal scroll is overflowing beyond its boundaries

I am working with a flex box container that contains two child elements: a left side and a right side. I want the right side item to have a horizontal scrollbar in order to fit its content. .container { display: flex; overflow: hidden; height: 300 ...

Place a written message on an picture

<head> <style> .relative{position:relative; width:600px;} .absolute-text{position:absolute; bottom:1; font-size:12px; font-family:"vedana"; background:rgba(251,251,251,0.5); padding:10px 20px; width:10%; text-align:center;} </style> < ...

Troubleshooting Problems with CSS `transform` in JQuery UI's `Slide` Transition

While implementing JQueryUI's slide transition on an element with a CSS transform, I encountered an issue where the top half of the element gets hidden during the animation. Is there a way to tweak either my JQueryUI animation or CSS to avoid this pro ...

Enhancing user experience by highlighting invalid input fields with a red border using client-side HTML5 validation and Bootstrap 5.2

When reviewing the Bootstrap 5.2 validation documentation, https://getbootstrap.com/docs/5.2/forms/validation/ "It has come to our attention that the client-side custom validation styles and tooltips are not accessible at this time, as they are not ...

Filtering visibility of bootstrap cards based on card content

I am having trouble with a seemingly simple task. I have a grid of cards that have the following structure: <div class="card"> <img src="data:image/jpg;base64,{{ books[book]['cover']}}" class="card-img-top" ...

Efficiently Embedding Images into Canvas Elements

I am struggling with loading individual photos from an array into "canvas" tags. In my function, I generate multiple sets of "div" tags with a "canvas" tag inside them, but I'm facing difficulties in inserting images from an array into these "canvas" ...

configuring radio buttons with a default value using PHP

I am facing an issue in setting a default value for radio buttons in my form. The default value needs to be fetched from the database. I am aware of how to set a default value using checked="checked", however, in my specific case, I am struggling with in ...

Display an image overlay upon hovering over a div

I've developed an add-on for Elementor that includes a card with the following HTML markup: <div class="card"> <div class="header"> <img src="img.jpg"> < ...

Stop the link height from changing when hovered over

Incorporating Angular, Angular Material, and Angular Flex-Layout, I have designed a collection of links that resemble cards or tiles. The links initially display an icon and title but transition to show informational text upon hovering. However, for links ...

Submitting both $_POST[] data and $_FILES[] in a single AJAX request

Struggling with uploading images along with dates on my website. I am passing the date using $_POST and the image files in $_FILES. Here is the Javascript code snippet: (function post_image_content() { var input = document.getElementById("images"), ...

Exploring the possibilities of device orientation in combination with 3D transforms

Imagine a project that aims to create a cube with sides representing different geolocations. The cube's sides for east, west, up, ground, north, and south are meant to always point in their respective directions. To gather the necessary data, the proj ...

Thickness of Border in Bootstrap Cards

I've been attempting to include a thicker border around the entirety of my Bootstrap 4 card. Despite specifying a thicker border, nothing seems to change. Below is a snippet of the code I'm working with: <div class="container"> <di ...

Display the accurate duration based on the dates selected in an HTML form automatically

If someone has office hours on Monday, Wednesday, and Friday from 7:00 am to 7:00 pm, and on Tuesday and Thursday from 10:00 am to 9:00 pm, the dropdown menu should display only the timings of 7:00 AM to 7:00 PM if the selected date is a Monday, Wednesda ...

HTML needs to be wrapped around every set of three items using C# ForEach loop

Currently, I am faced with the task of constructing an HTML code structure within C# code behind. Specifically, I need to insert an HTML element that spans 3 columns in a row of 12 columns (utilizing Zurb Foundation). To achieve this, I am iterating throu ...

Show a div depending on user input

For those with more programming experience than myself, I have a simple question. In Rails, using coffescript, I want to show additional content based on a user's selection. Essentially, if they click on a checkbox, it should reveal an extra field for ...

Using JavaScript to dynamically insert HTML content and create a toggle effect

Within a div, I have a collection of large images that I am attempting to insert into another div using JavaScript toggle functionality. Please test the code snippet provided below. $(".toggleimages").on("click", function(e) { e.preventDefault(); ...

What is the best way to ensure that a child div can expand to fit within the scrollable area of its parent div

I am facing an issue with a parent div that changes size based on the content inside it. When the content exceeds the initial size, causing the parent to scroll instead of expanding, I have a child div set to 100% width and height of the parent. However, t ...

Switch Cursor on Movable Area in Electron

Working on a project in Electron and having some trouble with a frameless window. I have designated certain top areas as draggable using -webkit-app-region: drag, but the cursor will not change as expected. Although this code snippet won't make the e ...

Utilizing CSS variables and HSLA, create a distinctive linear gradient styling

I am encountering an issue with a CSS variable: :root{ --red: hsl(0, 100%, 74%); } Despite defining the variable, it does not work in the following code snippet: .page-wrapper{ background-image: linear-gradient(hsla(var(--red),.6), hsla(var(--red),.6 ...

Organizing Pictures in a Gridded Design

My dilemma lies in displaying a set of thumbnail images within a div. The width of the div can vary depending on the screen size. Each image is fixed at 150px * 150px with a padding of 5px. I aim to arrange these thumbnails in a grid layout while ensuring ...