Putting a link on a button exclusively

Currently, I am utilizing Bootstrap 5 to develop a website. One of the pages features a header that consists of an image with text and a button overlay. The intended functionality is for users to be redirected to another site when clicking on the button. However, the current issue is that clicking anywhere on the image also triggers the redirect.

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

#copyright {
  border-top: 1px solid hsl(0, 0%, 20%);
}

.c-item {
  height: 900px;
}

.c-img {
  height: 100%;
  object-fit: cover;
  filter: brightness(0.6);
}

#team-img {
  height: 100%;
  object-fit: cover;
}

.dropdown:hover .dropdown-menu {
  display: block;
  background-color: hsl(196, 66%, 82%);
}

.dropdown-item:hover {
  background-color: hsl(198, 100%, 43%);
}

#button {
    background-color:hsl(208, 96%, 29%);
    border: 1px solid hsl(208, 96%, 29%);
}

#button:hover {
    background-color:hsl(198, 100%, 43%);
    border: 1px solid hsl(198, 100%, 43%);
}

#caption-h2 {
    text-shadow: 1px 1px 10px hsl(0, 0%, 0%);
    padding:1rem;
}

#caption-p {
    color: hsl(208, 96%, 29%);
}
<!-- SHOWCASE START -->
<section>
    <div id="herocarousel" class="carousel slide" data-bs-ride="carousel" >
          <div class="carousel-inner">
            <div class="carousel-item active c-item">
              <img src="./images/about001.jpg" class="d-block w-100 c-img" alt="...">
              <div class="carousel-caption mt-3 top-0 ">
                <p class=" dtext-uppercase text-center" id="caption-p">We&nbsp;Are</p>
                <h2 class="display-3 fw-bolder text-capitalize" id="caption-h2">Project Name</h2>
                <div>
                    <a href="link">
                        <button class="btn btn-primary px-4 py-2 fs-5 mb-5" id="button">Book&nbsp;a&nbsp;Call</button>
                    </a>
                    
                </div>      
            </div>  
        </div> 
    </div>
  </section>
  <!-- SHOWCASE CLOSE -->

Answer №1

You have the option to utilize button tags. Simply eliminate the button element and format the link as a button (remember to include the URL in the href attribute, and you can also specify target="_blank" to open it in a new window):

<a href="link-to-somewhere" target="_blank" class="btn btn-primary px-4 py-2 fs-5 mb-5" id="button">Book&nbsp;a&nbsp;Call</a>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="caa8a5a5beb9beb8abba8affe4f9e4f8">[email protected]</a>/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cba9a4a4bfb8bfb9aabb8bfee5f8e5f9">[email protected]</a>/dist/js/bootstrap.bundle.min.js"></script>


<section>
  <div id="herocarousel" class="carousel slide" data-bs-ride="carousel">
    <div class="carousel-inner">
      <div class="carousel-item active c-item">
        <img src="https://placehold.co/600x400" class="d-block w-100 c-img" alt="...">
        <div class="carousel-caption mt-3 top-0 ">
          <p class=" dtext-uppercase text-center" id="caption-p">We&nbsp;Are</p>
          <h2 class="display-3 fw-bolder text-capitalize" id="caption-h2">Project Name</h2>
          <div>

            <a href="link-to-somewhere" target="_blank" class="btn btn-primary px-4 py-2 fs-5 mb-5" id="button">Book&nbsp;a&nbsp;Call</a>


          </div>
        </div>
      </div>
    </div>
</section>

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

jQuery tooltip anchored to the left side of the screen, ignoring all attempts to adjust its position

I have a jQuery tooltip that is supposed to hover over the table header, but it is displaying on the far left side of my screen with no formatting - just black text. I have attempted to use the placement and position jQuery attributes, but they do not seem ...

I incorporated a YouTube video using the iframe tag, but encountered an issue where the page would not scroll up or down when the mouse cursor was positioned on the iframe

How would you like your HTML code to function? When the cursor is on the iframe, do you want it to play a video? Also, should the parent page scroll when you scroll? <section class="section section-padding"> <div class="container"> ...

Implement responsive data tables by setting a specific class for hiding columns

Having trouble assigning a specific class name to individual columns in datatables? It seems that when columns are hidden using the responsive extension, the desired class is not applied. Looking for a solution or workaround. Check out this example from D ...

When I set margin-top to auto to move the last item in the list to the bottom, the item ends up being clipped

