當且僅當中心div小於Left SideBar2時,如何讓我的中心div與Left SideBar2高度相同? 我不確定這是否可以用純CSS完成,或者我應該如何使用JS以及如何?只有在中心div小於中心div時,才能使中心div與邊div相同
1
A
回答
1
這應該用JavaScript來完成......在這裏,我將使用jQuery的。 將其放入您的標籤並進行適當的更改。
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
(function() {
function changeHeight() {
$centerDiv = $('#centerDivId');
$leftBar = $('#leftBarId');
if ($centerDiv.height() < $leftBar.height()) {
$centerDiv.css('height', $leftBar.height())
}
}
});
</script>
0
jQuery(document).ready(function() {
var $center = jQuery('.center-selector');
$center.height(getCenterHeight());
});
var getCenterHeight = function() {
var $left = jQuery('.left-sidebar-container-selector');
var $right = jQuery('.right-sidebar-container-selector');
var leftHeight = parseInt($left.height(), 10);
var rightHeight = parseInt($right.height(), 10);
return Math.max(leftHeight, rightHeight);
};
0
也許你可以使用CSS3 min-height
屬性設置爲中心div的minimum height。
相關問題
- 1. DIV與CSS中心DIV
- 2. div中的中心div
- 3. div中的中心div
- 4. @media與中心div
- 5. 在一個div中心的div div
- 6. DIV中的中心DIV與圖像
- 7. DIV ALIGN =中心
- 8. 中心DIV
- 9. CSS DIV中心
- 10. 中心對齊div內div?
- 11. textarea旁邊的中心div
- 12. 對齊中心div的左右div div
- 13. 中心位置:相對DIV
- 14. JQuery從中心縮小div
- 15. 一個div與中心對齊div和右側div div
- 16. 不能中心導航Div
- 17. 我如何在IE7中心DIV在DIV
- 18. 保持Div中心
- 19. 中心響應DIV
- 20. Div中心位置
- 21. 對齊中心div
- 22. Div偏離中心
- 23. 水平中心div
- 24. 中心一個div
- 25. 中心浮動div
- 26. 垂直中心div
- 27. 中心DIV水平
- 28. DIV PX從中心
- 29. DIV不會中心
- 30. 中心兩個div
您可以使用媒體查詢 –
查看該主題的[這篇文章](http://css-tricks.com/fluid-width-equal-height-columns/)。讓我知道,如果這有助於你! – jmeas
您的意思是,如果中心div小於僅限Left SideBar2的高度,或者如果中心div中沒有足夠的內容可以觸及Left SideBar 2? – kyletaylored