首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在css头中修正前后

在css头中修正前后
EN

Stack Overflow用户
提问于 2022-10-07 20:56:37
回答 2查看 32关注 0票数 -2

我不明白为什么这段代码在我的第一个html中工作,但这里没有。当我在内容中添加任何文本而不是空间时,它会工作。我只需要headerBuy_bs周围的两条线。以及任何要接受的短信。

代码语言:javascript
复制
.buyBox_bs {
  grid-area: 2/2/2/3;
  width:  max-content;
  margin: auto;
  margin-top: 5vmin;
  
    
 }
.headerBuy_bs {
    color: black;
    margin-bottom: $gor-10 * 3;
    text-align: center;
    font-size: $font-24;
    margin-top: $gor-10 * 3;
}

.headerBuy_bs:after {
      content: "";
      height: 2.09vh;
      width: 4.48vw;
      background: linear-gradient(
        to right,
        #f7c901 0%,
        #f7ca0181 50%,
        rgba(255, 255, 255, 0) 100%
      );
      position: relative;
      top: 50%;
      right: 22%;
    }
    
    .headerBuy_bs:before {
      content: "";
      height: 0.09vh;
      width: 4.48vw;
      background: linear-gradient(
        to left,
        #f7c901 0%,
        #f7ca0181 50%,
        rgba(255, 255, 255, 0) 100%
      );
      
      position: relative;
      top: 50%;
      left: 22%;
    }
代码语言:javascript
复制
<div class='buyBox_bs'>
  <div class='headerBuy_bs'>hello</div>
</div>

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-10-07 21:05:28

只需将display:inline-block;添加到.headerBuy_bs::after.headerBuy_bs::before

代码语言:javascript
复制
.buyBox_bs {
  grid-area: 2/2/2/3;
  width:  max-content;
  margin: auto;
  margin-top: 5vmin;
  
    
 }
.headerBuy_bs {
    color: black;
    margin-bottom: $gor-10 * 3;
    text-align: center;
    font-size: $font-24;
    margin-top: $gor-10 * 3;
}

.headerBuy_bs::after {
      content: "";
      display:inline-block;
      height: 2.09vh;
      width: 4.48vw;
      background: linear-gradient(
        to right,
        #f7c901 0%,
        #f7ca0181 50%,
        rgba(255, 255, 255, 0) 100%
      );
      position: relative;
      top: 50%;
      right: 22%;
    }
    
    .headerBuy_bs::before {
      content: "";
      display:inline-block;
      height: 0.09vh;
      width: 4.48vw;
      background: linear-gradient(
        to left,
        #f7c901 0%,
        #f7ca0181 50%,
        rgba(255, 255, 255, 0) 100%
      );
      
      position: relative;
      top: 50%;
      left: 22%;
    }
代码语言:javascript
复制
<div class='buyBox_bs'>
  <div class='headerBuy_bs'>hello</div>
</div>

票数 1
EN

Stack Overflow用户

发布于 2022-10-07 21:08:04

请将position: absolute;添加到.headerBuy_bs:before.headerBuy_bs:after中,.headerBuy_bs添加position: relative;

代码语言:javascript
复制
 .headerBuy_bs {
      position: relative;
}
.headerBuy_bs:after {
      position: absolute;
      right: -100%;
      top: 50%;
      transform: translateY(-50%);
}
.headerBuy_bs:before {
      position: absolute;
      left: -100%;
      top: 50%;
      transform: translateY(-50%);
}

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73992523

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档