簡體   English   中英

如何使div覆蓋網頁的整個寬度,而不僅僅是視口?

[英]How to make a div cover the whole width of a webpage, not just the viewport?

我正在設計一個用於最終項目的網站。 我包括的一件事是導航欄和一個只有紫色背景的div作為標題。

問題是,當窗口小於全屏時,div不會到達末尾。 我如何才能使div即使在調整窗口大小時也能到達頁面的末尾? 邊距設置得太零。

PS。 我不能使用位置:已修復,因為標頭應該位於頂部,而且我不認為vh或vw會因為我使用的程序太舊而起作用。 (Dreamweaver CS3)

這是代碼:(添加了jsfiddle) https://jsfiddle.net/0x4arjk2/8/

#apDiv5 {
position:absolute;
left:0px;
top:0px;
width:100%;
height:100px;
z-index:1;
background-color: #1A001A;
}

謝謝!

標記的問題是,您已經完全定位了所有div,並將它們從元素流中刪除。 絕對定位是指定位到最接近的祖先,而不是定位到視口。 因此,在調整屏幕大小時,絕對定位的topnav傾向於留在其位置,並且其內容在x方向上溢出,因此顯示了水平滾動條。 但是紫色的

width: 100%;

繼承自html標簽,即視口的寬度。 因此,觀察到的效果。

您不應該絕對定位每個div。 假設可以使用彈性盒,那么一種簡單的響應方法就是使用彈性盒。 當達到一定寬度時,它可以自動包裝所有元素,從而使設計更具響應性。 您可以使用以下方法調整此寬度(在發生包裹的下方)

max-width: 100px; //some value

headerMenu div中。

 html, body { padding: 0; margin: 0; overflow-x: hidden; } ul { list-style: none; } .header { top: 0; left: 0; display: flex; flex-direction: row; align-items: baseline; justify-content: space-between; background-color: #1A001A; } .headerMenu { display: flex; flex-direction: row; flex-wrap: wrap; max-width: 1000px; justify-content: flex-end; align-items: baseline; background-color: #000; } .headerMenu a { color: #f2f2f2; text-align: center; padding: 14px 16px; text-decoration: none; font-size: 17px; } .headerMenu a:hover { background-color: #ddd; color: black; } .headerMenu a.active { background-color: #FF0000; color: white; } 
 <html> <body> <div class="header"> <div> <!--add image/logo here--> <img src="http://via.placeholder.com/100x100" alt="" /> </div> <div class="headerMenu"> <a href="Splash.html">Home</a> <a href="Bio.html">Bio</a> <a href="Gallery.html">Gallery</a> <a class="active" href="upcoming Gigs.html">Upcoming Gigs</a> <a href="songs.html">Song List</a> <a href="Contact.html">Contact</a> <a href="media.html">Media</a> </div> </div> </body> </html> 

在此處了解有關CSS flexbox的更多信息

怎么做<div>覆蓋整個頁面,而不僅僅是視口</div><div id="text_translate"><p>我正在嘗試讓一個 div 覆蓋我的整個頁面。 目前,問題在於它僅覆蓋視口的大小(例如 1920x1080px)。</p><p> 這就是我目前正在使用的 div 的 CSS :</p><pre> #cursor-container { position: absolute; z-index: 99999; pointer-events: none; overflow-x: auto; background-color: rgba(0, 0, 0, 0.25); top: 0; left: 0; bottom: 0; right: 0; height: 100%; width: 100%; }</pre><p> 目前,它看起來像這樣:</p><p> <a href="https://i.stack.imgur.com/Zat4F.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Zat4F.png" alt="在此處輸入圖像描述"></a></p><p> 但它應該看起來像這樣:</p><p> <a href="https://i.stack.imgur.com/iAKcZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iAKcZ.png" alt="在此處輸入圖像描述"></a></p><p> 我怎樣才能解決這個問題?</p></div>

[英]How to make <div> cover whole page and not only viewport

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

相關問題 怎么做<div>覆蓋整個頁面,而不僅僅是視口</div><div id="text_translate"><p>我正在嘗試讓一個 div 覆蓋我的整個頁面。 目前,問題在於它僅覆蓋視口的大小(例如 1920x1080px)。</p><p> 這就是我目前正在使用的 div 的 CSS :</p><pre> #cursor-container { position: absolute; z-index: 99999; pointer-events: none; overflow-x: auto; background-color: rgba(0, 0, 0, 0.25); top: 0; left: 0; bottom: 0; right: 0; height: 100%; width: 100%; }</pre><p> 目前,它看起來像這樣:</p><p> <a href="https://i.stack.imgur.com/Zat4F.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Zat4F.png" alt="在此處輸入圖像描述"></a></p><p> 但它應該看起來像這樣:</p><p> <a href="https://i.stack.imgur.com/iAKcZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iAKcZ.png" alt="在此處輸入圖像描述"></a></p><p> 我怎樣才能解決這個問題?</p></div> Swiper如何使圖像覆蓋整個寬度? 如何使div覆蓋整個屏幕 使div覆蓋視口正確 如何讓 div、header、container 等覆蓋視口 如何使用meta視口“ width = device-width”獲得100%的div以完全覆蓋頁面的寬度 如何使頁腳覆蓋屏幕的整個寬度? 使絕對定位的div覆蓋視口 使div覆蓋視口的整個可見部分 Div不會覆蓋整個頁面的寬度
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM