Display text on top of an image using HTML

I'm having trouble creating a submit button for my form that includes both an image and text. I've tried multiple methods, but encountered some issues. Here's the HTML code:

<form action="www.page.html" method="post>
some text
<span>Check The Page</span>
<input type="image" src="check.png" name="Check" alt="Check" width="161" height="30">

This is my CSS:

#reservation span{
display: inline-block;
z-index: 100;
}

#reservation input{
margin-top: -30px;
z-index: -100;
}

The problem is that the z-index property isn't working as expected, causing the picture to overlap the text. I then attempted another approach using a div element. Here's the HTML code for that:

<form action="www.page.html" method="post>
some text
<input type="submit" id="image-button">Check The Page </input>
    <div class="check">
      <input type="image" src="check.png" name="Check">       
  <span>Check</span>
</div>

And here's the CSS for this method:

.check { 
   margin-left: 10px;
   position: relative; 
   width: 100%; /* for IE 6 */
}

.check span { 
   position: absolute; 
   left: 0; 
   margin-top: 5px;
   margin-left: 10px;
   color: #ffffff;
   font-family: Calibri;
   font-size: 16px;
   font-weight: bold;
   font-style: italic;
   text-shadow: #222222 1px 1px 0;
   width: 100%; 
}

While this solution makes the image and text display nicely together, only the sides of the button are functional as links within the form. The middle portion behaves like a text layer. Can anyone offer assistance with this issue? :)

Answer №1

#icon-button
{
    background-image: url('tick.png');
    background-position: center;
    background-repeat: no-repeat;
    background-color: transparent;
    border: 1px solid black;
    width: 200px;
    height: 40px;
    text-align: center;
}

<input type="submit" id="icon-button" value="Mark as Complete" /> 

Adjust the background position, dimensions of the button, and alignment of the text to achieve the desired layout, but this setup should achieve the intended result.

Answer №2

<input type="submit" value="Verify Page" id="image-button" style="background-image:url(check.png);height:200px;width:200px;" ></input>  

Adjust the height and width to match the dimensions of check.png.. Alternatively, for a fixed button size with stretched image, include 'background-size:100%' in the CSS properties. :)

Answer №3

<button type="submit">
<img src="check.png" alt="Check"/>
<br/>
Verify The Content
</button>

To overlay text on an image, you can use the following code and adjust the values for left and top accordingly. I must mention that I am not completely satisfied with this code, my preferred alternative would be to edit the image itself and include the text within it if the text doesn't need to be changed frequently.

<button type="submit">
<img src="demo.png" alt="Check"/>
<span style="position: absolute; left: 20px; top: 16px;">Verify The Content</span>
</button>

Answer №4

Give this a shot:

<input type="submit" value="Visit The Site" id="button-image" style="background-image:url(visit.png);height:400px;width:400px;" ></input>

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

Incorporating an image into a list of checkboxes post-connection

Looking for a way to populate a checkbox list through datasource/databind and then integrate an image with each checkbox? I can do both separately but struggling to combine them successfully. My task is to create a checkbox list of students for teachers t ...

Angular 8 dropdown menu that closes when clicking outside of it

Hello, I am currently using the click function on the p tag. When a user opens the dropdown menu, I want to close it when they click outside of it in Angular. Here is the HTML code: <div class="select_cat"> <p class="cat_name" (click)="openC ...

A dynamic jQuery plugin that replicates the smooth page sliding animation found in iPhone apps

Currently, I am in search of a jQuery plugin that has the capability to navigate users to different pages on a website with a sleek sliding animation, similar to what we see in some widely used iPhone apps. Despite my best efforts to create this functional ...

Altering the hue within text/typography

While I may not be a professional web developer, I've successfully created an HTML5 and CSS3 website by piecing together information from various tutorials and conducting Google searches to hack code. My website aims to showcase environmental data in ...

Change a variable on the fly without needing to reload the page

