如何在 HTML 中隐藏位置固定元素后面的文本



我需要隐藏位置固定元素后面的文本。元素后面的文本将不会显示这是 HTML 代码。

<!DOCTYPE html>
<html>
<head>
<style>
#fixed {
    position: fixed;
    border: 1px solid blue;
    background-color: rgba(255,200,200,0.5);    
    width: 300px;
    height: 100px;
    top: 40px;
    left: 0;
    right: 0;
}
</style>
</head>
<body>
<h1>The position property</h1>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum
</br>
<div id="fixed">position: fixed
</div>
</body>
</html>

除非你像这样为 #fixed 赋予全彩色,否则不可能不显示 #fixed 后面的文本:

<!DOCTYPE html>
    <html>
    <head>
    <style>
    #fixed {
        position: fixed;
        border: 1px solid blue;
        background-color: rgba(255,200,200);    
        width: 300px;
        height: 100px;
        top: 40px;
        left: 0;
        right: 0;
    }
    </style>
    </head>
    <body>
    <h1>The position property</h1>
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum
    </br>
    <div id="fixed">position: fixed
    </div>
    </body>
    </html>

Alpha 表示不透明度。因此,它可以显示背后的元素。因此,如果您想要较浅的颜色,您可以更改RGB属性。(但不是阿尔法属性。

否则,可以使用 opacity 属性使文本不可见。但是,不会显示所有文本。

更改 :

background-color: rgba(255,200,200,0.5);   

自:

background-color: rgb(255,200,200);   

最新更新