我想設(shè)定一個(gè)元素,使其從頁面視圖中隱藏,並且其頂部恰好接觸頁面底部(該元素在視線之外)。當(dāng)元素的高度恆定為 66px 時(shí),我首先執(zhí)行 botttom: -66px;'
。但現(xiàn)在我需要這個(gè)來處理任何大小的元素。
如果我執(zhí)行 bottom: -100%;
,它會(huì)將其設(shè)定為父級(jí)大小的 100%。如何將其設(shè)定為自身高度的-100%。
您正在尋找「position:fixed
」和「transform:translateY(100%);
」。這允許您將 div 移出視窗 100%,與 div 的高度無關(guān)。
範(fàn)例:
div { position: fixed; bottom: 0px; left: 0px; width: 100%; height: 40px; background-color: red; color: #fff; transform: translateY(100%); }