弹幕背景记录

119 阅读1分钟

弹幕背景记录,背景切割成了三段,前后半段都固定长度,中间长度可根据字体长度自适应

其实这个问题并不难解决,但是因为基本功问题,不知道width: fit-content导致我在100%和auto两者之间研究了半天无果

关键记录

width: fit-content;

完整代码

.barrage {
  position: relative;
  padding: 0 14px;
  width: fit-content;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;

  .left {
    position: absolute;
    top: 0;
    left: 0;
    width: 26px;
    height: 24px;
    background: url("../assets/images/barrage_1.png") no-repeat;
    background-size: 100% 100%;
  }

  .middle {
    position: absolute;
    top: 0;
    left: 26px;
    right: 30px;
    height: 24px;
    background: url("../assets/images/barrage_2.png") repeat-x;
    background-size: auto 100%;
  }

  .right {
    position: absolute;
    top: 0;
    right: 0;
    width: 30px;
    height: 24px;
    background: url("../assets/images/barrage_3.png") no-repeat;
    background-size: 100% 100%;
  }

  .text {
    position: relative;
    z-index: 1;
    font-size: 10px;
    color: #fff;
    white-space: nowrap;
  }
}