Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

Need Help figuring out this code

Foxxster

New Coder
I found this code on codepen and I have edited it quite a bit, but I am having trouble figuring out how to make the focused imaged on hover not transparent. Can anyone help me figure it out?

CSS:
<style>
  * {
  box-sizing: border-box;
}

 body {
  display: grid;
  place-items: center;
  min-height: 100vh;
 
}

ul {
  display: flex;
  width: calc(100% - 2rem);
  padding: 0;
  margin: 0;
  list-style-type: none;
  justify-content: center !important;
}

li {
  padding: 0;
}

img {
  max-width: 100%;
  width: 100%;
  object-fit: cover;
  transition: all 0.2s ease;
}

ul:is(:hover, :focus-within) img {
 
  filter: grayscale(calc(1 - var(--active-lerp, 0)));
}

:root {
  --lerp-0: 1;
  --lerp-1: 0.5787037;
  --lerp-2: 0.2962963;
  --lerp-3: 0.125;
  --lerp-4: 0.037037;
  --lerp-5: 0.0046296;
  --lerp-6: 0;
}

a {
  outline-offset: 4px;
}

li {
  flex: calc(0.1 + (var(--active-lerp, 0) * 1));
  transition: flex 0.2s ease;
}

li:is(:hover, :focus-within) {
  --active-lerp: var(--lerp-0);
  z-index: 7;
}
li:has( + li:is(:hover, :focus-within)),
li:is(:hover, :focus-within) + li {
  --active-lerp: var(--lerp-1);
  z-index: 6;
}
li:has( + li + li:is(:hover, :focus-within)),
li:is(:hover, :focus-within) + li + li {
  --active-lerp: var(--lerp-2);
  z-index: 5;
}
li:has( + li + li + li:is(:hover, :focus-within)),
li:is(:hover, :focus-within) + li + li + li {
  --active-lerp: var(--lerp-3);
  z-index: 4;
}
li:has( + li + li + li + li:is(:hover, :focus-within)),
li:is(:hover, :focus-within) + li + li + li + li {
  --active-lerp: var(--lerp-4);
  z-index: 3;
}
li:has( + li + li + li + li + li:is(:hover, :focus-within)),
li:is(:hover, :focus-within) + li + li + li + li + li {
  --active-lerp: var(--lerp-5);
  z-index: 2;
}
li:has( + li + li + li + li + li + li:is(:hover, :focus-within)),
li:is(:hover, :focus-within) + li + li + li + li + li + li {
  --active-lerp: var(--lerp-6);
  z-index: 1;
}
</style>
HTML:
<center>
<ul class="results">
  <li class="result">
    <a href="/wheins" target="_blank"><img src="https://static1.squarespace.com/static/61646d7cb4e28c4aa05e672d/t/65286d265b1cc2124d925ea9/1697148198679/WHeins+Pic.jpg" width="500" height="500" alt=""></a>
  </li>
    <li class="result">
    <a href="/scutliff" target="_blank"><img src="https://static1.squarespace.com/static/61646d7cb4e28c4aa05e672d/t/65286d9eb52f32053f9d7ab5/1697148318606/SCutliff+Pic.jpg" width="500" height="500" alt=""></a>
  </li>
  <li class="result">
    <a href="/jsale" target="_blank"><img src="https://static1.squarespace.com/static/61646d7cb4e28c4aa05e672d/t/652869b7ab9ddf1c543695d8/1697147319466/JSale+Pic.jpg" width="500" height="500" alt=""></a>
  </li>
  <li class="result">
    <a href="/cvache" target="_blank"><img src="https://static1.squarespace.com/static/61646d7cb4e28c4aa05e672d/t/65286c0cdbaa5f53bd7cfb4a/1697147916652/CVache+Pic.jpg" width="500" height="500" alt=""></a>
  </li>
  <li class="result">
    <a href="/jwilliams" target="_blank"><img src="https://static1.squarespace.com/static/61646d7cb4e28c4aa05e672d/t/65286c8657d1630d91e2fc96/1697148039037/JWilliams+Pic.jpg" width="500" height="500" alt=""></a>
  </li>
</ul>
</center>
 
