在推荐视频上方制作 YouTube 栏时出现问题

问题描述 投票:0回答:1

bar image

我正在尝试在我的 YouTube 复制项目中制作这个栏。我使按钮的背景通过线性渐变逐渐消失,但我不知道如何对文本执行相同的操作。 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>

完整代码位于 https://github.com/Krzyziiu/youtube-copy

我也尝试过对文本进行线性渐变,但它不起作用。

javascript html css youtube
1个回答
0
投票

您需要渐变叠加。

#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>

© www.soinside.com 2019 - 2024. All rights reserved.