使用javascript或css的自动高度div

使用javascript或css的自动高度div,javascript,jquery,css,Javascript,Jquery,Css,在这一页,你会看到右边的边栏,我想这列有相同的高度作为主要的中央列。 我认为这需要javascript或css,但我不知道如何实现。 这是一个Joomla CMS,但我可以在模块中添加一些代码 谢谢。您可以使用javascript。 此页面包括jQuery。因此,请将此添加到您的页面 <script> $(function(){ jQuery('#right .inner'). css('height', jQuery('#center .inner').height())

在这一页,你会看到右边的边栏,我想这列有相同的高度作为主要的中央列。 我认为这需要javascript或css,但我不知道如何实现。 这是一个Joomla CMS,但我可以在模块中添加一些代码

谢谢。

您可以使用javascript。 此页面包括jQuery。因此,请将此添加到您的页面

<script>
$(function(){
  jQuery('#right .inner').
  css('height', jQuery('#center .inner').height())
})

$(函数(){
jQuery('#right.inner')。
css('height',jQuery('#center.inner').height()
})
您必须使用内部元素。因为背景应用于内部。
如果我们更改$('#right')的高度,您将看不到它。

是的,您可以使用jquery执行此操作,您可以使用
.height()
获取最小内容的高度

$(document).ready(function(){
  var mainHeight = $('#center').height();
  alert(mainHeight);
});

您根本不需要JavaScript或JQuery。你可以用一些CSS来解决这个问题。这里回答了一个几乎相同的问题:


您可以单独使用CSS,使用人造列技术来解决这个问题,下面是一个演示:。我更新了下面的id和CSS,以反映链接页面上的id

<div id="main">
    <div class="faux-col-right"><!-- this is just for the background //--></div>

    <div id="center">
    <!-- center column content goes here //-->
    </div>

    <div id="right">
    <!-- right column content goes here //-->
    </div>
</div>

#main {
    position: relative;
    overflow: auto;
    zoom: 1;
}

.faux-col-right {
    background: #cccccc;
    position: absolute;
    left: 69.047619047619%;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 1;
}

#right {
    width: 30.952380952381%;
    float: left;
    position: relative;
    z-index: 2;
}

#center {
    width: 69.047619047619%;
    float: left;
}

#主要{
位置:相对位置;
溢出:自动;
缩放:1;
}
1.仿冒col right{
背景:#中交;;
位置:绝对位置;
左:69.047619047619%;
右:0;
排名:0;
底部:0;
z指数:1;
}
#对{
宽度:30.952380952381%;
浮动:左;
位置:相对位置;
z指数:2;
}
#居中{
宽度:69.047619047619%;
浮动:左;
}

首先尝试用CSS解决问题。也许你应该看看像这样的教程:Hello@alynioke的可能副本我看到你删除了你的解决方案,为什么,这对我有用?谢谢,我尝试在页面上添加此代码,但这不起作用。你好,谢谢,但这不起作用。回答好。如果右栏内容超过左栏内容,我不确定此解决方案是否有效。我发布的解决方案应该适用于任何一种情况。是的,如果右栏内容超过中栏,则此解决方案不起作用您好,您的解决方案更好,但如果像在本页上一样,没有左栏,则这是一个问题。感谢我仅为此页更改css