Search code examples
javascripthtmlcssyoutube

Problem with making a youtube bar above recommended videos


bar image

I'm trying to make this bar in my youtube-copy project. I made the background of the buttons fade away with linear-gradient, but I don't know how to do the same with the text. html:

#bar-wrap{
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: row;
    gap: 0.6rem;
    font-size: 0.9rem;
    align-items: center;
    overflow-x: scroll;
    white-space: nowrap;
}
#bar-wrap .button{
    background-color: rgb(211,211,211);
    color: black;
    width: fit-content;
    height: 2rem;
    border-radius: 0.8rem;
    padding: 0.4rem;
    cursor: pointer;


    display: flex;
    align-items: center;
    justify-content: center;
}
<div id="bar-wrap">
  <div class="button" onclick="barActive(this)">Wszystkie</div>
  <div class="button" onclick="barActive(this)">Źródło: Ixo Music</div>
  <div class="button" onclick="barActive(this)">Podobne</div>
  <div class="button" onclick="barActive(this)">Na żywo</div>
  <div class="button" onclick="barActive(this)">Ostatnio przesłane</div>
  <div class="button" onclick="barActive(this)">Obejrzane</div>
</div>

I've tried to do linear-gradient on text as well but it doesn't work.


Solution

  • You need a gradient overlay.

    #bw1 {
      display: inline-block;
      position: relative;
    }
    
    #bw1::after {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: linear-gradient(90deg, rgb(255 255 255 / 0) 75%, rgb(255 255 255 / 1) 100%);
      pointer-events: none;
    }
    
    #bw2 {
      display: flex;
      align-items: center;
      gap: 0.6em;
      font-size: 0.9em;
      overflow: auto;
      white-space: nowrap;
      width: 400px;
      overflow: auto;
    }
    
    .button {
      background-color: rgb(211,211,211);
      border-radius: 0.8em;
      padding: 1em 0.5em;
      cursor: pointer;
    }
    
    /* Hide scrollbar for Chrome, Safari and Opera */
    #bw2::-webkit-scrollbar {
      display: none;
    }
    
    /* Hide scrollbar for IE, Edge and Firefox */
    #bw2 {
      -ms-overflow-style: none;  /* IE and Edge */
      scrollbar-width: none;  /* Firefox */
    }
    <div id="bw1">
      <div id="bw2">
        <div class="button" onclick="barActive(this)">Wszystkie</div>
        <div class="button" onclick="barActive(this)">Źródło: Ixo Music</div>
        <div class="button" onclick="barActive(this)">Podobne</div>
        <div class="button" onclick="barActive(this)">Na żywo</div>
        <div class="button" onclick="barActive(this)">Ostatnio przesłane</div>
        <div class="button" onclick="barActive(this)">Obejrzane</div>
      </div>
    </div>