Jump to content

Custom code help: How to turn entire grid cell into a link

Go to solution Solved by jpeter,

Recommended Posts

Posted (edited)

Site URL: https://steven.squarespace.com/test

I've created a very simple custom grid using display: grid

 

Here's the code:

 

<div class="grid">
  <div class="grid-cell">Some Text</div>
  <div class="grid-cell">Some Text</div>
  <div class="grid-cell">Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text</div>
</div>

<style>
  .grid {
    width: auto;
    margin: 0 auto;
    display: grid;
    grid-gap: 1px;
    background-color: #000 !important;
    border: 1px solid #000 !important;
    grid-template-columns: repeat(3, 1fr);
  }
  
  .grid-cell {
    background-color: #fff;
    color: #000;
    padding: .5rem;
    min-height: 4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center !important;
    word-break: break-word;
  }
</style>

 

 

How do I turn each entire grid cell into a link?

I tried wrapping <div class="grid-cell">Some Text</div> in anchor tags, but for some reason, it breaks the grid design.

Any non-JS solutions?

Thank you in advance.

Edited by sqsp
Posted
22 hours ago, sqsp said:

Site URL: https://steven.squarespace.com/test

I've created a very simple custom grid using display: grid

 

Here's the code:

 

<div class="grid">
  <div class="grid-cell">Some Text</div>
  <div class="grid-cell">Some Text</div>
  <div class="grid-cell">Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text Some Text</div>
</div>

<style>
  .grid {
    width: auto;
    margin: 0 auto;
    display: grid;
    grid-gap: 1px;
    background-color: #000 !important;
    border: 1px solid #000 !important;
    grid-template-columns: repeat(3, 1fr);
  }
  
  .grid-cell {
    background-color: #fff;
    color: #000;
    padding: .5rem;
    min-height: 4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center !important;
    word-break: break-word;
  }
</style>

 

 

How do I turn each entire grid cell into a link?

I tried wrapping <div class="grid-cell">Some Text</div> in anchor tags, but for some reason, it breaks the grid design.

Any non-JS solutions?

Thank you in advance.

Do you mean adding a link to grid cell?

image.thumb.png.af2e3d701b7dcd862e7d9960e4715857.png

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Pinch/Zoom images, videos - PDFs Lightbox - ...) </>  🗓️ Delivery Date Picker (Date picker form field)
Gallery block 7.1 workaround </> 🤖 Ask me anything

Posted
49 minutes ago, bangank36 said:

Do you mean adding a link to grid cell?

image.thumb.png.af2e3d701b7dcd862e7d9960e4715857.png

 

 

What I would like is make the entire grid cell clickable, not just "Some Text."

Posted (edited)
5 hours ago, sqsp said:

 

 

What I would like is make the entire grid cell clickable, not just "Some Text."

I think we can implement some Css code to make the a tag cover all cell.

Kindly wrap the content in cell with the a tag and try the following style

.grid-cell a {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

with the style, I think we should combine with block id so your css would not affect the other element on your site

Hope it makes sense

Edited by bangank36

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Pinch/Zoom images, videos - PDFs Lightbox - ...) </>  🗓️ Delivery Date Picker (Date picker form field)
Gallery block 7.1 workaround </> 🤖 Ask me anything

Posted
54 minutes ago, bangank36 said:

I think we can implement some Css code to make the a tag cover all cell.

Kindly wrap the content in cell with the a tag and try the following style

.grid-cell a {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

with the style, I think we should combine with block id so your css would not affect the other element on your site

Hope it makes sense

 

Thank you!!

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.