Last edited by a moderator:
I found this code on codepen and I have edited it quite a bit, but I am having trouble figuring out how to make the focused imaged on hover not transparent. Can anyone help me figure it out?

CSS:
<style>
  * {
  box-sizing: border-box;
}

 body {
  display: grid;
  place-items: center;
  min-height: 100vh;
 
}

ul {
  display: flex;
  width: calc(100% - 2rem);
  padding: 0;
  margin: 0;
  list-style-type: none;
  justify-content: center !important;
}

li {
  padding: 0;
}

img {
  max-width: 100%;
  width: 100%;
  object-fit: cover;
  transition: all 0.2s ease;
}

ul:is(:hover, :focus-within) img {
 
  filter: grayscale(calc(1 - var(--active-lerp, 0)));
}

:root {
  --lerp-0: 1;
  --lerp-1: 0.5787037;
  --lerp-2: 0.2962963;
  --lerp-3: 0.125;
  --lerp-4: 0.037037;
  --lerp-5: 0.0046296;
  --lerp-6: 0;
}

a {
  outline-offset: 4px;
}

li {
  flex: calc(0.1 + (var(--active-lerp, 0) * 1));
  transition: flex 0.2s ease;
}

li:is(:hover, :focus-within) {
  --active-lerp: var(--lerp-0);
  z-index: 7;
}
li:has( + li:is(:hover, :focus-within)),
li:is(:hover, :focus-within) + li {
  --active-lerp: var(--lerp-1);
  z-index: 6;
}
li:has( + li + li:is(:hover, :focus-within)),
li:is(:hover, :focus-within) + li + li {
  --active-lerp: var(--lerp-2);
  z-index: 5;
}
li:has( + li + li + li:is(:hover, :focus-within)),
li:is(:hover, :focus-within) + li + li + li {
  --active-lerp: var(--lerp-3);
  z-index: 4;
}
li:has( + li + li + li + li:is(:hover, :focus-within)),
li:is(:hover, :focus-within) + li + li + li + li {
  --active-lerp: var(--lerp-4);
  z-index: 3;
}
li:has( + li + li + li + li + li:is(:hover, :focus-within)),
li:is(:hover, :focus-within) + li + li + li + li + li {
  --active-lerp: var(--lerp-5);
  z-index: 2;
}
li:has( + li + li + li + li + li + li:is(:hover, :focus-within)),
li:is(:hover, :focus-within) + li + li + li + li + li + li {
  --active-lerp: var(--lerp-6);
  z-index: 1;
}
</style>
HTML:
<center>
<ul class="results">
  <li class="result">
    <a href="/wheins" target="_blank"><img src="https://static1.squarespace.com/static/61646d7cb4e28c4aa05e672d/t/65286d265b1cc2124d925ea9/1697148198679/WHeins+Pic.jpg" width="500" height="500" alt=""></a>
  </li>
    <li class="result">
    <a href="/scutliff" target="_blank"><img src="https://static1.squarespace.com/static/61646d7cb4e28c4aa05e672d/t/65286d9eb52f32053f9d7ab5/1697148318606/SCutliff+Pic.jpg" width="500" height="500" alt=""></a>
  </li>
  <li class="result">
    <a href="/jsale" target="_blank"><img src="https://static1.squarespace.com/static/61646d7cb4e28c4aa05e672d/t/652869b7ab9ddf1c543695d8/1697147319466/JSale+Pic.jpg" width="500" height="500" alt=""></a>
  </li>
  <li class="result">
    <a href="/cvache" target="_blank"><img src="https://static1.squarespace.com/static/61646d7cb4e28c4aa05e672d/t/65286c0cdbaa5f53bd7cfb4a/1697147916652/CVache+Pic.jpg" width="500" height="500" alt=""></a>
  </li>
  <li class="result">
    <a href="/jwilliams" target="_blank"><img src="https://static1.squarespace.com/static/61646d7cb4e28c4aa05e672d/t/65286c8657d1630d91e2fc96/1697148039037/JWilliams+Pic.jpg" width="500" height="500" alt=""></a>
  </li>
</ul>
</center>
Hi there,

Not quite sure I follow...I copied your code over and tested it, and I don't see any image becoming transparent. I do see that once you hover over an image, the other images grey out, is that what you are referring to?
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom