gpt4 book ai didi

html - 基于 css 百分比的背景

转载 作者:太空宇宙 更新时间:2023-11-03 22:40:12 24 4
gpt4 key购买 nike

我怎样才能显示带有一些文本的 div(其宽度完全填满 div),然后显示只有 40% 的背景颜色而不遮挡文本。

以下是有问题的,因为文本位于内部 div 中。可以这么说,我希望它在外部 div 中。

<div>
<div style="background-color:#EAFEE2; width:35%;"><span>This is a much longer text and takes up a lot of space</span></div>
</div>

最佳答案

您可以使内部 DIV 绝对定位,使用负 z-index 和所需的宽度限制,如以下代码段所示。

注意:内层DIV为空,文字只在外层DIV,内层没有)

.outer {
position: relative;
}

.inner {
position: absolute;
top: 0;
left: 0;
width: 35%;
height: 100%;
background: #EAFEE2;
z-index: -1;
}
<div class="outer">
<div class="inner"></div>
This is a much longer text and takes up a lot of space
</div>

关于html - 基于 css 百分比的背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44359685/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com