停止SVG覆盖高度

发布于 2025-02-12 03:25:59 字数 1303 浏览 0 评论 0原文

我有一个伪造的div:以前,这具有SVG作为内容。但是SVG比DIV更长,并且不断发展。如何阻止这种情况发生?

   body {
      background: #333333;
    }
    
    .pseudo--code {
      height: 300px;
      max-height: 300px;
      padding-left: 20px;
    }
    .pseudo--code:before {
      position: absolute;
      content: url("https://d33wubrfki0l68.cloudfront.net/96dbb28f6281e8f1cda214c22b571de137716690/bdc12/assets/numbers-light.svg");
      width: 10em;
      left: 10px;
      overflow-x: hidden;
      overflow-y: hidden;
      opacity; 0.1;
      max-width: 100%;
      max-height: 100%;
    }
    
    .pseudo--code:after, .pseudo-code:before {
      content: "";
      position: absolute;
      bottom: 0;
      top: 0;
    }
<div>
      <h1> This is a heading</h1>
      <div class="pseudo--code">
        <h> this is a second heading</h>
      </div>
      <h2>this is also a heading</h>
    </div>



 

还制作了Codepen https://codepen.io/losk.io/loskey/loskwantos/pen/pen/pen/nwypvvy

I have a div with a pseudo:before, and this has a svg as content. But the svg is longer then the div and it keeps going the full length. How do I stop this from happening?

   body {
      background: #333333;
    }
    
    .pseudo--code {
      height: 300px;
      max-height: 300px;
      padding-left: 20px;
    }
    .pseudo--code:before {
      position: absolute;
      content: url("https://d33wubrfki0l68.cloudfront.net/96dbb28f6281e8f1cda214c22b571de137716690/bdc12/assets/numbers-light.svg");
      width: 10em;
      left: 10px;
      overflow-x: hidden;
      overflow-y: hidden;
      opacity; 0.1;
      max-width: 100%;
      max-height: 100%;
    }
    
    .pseudo--code:after, .pseudo-code:before {
      content: "";
      position: absolute;
      bottom: 0;
      top: 0;
    }
<div>
      <h1> This is a heading</h1>
      <div class="pseudo--code">
        <h> this is a second heading</h>
      </div>
      <h2>this is also a heading</h>
    </div>



 

Also made a codepen https://codepen.io/Loskwantos/pen/NWYPvvy

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一梦浮鱼 2025-02-19 03:26:00

高度添加到您的.pseudo-编码:之前,它将解决您的问题。如果您的元素的大小固定,则溢出有效

body {
  background: #333333;
}

.pseudo--code {
  height: 300px;
  max-height: 300px;
  padding-left: 20px;
}
.pseudo--code:before {
  position: absolute;
  content: url("https://d33wubrfki0l68.cloudfront.net/96dbb28f6281e8f1cda214c22b571de137716690/bdc12/assets/numbers-light.svg");
  width: 10em;
  left: 10px;
  overflow-x: hidden;
  overflow-y: hidden;
  opacity; 0.1;
  max-width: 100%;
  max-height: 100%;
  height:300px;
}

.pseudo--code:after, .pseudo-code:before {
  content: "";
  position: absolute;
  bottom: 0;
  top: 0;
}
<div>
  <h1> This is a heading</h1>
  <div class="pseudo--code">
    <h> this is a second heading</h>
  </div>
  <h2>this is also a heading</h>
</div>
  

Add height to your .pseudo--code:before and it will solve your problem. Overflow works if your element have fixed size

body {
  background: #333333;
}

.pseudo--code {
  height: 300px;
  max-height: 300px;
  padding-left: 20px;
}
.pseudo--code:before {
  position: absolute;
  content: url("https://d33wubrfki0l68.cloudfront.net/96dbb28f6281e8f1cda214c22b571de137716690/bdc12/assets/numbers-light.svg");
  width: 10em;
  left: 10px;
  overflow-x: hidden;
  overflow-y: hidden;
  opacity; 0.1;
  max-width: 100%;
  max-height: 100%;
  height:300px;
}