I have a sidebar with 100% height that includes a div and a ul. The div will display an image at the top of the sidebar, while the ul will contain all the sidebar menu items. It is crucial that the div and ul remain separate and not combined. The challeng ...

Mobile Device Centering Problem with Bootstrap Cards

Despite my thorough research efforts, I have been unable to find a solution. The code snippet below is meant to display the image provided, but it seems to shift to the left when viewed on a mobile device. If anyone can assist me with this issue, I would ...

Increase visibility, decrease visibility by utilizing ng-hide/ng-show and functions

As I implement the show more/show less feature, I am uncertain if achieving a smooth effect is feasible. However, I believe it's worth reaching out to this community for some creative ideas on how to make it possible. I have a list of dynamic links w ...

Adding a div element to the canvas and generating a DataURL is currently experiencing technical difficulties

My task involves displaying an image with two div elements placed above it - one containing an image and the other containing text. I need to combine these three elements to create a final image and store it in a database/server. To achieve this, I am usin ...

Code that achieves the same functionality but does not rely on the

I utilized a tutorial to obtain the ajax code below. The tutorial referenced the library jquery.form.js. Here is the code snippet provided: function onsuccess(response,status){ $("#onsuccessmsg").html(response); alert(response); } $("# ...

What is the best way to display a bitmap image in a Div, Span, Label, etc. on an Asp.Net page without using a Handler?

I am looking to display a bitmap image within a Div element using code behind. I prefer not to use a handler for this task. Here is an example of what I would like to achieve: div.InnerHtml = BitmapImage; ...

Reposition buttons using JavaScript

I attempted to modify the button that appears at the top of an HTML page. <div class='play'> <input id="play" type="button" value="Play" onclick="mode('play');startSlideshow();" /> </div> <div class='pause ...

Using Android to Load HTML Content from a Database and Display in a WebView

I am currently facing an issue with loading HTML content from my sqlite database into a webview successfully. The HTML renders beautifully, however, the local file included in the HTML is not being loaded. I have placed it in the assets folder under this s ...

A guide to retrieving all image URLs when a checkbox is selected using Javascript

My goal is to extract only image URLs from the concatenated values of price and picture URL. However, when I check different images using checkboxes, it always displays the URL of the first selected image. When I try to split the value, all the prices and ...

Issue with CSS causing dropdown to open underneath modal

I am facing an issue with my bootstrap modal that contains multiple dropdowns. To accommodate the content, I have set overflow: auto to enable a scroll bar on the right side of the modal. The problem arises when I click on a dropdown - it opens under the ...

Problem with CSS animations in IE10

I've encountered a problem with a specific section of a website I created. This section functions perfectly on all browsers and older versions of Internet Explorer, but not on the latest versions. It seems that IE no longer supports [IF] statements in ...

Adjust the color of the border surrounding the icon within a button

Is there a way to customize the color border of an SVG icon within a button to match the text of the button? My code snippet can be found on JSFiddle, along with my usage of Bootstrap: JSFiddle @import 'https://maxcdn.bootstrapcdn.com/bootstrap/4 ...

Issue with Navigation bar: Bootstrap menu fails to open upon clicking

My Bootstrap menu is experiencing an issue where it fails to open when I click on it. This means that I can't see any items in the menu. However, when I press the "Down key" on my keyboard, it opens immediately. This issue seems to occur specifically ...

Having trouble loading the URL into an iframe using angularJS

With AngularJS, I am attempting to dynamically load the URL address "myLink" into an iframe in another HTML file. The data.No variable is obtained from elsewhere and functions correctly (providing the necessary ID for the URL). In the controller - "Transa ...

I would like to give the option for file uploads, but the form refuses to submit unless a file is uploaded

I've recently developed a form in React and React Bootstrap, and I've encountered an issue with the file upload feature. I want the file upload to be optional, but when I try to submit the form without uploading a file, it doesn't work as ex ...

Exploring ways to customize the input color of Material UI TextField when it is disabled [Version: 5.0.8]

I am having trouble changing the border color and text color when an input is disabled. I have tried multiple variations, as seen below: const textFieldStyle = { '& label': { color: darkMode?'#1976d2':'', } ...

The fillOpacity and opacity properties appear to be malfunctioning

Note: While I understand that image masking can solve my issue, I prefer not to use it as it would require me to use my image as a background and could present accessibility challenges. I am specifically looking for solutions involving clip-path. Issue: T ...