Is the z-index problem in Safari related to a transform issue?

I've tried different solutions for similar issues, but I'm struggling to get the text to appear properly on my custom buttons in Safari. They are displaying perfectly in Chrome and Firefox, but not on iOS devices.

Does anyone have any suggestions on how to make sure the text is on top of the background as intended?

HTML:

<a href="#" class="dark-button border">Register</a>
<a href="#" class="light-button border">Register</a>

CSS:

/* Hexagon Button Style */
.dark-button,
.light-button{
  position: relative;
  display: block;
  background: transparent;
  width: 280px;
  height: 48px;
  line-height: 46px;
  text-align: center;
  font-size: 16px;
  letter-spacing: 1.8px;
  text-decoration: none !important;
  text-transform: uppercase;
    font-weight:600;
  margin: 15px auto;
  font-family: Orbitron, Helvetica, sans-serif;
 
}
.dark-button:before,
.dark-button:after,
.light-button:before,
.light-button:after{
  position: absolute;
  content: '';
  width: 280px;
  left: 0px;
  height: 24px;
  z-index: -1;
}

.dark-button:before,
.light-button:before{
  transform: perspective(8px) rotateX(3deg);
}
.dark-button:after,
light-button:after{
  top: 24px;
  transform: perspective(8px) rotateX(-3deg);
}

/* Hex Button color styles */
.dark-button{
    color: #ffffff;
}
.light-button{
    color: #2c2a2b;
}
.dark-button.border:before,
.dark-button.border:after {
  background: #2c2a2b;
}
.light-button.border:before,
.light-button.border:after {
  background: #ededed;
}
/* Hex Button hover styles */
.dark-button.border:hover:before,
.dark-button.border:hover:after,
.light-button.border:hover:before,
.light-button-border:hover-after{
  background: #BDBDBD;
}
.dark-button.border:hover,
.light-button:hover{
  color: #ffffff;
}

>> Link to CodePen

Answer №1

It seems that the issue lies within the transforms mentioned in the question. When a non-null transform is applied, it can create a new stacking context. It's unclear why different browsers handle the collection of transforms differently.

Instead of using pseudo elements and transforms, consider using clip-path on the anchor element to achieve the desired appearance. This approach simplifies things in terms of stacking contexts.

The CSS provided below is for creating a green button, but the same concept applies to other buttons. Adjust the percentage settings on the clip path to achieve the desired pointed look.

/* Hexagon Button Style */


/* Green Button Style */

.green-button {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 180px;
  height: 48px;
  line-height: 38px;
  text-align: center;
  font-size: 14px;
  letter-spacing: 1.8px;
  text-decoration: none !important;
  text-transform: uppercase;
  font-weight: 600 !important;
  color: #ffffff;
  margin: 15px auto;
  font-family: Orbitron, Helvetica, sans-serif;
  clip-path: polygon(10% 0, 90% 0, 100% 50%, 90% 100%, 10% 100%, 0 50%);
  background-color: #4f9f45;
}

.green-button:hover {
  color: #ffffff;
}
<a href="#" class="green-button border">Register</a>

Note: Clip-path may not be supported on IE, so users might see a rectangular button if using IE.

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

The iPad Overlay fails to fully extend across the screen

I have implemented a modal div as an overlay to disable the background page while the overlay DIV is open. Below is the code I am using: #TB_overlay { height: 100%; left: 0; position: fixed; top: 0; width: 100%; z-index: 100; } Al ...

Is there a way to have a fixed width div positioned in the center of the screen, with two additional divs on either side

I have come across this stunning image: https://i.stack.imgur.com/tUYMc.png It serves as a header for a website - click on it to see the full size. I am trying to replicate this using HTML, CSS, and images, but I'm struggling. It needs to be 100% w ...

Do you understand why my Fabricjs canvas is rejecting a rectangle?

http://jsfiddle.net/a7ZSG/10/ check out the link to the jsfiddle for more information. Having trouble getting a red rectangle to appear in a green canvas? Can anyone figure out why it's not showing up? I've attempted using window.onload around a ...

Modifying SASS variable values based on the presence of specific text in the page URL

How can I utilize the same SASS file for two different websites with similar functionality but different color schemes? My goal is to dynamically change the color based on the URL of the page. However, I am facing challenges in extracting the page URL from ...

