Jump to content

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

Go to solution Solved by jpeter,

Recommended Posts

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
Link to comment
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

Greeting, it's BeyondSpace, I am Squarespace dev focus on provide solutions to enhance feature that squarespace.com can't provide.
Feel free to check my current Squarespace Plugins Developement: Enable Pinch/Zoom on lightbox, Delivery Date Picker, Keyword Highlighter
If you find my answer fit your need, let's leave a like or upvote so others with the same issue can find their solution. Thank you

Link to comment
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

Greeting, it's BeyondSpace, I am Squarespace dev focus on provide solutions to enhance feature that squarespace.com can't provide.
Feel free to check my current Squarespace Plugins Developement: Enable Pinch/Zoom on lightbox, Delivery Date Picker, Keyword Highlighter
If you find my answer fit your need, let's leave a like or upvote so others with the same issue can find their solution. Thank you

Link to comment
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!!

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.