左右div高度相同

来源:互联网 发布:dj小可网络电音歌曲 编辑:程序博客网 时间:2024/06/07 20:39

1.head引入

<script type="text/javascript" src="./resources/js/jquery.js"></script> <script type="text/javascript">    $(document).ready(function() {        window.onload=function(){            autoHeight();        }    })    function autoHeight(){        if($("#left").offsetHeight>=$("#right").offsetHeight){            $("#right").css({'height':'$("#left").offsetHeight+"px"'})        }else{            $("#left").css({'height':'$("#right").offsetHeight+"px"'})        }    }    </script>

2.html

<div style="width:800px;" style="display:inline">    <div id="left" style='float:left;width:330px; height:200px;background-color:red'>            <p>左侧页面</p>            <p>右侧页面</p>            <p>右侧页面</p>            <p>右侧页面</p>            <p>右侧页面</p>            <p>右侧页面</p>    </div>    <div id="right" style='float:left;width:330px; height:200px;background-color:blue'>            <p>右侧页面</p>    </div></div>
0 0
原创粉丝点击