Button remains behind the image, not moving to the front

I have placed my button on the image, but I want it to sit on top of the image. However, the z-index: 1; property is not working as expected. I have tried all possible position attributes to see if it works, but there was no change. I also added z-index to all the CSS code below, but nothing seems to be working. I even searched the internet, including YouTube, and tried various methods, but none of them seem to solve the issue.

Below is my HTML code:

a .play {
  background: steelblue;
  border-radius: 50% / 10%;
  color: #FFFFFF;
  font-size: 2em;
  height: 3em;
  margin-top: -350px;
  float: right;
  margin-right: 10px;
  margin-top: 25px;
  padding: 0;
  position: relative;
  z-index: 1;
  text-align: center;
  text-indent: 0.1em;
  transition: all 150ms ease-out;
  width: 4em;
}

a .play:hover {
  background: #ff0000;
}

a .play::before {
  background: inherit;
  border-radius: 5% / 50%;
  bottom: 9%;
  content: "";
  left: -5%;
  position: absolute;
  right: -5%;
  top: 9%;
}

a .play::after {
  border-style: solid;
  border-width: 1em 0 1em 1.732em;
  border-color: transparent transparent transparent rgba(255, 255, 255, 0.75);
  content: ' ';
  font-size: 0.75em;
  height: 0;
  margin: -1em 0 0 -0.75em;
  top: 50%;
  position: absolute;
  width: 0;
}
<div id="index-gallery">
  <div class="item">
    <img src="img/after.jpg" alt="" width="300px" />
    <p>My Caption here</p>
    <a href="#">
      <div class="play"></div>
    </a>
  </div>
  <div class="item2">
    <img src="img/after.jpg" alt="" width="300px" />
    <p>My Caption here</p>
    <a href="#">
      <div class="play2"></div>
    </a>
  </div>
  <div class="item3">
    <img src="img/after.jpg" alt="" width="300px" />
    <p>My Caption here</p>
    <a href="#">
      <div class="play3"></div>
    </a>
  </div>
  <div class="item4">
    <img src="img/after.jpg" alt="" width="300px" />
    <p>My Caption here</p>
    <a href="#">
      <div class="play4"></div>
    </a>
  </div>
</div>

Answer №1

Give this a shot:

div.item {
    position: relative;
}

a.button-wrapper {
    display: block;
    height: 100px;
    position: absolute;
    top: 16px;
    left: 80px;
}

a .play {
    background: steelblue;
    border-radius: 50% / 10%;
    color: #FFFFFF;
    font-size: 2em;
    height: 3em;
    float: left;
    margin-right: 10px;
    margin-top: 0;
    padding: 0;
    position: relative;
    z-index: 1;
    text-align: center;
    text-indent: 0.1em;
    transition: all 150ms ease-out;
    width: 4em;
}

a .play:hover {
    background: #ff0000;
}

a .play::before {
    background: inherit;
    border-radius: 5% / 50%;
    bottom: 9%;
    content: "";
    left: -5%;
    position: absolute;
    right: -5%;
    top: 9%;
}

a .play::after {
    border-style: solid;
    border-width: 1em 0 1em 1.732em;
    border-color: transparent transparent transparent rgba(255, 255, 255, 0.75);
    content: ' ';
    font-size: 0.75em;
    height: 0;
    margin: -1em 0 0 -0.75em;
    top: 50%;
    position: absolute;
    width: 0;
}
<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
  <div id="index-gallery">
    <div class="item">
      <img src="https://via.placeholder.com/350x150" alt="" width="300px" />
      <p>My Caption here</p>
      <a href="#" class="button-wrapper">
        <div class="play"></div>
      </a>
    </div>
    <div class="item">
      <img src="https://via.placeholder.com/350x150" alt="" width="300px" />
      <p>My Caption here</p>
      <a href="#" class="button-wrapper">
        <div class="play"></div>
      </a>
    </div>
    <div class="item">
      <img src="https://via.placeholder.com/350x150" alt="" width="300px" />
      <p>My Caption here</p>
      <a href="#" class="button-wrapper">
        <div class="play"></div>
      </a>
    </div>
    <div class="item">
      <img src="https://via.placeholder.com/350x150" alt="" width="300px" />
      <p>My Caption here</p>
      <a href="#" class="button-wrapper">
        <div class="play"></div>
      </a>
    </div>
</body>
</html>

Answer №2

It seems like you're interested in adding an image as the background for your <p> and <a> tags. One approach to achieve this is by creating a wrapping div with a class like item that includes a

background-image:url(<enter image url here>)
attribute in the CSS.

Here's an example:

HTML:

<div class='item'>
    <p>My Caption here</p>
    <a href='#'>
        <div class='play'>
    </a>
</div>

CSS:

.item {
    background-image : url('./example-image.png');
}

insert 
other 
css 
code  
here
...

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

Utilize the DataTables plugin to arrange a column based on icons with hidden boolean values in rows

I am currently utilizing the DataTables plugin to enhance my HTML table. While I have managed to successfully implement most functionalities, I am facing a challenge with the boolean column. This particular column consists of icons representing X (value 0) ...

Is it possible for images to align vertically instead of horizontally in IE?

Encountering an issue with image alignment in Internet Explorer - they are aligning vertically instead of horizontally, while functioning correctly in all other browsers. Moreover, in IE8 and 7, the images are not being displayed at all. Is there a workaro ...

Comparing v-show(true/false) and replaceWith: Exploring the best practice between Vue and jQuery

Currently, I am in the process of learning vue.js and have a question regarding the best approach to implement the following scenario: https://i.sstatic.net/2YBEF.png https://i.sstatic.net/YCEHG.png The main query is whether it is acceptable in HTML to w ...

Creating a personalized design for MUI TextField spin button

Looking to customize the appearance of the up/down spin buttons in MUI TextField. https://i.sstatic.net/DcG66.png Desiring white arrows and a black surrounding area that's slightly larger, akin to this: https://i.sstatic.net/ZxMJw.png I'm aware ...

What could be causing my THREE.js Documentation Box to malfunction?

I am a newcomer trying to get the hang of THREE.js. I delved into the THREE.js Documentation and attempted to implement the code, but when I loaded my HTML page, it appeared blank. I am at a loss for what to do next. I utilized Visual Studio Code for codin ...

Region Covered by Mouse Over Does Not Extend Across Whole Div

On my website, there is an arrow located on the middle right side that, when hovered over with the mouse, reveals a sidebar. Clicking on each icon in the sidebar further extends it to reveal more content. However, the issue I am facing is that the sidebar ...

Retrieve JSON data within an HTML element, where the element is sourced from an AJAX GET response

What is the best way to extract JSON data from the response below? $.get('http://localhost:8000/json', function(response) { alert(response); }); The response is as follows: <div id="dom-target" style="display: none;"> {"logo":"log ...

What is the best way to position text below an image icon in a menu?

I am having trouble creating a menu that has the same style as shown in this image: . Unfortunately, my menu ends up looking like this instead: . Can someone please help me fix this issue? Here is the HTML code I am working with: <header> ...

A step-by-step guide on using Jquery to fade out a single button

My array of options is laid out in a row of buttons: <div class="console_row1"> <button class="button">TOFU</button> <button class="button">BEANS</button> <button class="button">RIC ...

Writing the success function for a jQuery ajax call involves defining the actions to be taken once

Embarking on my journey to learn jQuery and web development, I am faced with the task of sending user input (username and password through a submit button) to a PHP page using .ajax and success function. Below is the HTML form code: <form id="form1"&g ...

Having issues with AngularJS where ng-table/ng-repeat rows are failing to load properly

I've been following a tutorial on using ng-Table, which can be found Here. When I download the example from Git, it loads without any issues. However, when I try to replicate even the simplest example myself, the column headers and filters load but th ...

Steps to incorporate a session into an HTML login form

Need assistance with adding a session to my HTML form connected to MySQL database. The database updates whenever the page is reloaded or when a failed submission occurs. Can anyone provide a solution for this? <body> <?php // define variables a ...

Can certain parts of an MP4 file be accessed remotely through a network connection?

With modern MP4 players, you have the ability to skip to any part of a video without needing to download the entire file. Take a look at this example video: You can navigate to any point in the video before it finishes downloading. I am curious if there ...

What is the best way to position the hamburger menu icon on the right side of the header?

I need some assistance with adjusting the position of my mobile hamburger menu icon. It's currently on the left side of the screen, but I want to move it to the right. I've tried making the changes myself using CSS and HTML, but I'm not an e ...

Elements separated by empty space on a Complex Grid, appearing distant despite the available space

Struggling with creating a complex layout using minimal relative and absolute positioning. Here's the issue I'm facing: All my elements are aligned side by side with only one problem: the border image needs to bleed into the row below. How can t ...

Increase the dropdown size without altering the dimensions of the container

I have a dropdown menu enclosed in a div with a vibrant yellow background. Take a look at the code on Plunker here. Upon clicking the dropdown button, the list expands and the container's height increases as well. The background color of the dropdown ...

Sprockets could not locate the file for jquery.atwho

I have been attempting to integrate the jquery-atwho-rails into my application, a Rails gem designed for at.js. I have followed all the steps provided, executed bundle install, included the necessary code in both application.js and application.css, stopped ...

Implementing PHP code in HTML file

Is there a way to utilize PHP in order to make changes to an HTML file on a website? To clarify, I am looking to create a PHP file with input boxes that can append to a list in an HTML file. For example, the admin.php file will update the index.html file ...

Build a home page in HTML with full width design

My webpage currently allows scrolling to the right and left in HTML. I would like to change this functionality. What I envision is having my cup and book visible without the need for scrolling, with a background image centered on the page. <div cla ...

Can the lazy load script dependent on jQuery be utilized before the jquery.js script tag in the footer?

After receiving HTML from an AJAX callback, I noticed that there is a script tag for loading code that uses jQuery. However, I consistently encounter the error of jQuery being undefined. All scripts are connected before the closing </body> tag. Is ...