Speeding up the loading time of my background images

body { background: url(http://leona-anderson.com/wp-content/uploads/2014/10/finalbackgroundMain.png) fixed; background-size:100% auto; } I have unique background images on each of my sites, but they are large in size and take some time to load due to bein ...

Guide to integrating PHP and MySQL with HTML

I am venturing into the world of php for the first time in order to establish a connection with MySQL on my raspberry pi. Both the server and MySQL are up and running on the Pi, and I am seeking to modify my index.html file to display a value stored in the ...

The stylesheet is linked, but no changes are taking effect

I've linked my template.php to style.css, and when I make changes in template.php, they show up fine. However, if I make changes in the stylesheet, nothing happens. What should I do? My website is not live; I'm working on it using a WAMP server. ...

Trying to incorporate a PHP echo statement into the innerHTML of a button is ineffective

I have a piece of jQuery code that is not functioning as expected: $("#erase").click(function(){ $("#erase").attr("disabled", "disabled"); // Prevent double-clicking $(this).html("Erasing..."); $.post("erase.php", {target: $("#targ ...

Displaying a dynamic menu using Angular's ngFor loop

I am attempting to create a menu with sub-menus. The desired structure for my menu is outlined below. However, the demo I'm testing is not producing the correct structure. Check out the demo here. "Sub Test": { // Main menu "Example1":"hai",//sub ...

Ensuring stackable columns are centrally aligned using justify-content-center

My goal is to create a responsive layout with x columns that display 3 columns per row on lg screen sizes, aligned using justify-content-between. When the screen size is smaller than lg, all x columns should stack vertically and be aligned using justify-co ...

Is it possible to simultaneously adjust the source of multiple images using JavaScript?

After conducting some research, it is evident that there are numerous inquiries regarding changing the src of an image using JavaScript. My specific need, however, is to alter the src of three images simultaneously when a button is clicked. HTML: <ul ...

horizontal alignment of row content to the right in HTML

Trying to align a text and a small image horizontally to the right: <div class="row float-right"> <div class="title" >Stream Chat</div> <img src="~assets/chat.svg" /> </div> ...

Adjust the transparency of a separate image within a different container by hovering over another image container

Is my goal too complex to achieve? I am attempting to create a hover effect where the opacity of artwork1 and button1 changes simultaneously when hovered over. However, I am having trouble properly labeling my elements and getting them to interact as inten ...

Creating a toggle button in Python Tkinter that remains pressed until another button is pressed

I'm exploring ways to keep the Start button pressed in Tkinter until I press the Stop button. from Tkinter import * import tkMessageBox class MainWindow(Frame): def __init__(self): Frame.__init__(self) self.master.title("input") ...

JavaScript Implementation for Validating Birthdates

I'm facing an issue with validating a Birthday date. I need to ensure that all fields are filled in, otherwise there should be an alert stating ("day must be chosen / month must be chosen"). How can I effectively run this validation script? Birt ...

Removing CSS errors from HTML files in Visual Studio Code on a Mac

Currently, I am utilizing Visual Studio Code on a Mac for writing AngularJS style HTML. Whenever I try to include an inline expression for a CSS value, I encounter an irritating red Intellisense error, as displayed in the screenshot provided below. It is w ...

What is the best way to position a div as a footer within a larger main div?

I am aiming to create a div with simple header, content, and footer sections. Here is the design I am trying to achieve: https://i.stack.imgur.com/QfnGa.png You can check out my code on jsfiddle. I'm having trouble understanding how the relative lay ...

Is it impossible to adjust the background color?

https://i.sstatic.net/9uKBt.png <div class="container" ng-app="sortApp" ng-controller="mainController"> <form> <div class="form-group"> <div class="input-group"> ...

Is it common practice or a clever hack to use negative values for the top position in CSS?

I am working with a few Div's that have background images, and the top one has a curve design. I am trying to align the bottom Div with the curved top one, so I was considering using the following CSS properties: top: -39px; width: 260px; Would usi ...

Eliminating the bottom border of all buttons, except for the last three buttons in the list, solely using pure JavaScript, unless alternative methods are available

I have 3 sets of buttons, with each set containing 9 buttons stacked in 3 columns inside an ordered list (ol) within list items (li). I have removed the bottom border of the buttons to avoid double borders since they are stacked on top of each other withou ...