An easy way to incorporate an image into an HTML button

Is there a way to add an image on a button? I've been attempting to create a banner-like element for a large button, but the image doesn't seem to integrate inside the button as desired. I aim to have the image contained within the button without them appearing separate from each other.

Below is the HTML code provided:

<!DOCTYPE html>
<html lang='en'>

<head>
  <meta charset='UTF-8'>
  <meta name='viewport' content='width=device-width, initial-scale=1.0'>
  <title>Saharsh | Projects</title>
  
  <link rel='stylesheet' href='/Styles/projects.css'>
  <link rel='stylesheet' href='../style.css'>
  <script src='https://kit.fontawesome.com/a076d05399.js' crossorigin='anonymous'></script>

  <link rel='icon' type='image/x-icon' href='/Images/Branding/pfp.png'>
</head>

<body class='container'>
  <div id='home'>
    <nav class='navbar'>
      <ul>
        <li><a href='../index.html'>Home</a></li>
        <li><a href='#aboutMe'>About me</a></li>
        <li><a href='#moreSoon'>Contact me</a></li>
      </ul>
    </nav>
  </div>

    <br class='us'><br class='us'><br class='us'>
    <br class='us'><br class='us'><br class='us'>
    <br class='us'>

  <div>
    <h1 class='main'>My Projects</h1>
  </div>
    
  <br class='us'><br class='us'><br class='us'>
  <br class='us'>
  
  <div>
    <a href='#aboutMe'><img src='../Images/Projects/Modular-FPS.png' class='banner'><button class='project_button'>Modular FPS Template</button></img></a>
  </div>

  <br class='us'><br class='us'><br class='us'>
  <br class='us'><br class='us'><br class='us'>

  <div>
    <h1 id='moreSoon' style='text-align: center;'>
      <a href='https://github.com/Saharsh1223' target='_blank'><span class='icon_span'><img class='icon' src='/Images/Socials/github.svg'></span></a>
      <a href='https://discord.gg/bkP2P5uuH2' target='_blank'><span class='icon_span'><img class='icon' src='/Images/Socials/discord.svg'></span></a>
      <a href='https://youtube.com/SaharshDev' target='_blank'><span class='icon_span'><img class='icon' src='/Images/Socials/youtube.svg'></span></a>
      <a href='https://twitter.com/Saharsh1223' target='_blank'><span class='icon_span'><img class='icon' src='/Images/Socials/twitter.svg'></span></a>
    </h1>
  </div>

  <br class='us'>

  <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  <script src='Scripts/scrollSmooth.js'> </script>
  <!-- <script src='Scripts/i_am_a.js'> </script> -->
</body>

</html>

Furthermore, here is the CSS code provided:

@font-face {
  font-family: 'mainFont';
  src: url("../Fonts/Poppins/Poppins-Medium.ttf") format('truetype');
}

@font-face {
  font-family: 'descFont';
  src: url("../Fonts/Poppins/Poppins-Regular.ttf") format('truetype');
}

