What is the best way to create a clickable button using HTML and CSS? The button should be centered on top of an image with a title

I'm in the process of creating a button overlay on an image that directs to another page within the same site. I don't have much experience with coding, but with some online resources, I was able to piece together what I needed. The issue I'm facing is making the button clickable and figuring out where to place the code that will link to the target page. Here's the current HTML markup:

<div class="albumimagewrap">
<img src="https://static1.squarespace.com/static/55d3ad3ee4b0adc8c326fe3f/t/57967922e6f2e14eefb8c308/1469479203582/Artboard+1.png?format=1000w" width="100%" height="100%">

<input type="h1" class="albumtitleimg" value="INNER CIRCLE">
<input type="p" class="albumtextimg" value="Debut Album Available Now">
<button class="albumbutton1">LISTEN</button>
</div>

And here's the relevant CSS styling:

.albumimagewrap {
position:relative;left:0;top:0;
width: 100%;
height: 100%;
padding-top:0%
}

.albumtitleimg {
display: block;
position:absolute;
margin: auto;
width: 250px;
top:20%;right:0%;left:0%;
text-align: center;
font-size: 25px;
color:#ffffff;
background-color:transparent;
border: 0px;
}

.albumtextimg {
display: block;
position:absolute;
margin:auto;
width: 250px;
top:40%;right:0%;left:0%;
text-align: center;
font-size: 14px;
color:#ffffff;
background-color:transparent;
border: 0px;
}

.albumbutton1 {
display: block;
position:absolute;
margin:auto;
top:60%;right:0%;left:0%;
width: 240px;
height: 50px;
text-align: center;
background-color:transparent;
color: #ffffff;
border: 2px solid #BD9F6C;
}

Unfortunately, I can't upload images as I'm new here, but you can view the image/button setup here.

Your help would be greatly appreciated!

Answer №1

When an element click triggers the loading of a new page, it's best to use an anchor tag. In your scenario, consider using the following code:

<a href="new-page.html" class="albumbutton1">
  <span>LISTEN</span>
</a>

Anchors naturally direct to new pages without the need for extra JavaScript.

To center the anchor text both vertically and horizontally, I implemented the following CSS:

