停止SVG覆盖高度
我有一个伪造的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将
高度
添加到您的.pseudo-编码:
之前,它将解决您的问题。如果您的元素的大小固定,则溢出有效Add
height
to your.pseudo--code:before
and it will solve your problem. Overflow works if your element have fixed size添加
溢出:隐藏
到pseudo-code
类。并删除
位置:从
之前。pseudo-code中删除
:更新
回应您的评论。此示例适用于其他高度。在下面的示例中,我将高度提高到500px。
Add
overflow: hidden
to thepseudo--code
class.And remove
position: absolute
frompseudo--code:before
.Update
In response to your comment. This example works for other heights. In the example below, I have increased the height to 500px.