<!DOCTYPE html> <!-- To update your slot machine images without refreshing the page, you can use JavaScript to dynamically change the images on click. Here's a simple example using JavaScript: <html> <head> <title& ...

Arranging elements within distinct div containers

Utilizing Bootstrap 4, I crafted a card-deck containing two cards. Despite the equal height of both cards, the alignment of elements is affected by varying text lengths. <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min ...

Tips for combining data within an array in a PHPExcel report

Looking to concatenate my array values in order to generate a PHPexcel report in Excel, but struggling to make it work. Can anyone offer assistance with this issue? Here's a visual representation of the desired outcome: "Buenavista, Agusan del Norte" ...

I wonder where this design is originating from

After exploring several of the suggested questions that appeared while typing, I was unable to find a solution to my issue. Currently, I am utilizing Uikit V2 and I have implemented a div with the Sticky component as shown below: <div class="uk-st ...

The error message "removeClass is not a valid function" appeared on the

When I am attempting to eliminate a class using eq(), it is not effective and an error occurs in the console displaying TypeError: $(...).removeclass is not a function $("table tr:eq(9)").removeclass('mandatory');**strong text** html code: &l ...

What is the process for transforming information from a database into a clickable hyperlink?

My course list includes the following: SE1111 SE2222 SE3333 I want to display this list on my webpage and have it redirect to a page where the course name is saved for future use. Here's what I've tried so far: <div id="join_courses" clas ...

Enrich an HTML table using jQuery based on an indentation pattern

                 Overview: Currently, my colleague and I are working on developing an inventory control system using the Django Framework within our department. While most aspects of the system are operational, we are encountering ...

Difficulty switching back and forth between three varying heights

I have a container with a button labeled "Show more". Upon clicking the button, the height of the container will transition through 3 different states. <div class="segment-suggestion-content height-small"> <div class="segment-suggestion-sh ...

Prevent IonContent from scrolling to the bottom or top when using Ionic framework

In my Ionic app, I have a long text page with 2 buttons that trigger the actions scrollToBottom and scrollToTop. Due to the length of the page, I have set the scroll duration to be 30 seconds. I am facing two issues here: How can I stop the scrolling ...

Regular expressions used to efficiently parse CSS selectors

I am looking to enhance the scope of my selectors. One effective method, in my opinion, is to target a CSS selector and return a combination of mySelector and oldSelector For instance, if I have .old { background: black; }, I would modify it to .mySelecto ...

Every time a new message is sent or received, I am automatically brought back to the top of the screen on the

I'm currently working on integrating a chat feature into my Angular Firestore and Firebase app. Everything seems to be functioning well, except for one issue - whenever a new message is sent or received, the screen automatically scrolls up and gets st ...

Is there a way to change the color of a specific tab without affecting the content within it

I am attempting to change the color of an individual tab using jQuery. However, when I set the background attribute in CSS, it colors the entire background instead. What specific property should I be setting to only change the color of the tab itself? ...

React and SASS - issue with checkbox component not being properly aligned with its label

I'm brand new to React and I'm currently in the process of converting a pure HTML page into a React component. How can I adjust the SASS stylesheet to match the original HTML layout? Here is my current React setup (the checkbox displays on the r ...

Can you please provide guidance on implementing automatic horizontal scrolling with pauses between each div?

setInterval(function scroll() { $(".box_auto").each(function(i, e) { $("html, body").animate({ scrollTop: $(e).offset().top }, 500).delay(500); }); setTimeout(function() { $('html, body').animate({ scrollTop: 0 } ...

Spotlight a newly generated element produced by the*ngFor directive within Angular 2

In my application, I have a collection of words that are displayed or hidden using *ngFor based on their 'hidden' property. You can view the example on Plunker. The issue arises when the word list becomes extensive, making it challenging to ide ...

Hiding content in HTML with the Display:none property

After exploring various posts on this topic, I am still unable to find a solution that fits my specific scenario. Despite the challenges, I thought it would be worth asking for recommendations. Currently, I have a PowerShell script generating a report in ...