.project_button {
  font-family: 'descFont';
  font-weight: normal;
  font-style: normal; 

  background-color: #181818;
  border: none;
  color: white;
  /* padding: 20px; */

  text-decoration: none;
  display: inline-block;
  font-size: 18px;
  margin: 4px 6px;
  border-radius: 10px;

  cursor: pointer;

  width: 450px;
  height: 250px;

  box-shadow: 0px 16px 16px rgba(0,0,0,0.14);
  transition: 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.project_button:hover {
  transform: scale(1.03);
}

.banner {
  width: 350px;
  height: 190px;
}

Thank you in advance!

Answer №1

Here is a tip for you:

<button class='project_button'>Check out the Modular FPS Template <img src='../Images/Projects/Modular-FPS.png' /></button>

Make sure to nest your image within the button tag.

Answer №2

If you want to open a new window when clicking on an image, you can use the onClick event in the img tag:

<img onClick="window.open("https://example.com")" />

Answer №3

Give this a try. Much appreciated.

<!DOCTYPE html>
<html>
<body>

<h2>HTML Image</h2>
<button><img src="image.jpg" alt="No Image" width="50" height="30"></button>


</body>
</html>

Answer №4

To achieve this, utilize a form and incorporate an input element with the type attribute set to "image", as shown in the following example:

<input type="image" id="myimage" src="[...]" />

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

How can I ensure that the images span the entire width of the page in ResponsiveSlides?

I am trying to make my images occupy the entire width of the page just like in this example: However, I have not been able to find a property for this. I'm new to using Jquery but I have a good understanding of Javascript Can someone please help me ...

Tips for designing a flexible structure with 2 columns, each containing an additional 2 columns within

Is it possible to create a 4-column responsive layout? | column left | column right | column left| column right| I would like to achieve a single row layout on larger devices as shown below | column left | column right | column left| column right| an ...

What is the proper way to format lengthy lines in Twig templates while adhering to coding standards?

In my templates, I have the following code snippet for generating routes with parameters: <a class="btn btn-block btn-abcd" href="{{ path( 'auth.login', { 'type': constant('User::TYPE_CANDIDATE'), & ...

What could be causing the malfunction of my Superfish menu in Firefox?

I am currently experimenting with the Superfish jQuery plugin to improve a drop-down menu on my website. Unfortunately, in Firefox browser (v. 21.0), the drop-down menu does not open when hovering over it as expected. However, it works fine in Chrome and O ...

Is there a potential bug in Chrome with the submit button appearing "depressed" when focused?

Why do submit buttons act differently in Chrome? <input type='text' placeholder='Dummy Input'/> <input type='submit'/> In Chrome, the active 'depressed' state of the submit button will only occur if the ...

Is it possible to switch variations in WP-Commerce from drop-down menus to text input

Currently exploring ways to customize the size variations on an e-commerce website similar to Using WP Commerce, the size variations are originally displayed in select fields by default. <select class="wpsc_select_variation ...

Looking for some help with tweaking this script - it's so close to working perfectly! The images are supposed to show up while

Hey everyone, I'm struggling with a script issue! I currently have a gallery of images where the opacity is set to 0 in my CSS. I want these images to become visible when scrolling down (on view). In this script, I have specified that they should app ...

Can you explain the purpose of using the "overlay" value in the "overflow" property?

Can someone please clarify the distinction between "overlay" and "auto" for me? Is the function of "overlay" similar to that of "auto"? ...

What is the best way to display a single instance of a React component that is declared in multiple locations within the app?

Imagine I have 2 main components, A and B. Now, component C needs to be created inside both A and B. How can I guarantee that the same exact instance of C is generated in both places? Essentially, I want them to stay synchronized - any changes made to one ...

What is the best way to create a percentage glyphicon star icon that reflects a decimal average rating?

I have an average rating of 4.3 and I need to create a logic to display this as 4.3 stars (4 whole stars and the 5th star partially filled). The maximum rating is out of 5. Despite referring to examples on Stack Overflow and creating a JSFiddle, I am unabl ...

Adjusting input height with CSS in Google Chrome

When I define an input element with the following CSS properties: input { border: none; font-family: arial, sans-serif; font-size: 16px; line-height: 16px; padding: 0; } I anticipate the height of the input to be 16px, however, upon inspecting ...

Challenges arise with the safari navigation bar within a PWA platform

Struggling with the formatting and spacing issues of a PWA application on IOS devices due to notches and navbar heights. One specific problem is that a chat input with absolute positioning and bottom: 0 does not display properly in Safari because of the n ...

Resizing cell height in an HTML table is not supported by Angular 5

In my angular application, I've implemented a component that represents a basic HTML table. However, I'm facing an issue with reducing the height of cells within the table. It seems like my CSS styling is not affecting the display as desired. He ...

Utilize CSHTML Script to Show HTML Content When SQL Query Results in Null

I have a CSHTML Script that a friend has written, and I am currently making some changes to it. I have a SQL Query saved as a variable and if this query returns NULL, then I want to display different HTML compared to when it returns results. Below are the ...

What is the most efficient method for transferring ASP.NET form data to an Excel spreadsheet?

I am confident that exporting data from my web form should be achievable, but I'm not quite sure of the steps involved. My web form contains numerous select dropdowns and input boxes. Could anyone guide me on how to export the data from these asp co ...

I need to access a webpage using VBA without relying on Internet Explorer for logging in

I need to access the website by logging in. However, I am facing difficulty in using it. Unfortunately, I am unable to share the username and password due to confidentiality reasons. Below is the code snippet that I have: Sub checkdownload() Dim u ...

Performing calculations using jQuery and organizing sub-totals into groups

I am currently developing a web application and aiming to incorporate an invoice calculation feature with sub-groups. My goal is to have the total result of both group-totals and sub-totals at the end. Here is my progress so far: Check it out here $(func ...

Store <td> in a variable

At the moment, I have a script that allows users to input an item name, along with its size, color, and other options. Each of these entries is saved as individual items with their custom specifications, such as a black t-shirt in large size. The script c ...

Dealing with problematic hover behaviors in Cypress: A guide

I encountered an issue with Cypress hover functionality while trying to access a sub menu that appears after hovering over a main menu item. The error message I received was This element is not visible because it has CSS property: position: fixed and it&ap ...

Revamping Slideshows: Bringing CSS Animation to JavaScript

/* JavaScript */ var slides=0; var array=new Array('background.jpg','banner.jpg','image.jpg'); var length=array.length-1; $(document).ready( function(){ setInterval(function(){ slides++; ...