在CSS中,我們可以使用visibility
屬性來設(shè)置元素的可見性,當(dāng)visibility
屬性值為hidden
時,元素會被隱藏,但并不會影響布局或占據(jù)的空間,如果你想在隱藏欄中添加文字,那么你需要使用position
屬性來將文字定位到隱藏欄中。
下面是一個簡單的示例,展示如何在隱藏欄中添加文字:
<!DOCTYPE html> <html> <head> <style> .hidden-bar { position: absolute; top: 0; left: 0; width: 100px; height: 100px; visibility: hidden; } .hidden-text { position: absolute; top: 50px; left: 50px; width: 100px; height: 50px; visibility: hidden; } </style> </head> <body> <div class="hidden-bar"> <div class="hidden-text">隱藏欄中的文字</div> </div> <div style="position: relative; height: 200px; background-color: #f0f0f0;"></div> <div style="position: relative; height: 200px; background-color: #e0e0e0;"></div> <div style="position: relative; height: 200px; background-color: #d0d0d0;"></div> <div style="position: relative; height: 200px; background-color: #c0c0c0;"></div> <div style="position: relative; height: 200px; background-color: #b0b0b0;"></div> <div style="position: relative; height: 200px; background-color: #a0a0a0;"></div> <div style="position: relative; height: 200px; background-color: #909090;"></div> <div style="position: relative; height: 200px; background-color: #808080;"></div> <div style="position: relative; height: 200px; background-color: #707070;"></div> <div style="position: relative; height: 200px; background-color: #606060;"></div> <div style="position: relative; height: 200px; background-color: #505050;"></div> <div style="position: relative; height: 200px; background-color: #404040;"></div> <div style="position: relative; height: 200px; background-color: #303030;"></div> <div style="position: relative; height: 200px; background-color: #202020;"></div> <div style="position: relative; height: 200px; background-color: #101010;"></div> <div style="position: relative; height: 200px; background-color: #f5f5f5;"></div> <div style="position: relative; height: 200px; background-color: #e5e5e5;"></div> <div style="position: relative; height: 200px; background-color: #d5d5d5;"></div> <div style="position: relative; height: 200px; background-color: #c5c5c5;"></div> <div style="position: relative; height: 200px; background-color: #b5b5b5;"></div> <div style="position: relative; height: 200px; background-color: #a******5;"></div> <div style="position: relative; height: 200px; background-color: #959595;"></div> <div style="position: relative; height: 200px; background-color: #858585;"></div> <div style="position: relative; height: 200px; background-color: #7575