在我的 html 中,我给了 body 一种颜色,我需要在它上面放置另一个具有它自己颜色的元素。我已经尝试过使用 z-index 的相对位置和绝对位置。
这是 body 标签。
<body bgcolor="cyan" style="position: relative;">
这是另一个元素。
<p class="content">a</p>
这是我在网上搜索使用的css。
.content{
position: fixed; /* Sit on top of the page content */
display: none; /* Hidden by default */
width: 100%; /* Full width (cover the whole page) */
height: 100%; /* Full height (cover the whole page) */
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0,0,0,0.5); /* Black background with opacity */
z-index: 10;
}
最佳答案
一切似乎都在这里!只需从您的 css 中删除 display:none
.content{
position: fixed; /* Sit on top of the page content */
width: 100%; /* Full width (cover the whole page) */
height: 100%; /* Full height (cover the whole page) */
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0,0,0,0.5); /* Black background with opacity */
z-index: 10;
}
现在应该如您所料出现了!
关于html - 如何将元素 1 的颜色叠加在主体或元素 2 的颜色上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56224642/