」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > 使用CSS讓兩個浮動Div高度一致的技巧

使用CSS讓兩個浮動Div高度一致的技巧

發佈於2025-04-19
瀏覽:414

How Can I Make Two Floating Divs the Same Height Using Only CSS?
在html/css

使用CSS創建相等的高度divs

One approach involves setting large bottom padding, negating that padding with negative bottom margin, and surrounding the divs with a container with hidden overflow.

Implementation

To demonstrate this technique, consider the following CSS code:

#container { 溢出:隱藏; 寬度:100%; } #左col { 浮子:左; 寬度:50%; 背景色:橙色; 填充底:500EM; 保證底:-500EM; } #Right-Col { 浮子:左; 寬度:50%; 邊緣右:-1px; / *對於IE兼容性 */ 邊界左:1px固體黑色; 背景色:紅色; 填充底:500EM; 保證底:-500EM; }

In the HTML, create the div container and two child divs:

This approach essentially forces the two divs to have the same height, even if they contain different amounts of content.較大的底部填充和負距離相互抵消,使DIV僅佔用所需的垂直空間。具有隱藏溢出的容器可確保任何多餘的內容都不可見。

很少,這提供了一種CSS的高度浮動的,

最新教學 更多>

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3