Jump to content

Creating a layered button, z-index not working as expected

Recommended Posts

Note: this site isn't published so hopefully you can help without access to the page itself (I'm not the site owner). If not I may be able to get the owner to move it to password protected. 

 

I'm trying to create a button style like this (Figma screenshot): 

image.png.aa965feb7712e8e9ff4d22de41e087af.png

I found some CSS that should do exactly what I want (https://codepen.io/joebocock/pen/ZEWoMPb) but when I put in this code, it refuses to layer the boxes in the right order. The cream box is always on top (actual site screenshot):

 image.png.161395b3841178d9a27098f34288694d.png

I added z-index: 99 to the first button, which isn't in the example code. Without that, Squarespace treated the ::after as :onhover (cream box only appears when you hover).

Otherwise the CSS works great (colors, etc). It's just the layer order.

Here is the current CSS:

#page-section-62609597342c653695d5b87c .sqs-block-button-element {
  outline: 0;
  position: relative;
  background-color: #BF6939;
  z-index: 99;
}

#page-section-62609597342c653695d5b87c .sqs-block-button-element::after {
  content: "";
  background-color: #FAF7F3;
  border: 1px solid #BF6939;
  width: 100%;
  z-index: -1;
  position: absolute;
  height: 100%;
  top: 7px;
  left: 7px;
}

 

Link to comment
  • Replies 4
  • Views 521
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

40 minutes ago, KaijuCorgi said:

Note: this site isn't published so hopefully you can help without access to the page itself (I'm not the site owner). If not I may be able to get the owner to move it to password protected. 

 

I'm trying to create a button style like this (Figma screenshot): 

image.png.aa965feb7712e8e9ff4d22de41e087af.png

I found some CSS that should do exactly what I want (https://codepen.io/joebocock/pen/ZEWoMPb) but when I put in this code, it refuses to layer the boxes in the right order. The cream box is always on top (actual site screenshot):

 image.png.161395b3841178d9a27098f34288694d.png

I added z-index: 99 to the first button, which isn't in the example code. Without that, Squarespace treated the ::after as :onhover (cream box only appears when you hover).

Otherwise the CSS works great (colors, etc). It's just the layer order.

Here is the current CSS:

#page-section-62609597342c653695d5b87c .sqs-block-button-element {
  outline: 0;
  position: relative;
  background-color: #BF6939;
  z-index: 99;
}

#page-section-62609597342c653695d5b87c .sqs-block-button-element::after {
  content: "";
  background-color: #FAF7F3;
  border: 1px solid #BF6939;
  width: 100%;
  z-index: -1;
  position: absolute;
  height: 100%;
  top: 7px;
  left: 7px;
}

 

It could be better if you can share the protected password so we can take a look

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox)
🗓️ Delivery Date Picker (Squarespace Date picker form field)
💫 Gallery block 7.1 workaround
🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations)
🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget Templates)

If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you!

 

Link to comment

The site is still in trial mode so we can't publish, even privately 😕  I'll try to mock it up on another site I have access to and see if I can replicate the issue. 

Edit: @bangank36I've added a page on another site and tried to replicate it exactly. The section type, content, and CSS is the same and the button behavior is the same. 

https://pineapple-sapphire-khkb.squarespace.com/sandbox (no password)

Edited by KaijuCorgi
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.