Can you place an image (.png) on top of a button and still make the button clickable?
Can you place an image (.png) on top of a button and still make the button clickable?
Utilizing the z-index
property allows you to effectively control the stacking order of elements:
button.btn-class {
z-index: 999;
}
NOTE - Be sure to set the image's z-index
to a value lower than 999 as shown above!
Check out this helpful resource: https://css-tricks.com/almanac/properties/z/z-index/
It was mentioned in the comments that without adjusting the z-index
of the image (which is not an option), the only solution is to disable pointer events on the image.
img {
pointer-events:none;
}
Support is available in all modern browsers except for IE11
Below is a simple demonstration:
body {
margin: 0;
padding: 0;
}
div {
height: 400px;
display: flex;
flex-direction: column;
}
button {
align-self: flex-start;
}
img {
opacity: 0.5;
position: relative;
top: -1em;
margin-left: 2em;
border: 1px solid red;
pointer-events: none;
}
<div>
<button>Click Me</button>
<img src="http://lorempixel.com/g/400/200/" alt="" />
</div>
To ensure the button appears above the image, set a higher z-index value for the button than the image. You can find more information on this topic by visiting the following link
img{z-index:5;}
button{z-index:10;}
The z-index rule in CSS will only have an effect on elements with a specified position (such as position:absolute, position:relative, or position:fixed)
Here is an example of how to use it:
.imgclass {
position: relative; //you can also use position:fixed
z-index: -1;
}
.buttonclass {
position: relative;
z-index: 999;
}
When I am working in a view, I encounter an issue where I need to retrieve the value of an HTML input box after it has been changed. Initially, the page loads with the following code: <input id="input_one" type="text" value = "apple" /> Upon loadin ...
I'm currently working on incorporating a frame into a CSS modal, but the current display is not quite ideal. Additionally, I manually adjusted the frame's position (top and left), which is causing misalignment issues for different screen sizes, r ...
On my homepage, I have a large header image that is responsive in the mobile version. However, I am having trouble managing the spacing between the button and text below it. The spacing varies on different mobile screens and sometimes appears larger than i ...
I currently have a variable number of floating divs, ranging from 1 to 10. When I display either 1-5 or all 10, they appear correctly: item1 item2 item3 item4 item5 item6 item7 item8 item9 item10 However, when I try to display around 7 of them, things s ...
As a newcomer to streamlit, I am experimenting with creating an application that incorporates multiple tag objects. By default, the tags are displayed in red, but I would like to customize the colors for each tag based on its category. For example, I want ...
My HTML table has nested tables, but the border collapse property is not working. Despite adding the border-collapse property to both the main table and nested tables, only the outer borders are visible, with no inside borders. <table style="bord ...
I have a div tag enclosed within a content tag due to the implementation of a masterpage containing the forms and body tags. <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server"> <div id="xxx" style="overflow:s ...
I'm sorry for reaching out here instead of Google's forums, but I haven't had any luck finding answers there. Currently, I have a domain verified on Google Apps by uploading an HTML file, which is being used for email services. I don' ...
Feel free to modify the title! New and Improved!!! This is main.php $(document).ready(function(e) { $("#searchForm").submit(function(e) { e.preventDefault(); $("#result").load("process_search.php",{"searchKeyID":$("# ...
In my current project, I have set up a JavaScript object within a script tag. <script> searchdata = {"employees":[{"name":"john doe","sal": "10000"}]}; </script> I am utilizing the searchdata object in various functions as shown below: fu ...
Need some help troubleshooting why my code is causing IE to crash. After commenting out sections, I discovered that the issue arises when using .addClass and/or .removeClass inside the if conditions: if ( percentExpenses > 50 && percentExpenses ...
When updating your personal details on , you are required to choose your country first. Once the country is selected, the system automatically adjusts the city and/or state options based on that specific country's requirements. Can someone provide exa ...
Can anyone provide a jQuery code for validating the following HTML structure (view it on Jsbin)? HTML: <p id="options"> <strong>Options:</strong> <span> <input type="checkbox" name="ids" value="101" id="opcao-0"> <lab ...
I'm experiencing an issue with this error. I created a favicon parser from URLs using the following code: public class FavIconParser { public static String extractUrl(String url) { StringBuffer sb = new StringBuffer(); Pattern p = Pattern.co ...
Utilizing a standard asp.net menu in an asp.net 4.0 web application, this setup is for a standard web application and not any version of MVC applications currently available. The issue at hand is relatively straightforward. CSS styles are applied to the d ...
I need to show only the last four digits of the SSN and mask the rest with asterisks, like: ****-**-7654 Additionally, I want to implement a toggle functionality where users can reveal or hide the masked characters behind the asterisks. <in ...
Below is the code fragment that I currently have: <html> <script type="text/javascript"> function Run() {var a=["ONE" ,"TWO" ,"THREE", "FOUR", "FIVE"]; window.location.href = "index.php?w1=" +a;} </script> <body> <input type="b ...
Currently, I am in the process of developing a web application using Angular 6. In order to implement a customizable combo-box, I integrated the bootstrap-select library developed by Silvio Mureto into my project. However, I have encountered an issue with ...
While browsing the internet, I came across several examples of horizontal sliders with adjustable values. For example, if I set the maximum value as 100 and move the slider 10 sectors to the left, each sector would decrease by 10. What I am trying to ach ...
As a newcomer to PHP and MySQL, I am still learning the ropes. My goal is to extract data from the database and organize it into different divs based on unique IDs. For instance, div assigned to ID 1 will display the corresponding entry, div with ID 2 will ...