Jump to content

Hover link effects: CSS that doesn't apply to buttons

Go to solution Solved by Lesum,

Recommended Posts

Posted

Hi everyone!

 

I am experimenting with CSS to create some hover link effects for my site. For now, I'm going with something that gives a passing underline. 

This is the code I'm using:

}
a {
  color: #C8102E;
  position: relative;
  text-decoration: none;
}

a::before {
  content: '';
  position: absolute;
  width: 100%;
  height: 2px;
  border-radius: 4px;
  background-color: #C8102E;
  bottom: 0;
  left: 0;
  transform-origin: right;
  transform: scaleX(0);
  transition: transform .3s ease-in-out;
}

a:hover::before {
  transform-origin: left;
  transform: scaleX(1);
}

 

For the links in regular text, it's giving me the desired effect:

image.thumb.png.181d77261bca06d498ed9b48166bc295.png

However, the passing underline also appears below my buttons which I don't want.

image.thumb.png.394f70ca4d0f4223cff147365d4e9624.png

 

Is there some code that I can add so that this hover effect does not apply to any buttons? Or, will I have to use HTML to add these hover links on a link-by-link basis?

 

Thank you in advance.

 

  • Replies 4
  • Views 1.1k
  • Created
  • Last Reply

Top Posters In This Topic

Posted

@AustD You just need to add :not(.sqs-block-button-element) after the a tag in your code to exclude the buttons. The updated code should look like this:


a:not(.sqs-block-button-element) {
    color: #c8102e;
    position: relative;
    text-decoration: none;
}

a:not(.sqs-block-button-element)::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 2px;
    border-radius: 4px;
    background-color: #c8102e;
    bottom: 0;
    left: 0;
    transform-origin: right;
    transform: scalex(0);
    transition: transform .3s ease-in-out;
}

a:not(.sqs-block-button-element):hover::before {
    transform-origin: left;
    transform: scalex(1);
}

 

If my comments were useful, please like or mark my solution as answer so others can scroll to it quickly. 

Sam
Web Developer & Digital Designer

 Did you find my contribution helpful? Buy me a coffee?

Posted

@Lesum Thank you very much! The buttons are now excluded as I wanted.

The only issue I now have is that all the hyperlinks on my site are colour #C8102E. I realise it's probably bad practice but before I used your modified code, certain links (the social media links) on my site were black.  However, with this code, every link is now red.

 

image.thumb.png.f6c14138207e32a539e3e70ec0f2e303.png

Is there something I can add to ensure my links stay the colour they were before this hover link CSS was applied? Or, will it just be a case of manually changing the links in black back to red?

 

That aside, I've noticed a bigger issue with this code that I'm hoping you could also help me with. The issue must have been apparent when I created this post but I've only noticed it now. It seems the original hovel link CSS removed/hid all images across my site that contained links. Here is an example from one affected page: 

 

image.thumb.png.744b256930cfc0afbc5a3d42d13c823b.png

Page in question: https://www.sportsandsuitcases.com/lima

 

The page should look like this with each of these six images that you now see being clickable:

 

image.thumb.png.5ac7d2fcc02c2d2df9bc71f87e3bcdc4.png

 

Can the hover link code be modified so that it excludes buttons but not any image that contains a link?

 

Thank you again

 

  • Solution
Posted

@AustD Here's the updated code that fixes the issue with your image links and applies the red color only to text links inside a code block like you had initially. Regular text links will maintain their default color, which you can adjust in the Squarespace editor as needed.

a {
    color: #c8102e;
    text-decoration: none;
}

a:not(.sqs-block-button-element):not(.sqs-block-image-link) {
    position: relative;
}

a:not(.sqs-block-button-element):not(.sqs-block-image-link)::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 2px;
    border-radius: 4px;
    background-color: #c8102e;
    bottom: 0;
    left: 0;
    transform-origin: right;
    transform: scaleX(0);
    transition: transform .3s ease-in-out;
}

a:not(.sqs-block-button-element):not(.sqs-block-image-link):hover::before {
    transform-origin: left;
    transform: scaleX(1);
}

If my comments were useful, please like or mark my solution as answer so others can scroll to it quickly. 

Sam
Web Developer & Digital Designer

 Did you find my contribution helpful? Buy me a coffee?

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.