.albumbutton1 span {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

Check out this demo: https://jsfiddle.net/mkwmsd2d/

Answer №2

When looking to incorporate an image as an input button, you can achieve this by implementing the following CSS:

.button {
  background-image: url('/image.png') no-repeat;
}

Answer №3

Instead of utilizing input elements, it is recommended to use h1, p, and a tags.

To create links that are clickable and direct users to other pages, you can utilize the a tag.

<div class="album">
  <h1>INNER CIRCLE</h1>
  <p>Debut Album Available Now</p>
  <a href="#">LISTEN</a>
</div>

All you have to do is replace the # with the specific URL you want the link to lead to.

For more information, visit: https://jsfiddle.net/gosh95zb/

Answer №4

Here's a simple solution: just set up a trigger on your button.

<input type="button" onclick="javascript:window.open('http://www.google.com.br');" class="albumbutton1" value="LISTEN">

Check out this example for more details: http://jsfiddle.net/xqc36Lht/

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 effects failing to run properly in Internet Explorer

<script type="text/javascript" src="css/jquery-1.7.1.js"></script> <script type="text/javascript"> function slidedown(id){ $('#rerooftext').hide(0); $('#inspectiontext').hide(0); $('#remodelingtext').hid ...

Creating a CSS rollover effect for your logo on a WordPress website

Struggling to implement a CSS image rollover on a Wordpress header logo. The solution may be simple for you experts, but I can't find it anywhere on Stackoverflow. Could it have something to do with the position? Adding :relative or :absolute doesn&ap ...

It is not possible to assign a unique name to the custom attr() method

The code provided by someone else is working perfectly fine. However, when I try to rename the attr method, for example to attrx, I encounter an error. The error message I receive after renaming the method is: TypeError: arg.attrx is not a function Below ...

What is causing my AJAX script to refresh the page repeatedly?

I am currently testing the functionality of submitting a form using ajax. The script I have in place is designed to echo some plain text in processform.php. However, when I click on the submit button, no alert is displayed and the page is reloaded instead. ...

Issues with properly triggering re-clicking events in AngularJS when using Bootstrap modal

I am currently utilizing Angular JS in combination with Bootstrap modal. Below is the Anchor link I am referring to: <li><a href="#" data-toggle="modal" data-target="#inviteFriendModal" ><span class="frndInvt"></span>Invite Friends ...

What is the difference between a CSS background image and a default background?

I am faced with a challenge concerning a div element that has both a background color and an image with a transparent background. My objective is to have the default background color of the div be white, while having a different color as the background fo ...

CSS photo display with magnification feature

I currently have a functioning inner-zoomable image set up with the code provided. I am interested in converting this setup into an image gallery with zoom capabilities for the selected image element, but I'm unsure where to start. My objective is to ...

Discreet elements are not functioning

It's frustrating that everything in the 'wrapper' won't stretch to fit properly, instead staying at a fixed height. I'm trying to make the 'sidebar' and 'content' inside the area have the same height at all time ...

What is the best way to assign different colors to rows in a SharePoint list on each individual page?

After following the instructions provided on this website, <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"> </script> <script type="text/javascript"> $(document).ready(function () { ...

jQuery - Effortless Step-by-Step Form

I'm a beginner with jQuery and I'm working on creating a basic 3-step form using jQuery. I've managed to hide the gray title, but I'm struggling to get the next step to display. Check out my jsFiddle JS: $('.js-next-step'). ...

Ensure that the Bootstrap 5 modal and backdrop are sized to fit the parent container's width and height rather than filling the entire screen

Is there a way to limit the size of a Bootstrap 5 modal dialog and backdrop? The example below occupies 100% of the screen, can it be adjusted to cover only the parent main container? <main class="container-fluid pt-4 px-4" style="height ...

Tips for creating a stylish navbar with a faded effect on the right side and integrating a fresh button into its design

I'm looking to enhance my Navbar by implementing a feature where, if the width of the Navbar exceeds that of its parent div, it will fade on the right side and a new button will be added - similar to what can be seen on Youtube. 1- When the Navbar&ap ...

Solution to trigger CSS :hover to refresh following a transition (such as expanding a menu)

While there are existing discussions on this topic, I am presenting my query for two specific reasons: It introduces a potential alternative solution The demo code could be helpful to individuals looking to emulate a menu Following a CSS transition, the ...

Display a div when hovering over it, with its position set from the bottom of the main

I am attempting to use CSS to display another div within my main div, but positioned from the bottom of the main div rather than as a block as I am currently testing with my code. HTML <div id="main"> <a href="#"><img src="https://www.g ...

You are unable to select the drop-down menu and radio button

I am having trouble with the radio button and drop-down arrow on my project. When I try to click on them, nothing happens. It seems like something is hidden but I can't figure out what it is. Could someone please assist me with this issue? If anyone ...

Using HTML, CSS, and JavaScript, the main tab must include nested subtabs to enhance navigation and

When a user clicks on a tab, another tab should open within the main tab. Depending on the selection in the second tab, input fields should appear while others hide. Something similar to the nested tabs on expedia.com. I have experimented with the tab vie ...

Removing CSS from an Ajax combobox

When using an Ajax Combobox, I encountered a problem with the background color changing on hover. The combobox is bound to a datasource with specific conditions for defining the background color, but upon hovering over a list item, the color changes. I wan ...

Guide on inserting a row into a table class without unique values using jQuery

I have gathered information on stackoverflow regarding how to use jQuery to add a row to a table. $('.myTable').find('tbody:last').append('WHATEVER CODE'); Although this method seems to be effective, I have come across the i ...

Streaming live video on the website

Hi there! I'm looking to integrate live video capturing into an HTML/JavaScript site for a presentation. However, I'm not sure where to start my search. Can anyone point me in the right direction? :) The live video will be captured by a camera o ...

I'm having trouble showing the concealed list with JavaScript

I am new to javascript and facing a challenge. Whenever I update the list items in an HTML example from engineer, pilot, technician, if I select engineer, there should be an onchange event calling a function in JavaScript that shows a hidden select list co ...