.pseudo--code:after, .pseudo-code:before {
  content: "";
  position: absolute;
  bottom: 0;
  top: 0;
}
<div>
  <h1> This is a heading</h1>
  <div class="pseudo--code">
    <h> this is a second heading</h>
  </div>
  <h2>this is also a heading</h>
</div>
  

一绘本一梦想 2025-02-19 03:25:59

添加溢出:隐藏pseudo-code类。
并删除位置:从pseudo-code中删除之前。

body {
  background: #333333;
}

.pseudo--code {
  height: 300px;
  max-height: 300px;
  padding-left: 20px;
  overflow: hidden;
}
.pseudo--code:before {
  content: url("https://d33wubrfki0l68.cloudfront.net/96dbb28f6281e8f1cda214c22b571de137716690/bdc12/assets/numbers-light.svg");
  width: 10em;
  left: 10px;
  opacity; 0.1;
  max-width: 100%;
  max-height: 100%;
}

.pseudo--code:after, .pseudo-code:before {
  content: "";
  position: absolute;
  bottom: 0;
  top: 0;
}
<div>
  <h1> This is a heading</h1>
  <div class="pseudo--code">
    <h> this is a second heading</h>
  </div>
  <h2>this is also a heading</h>
</div>
  

更新
回应您的评论。此示例适用于其他高度。在下面的示例中,我将高度提高到500px。

body {
  background: #333333;
}

.pseudo--code {
  height: 500px;
  padding-left: 20px;
  overflow: hidden;
}
.pseudo--code:before {
  content: url("https://d33wubrfki0l68.cloudfront.net/96dbb28f6281e8f1cda214c22b571de137716690/bdc12/assets/numbers-light.svg");
  width: 10em;
  left: 10px;
  opacity; 0.1;
  max-width: 100%;
  max-height: 100%;
}

.pseudo--code:after, .pseudo-code:before {
  content: "";
  position: absolute;
  bottom: 0;
  top: 0;
}
<div>
  <h1> This is a heading</h1>
  <div class="pseudo--code">
    <h> this is a second heading</h>
  </div>
  <h2>this is also a heading</h>
</div>

Add overflow: hidden to the pseudo--code class.
And remove position: absolute from pseudo--code:before.

body {
  background: #333333;
}

.pseudo--code {
  height: 300px;
  max-height: 300px;
  padding-left: 20px;
  overflow: hidden;
}
.pseudo--code:before {
  content: url("https://d33wubrfki0l68.cloudfront.net/96dbb28f6281e8f1cda214c22b571de137716690/bdc12/assets/numbers-light.svg");
  width: 10em;
  left: 10px;
  opacity; 0.1;
  max-width: 100%;
  max-height: 100%;
}

.pseudo--code:after, .pseudo-code:before {
  content: "";
  position: absolute;
  bottom: 0;
  top: 0;
}
<div>
  <h1> This is a heading</h1>
  <div class="pseudo--code">
    <h> this is a second heading</h>
  </div>
  <h2>this is also a heading</h>
</div>
  

Update
In response to your comment. This example works for other heights. In the example below, I have increased the height to 500px.

body {
  background: #333333;
}

.pseudo--code {
  height: 500px;
  padding-left: 20px;
  overflow: hidden;
}
.pseudo--code:before {
  content: url("https://d33wubrfki0l68.cloudfront.net/96dbb28f6281e8f1cda214c22b571de137716690/bdc12/assets/numbers-light.svg");
  width: 10em;
  left: 10px;
  opacity; 0.1;
  max-width: 100%;
  max-height: 100%;
}

.pseudo--code:after, .pseudo-code:before {
  content: "";
  position: absolute;
  bottom: 0;
  top: 0;
}
<div>
  <h1> This is a heading</h1>
  <div class="pseudo--code">
    <h> this is a second heading</h>
  </div>
  <h2>this is also a heading</h>
</div>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文