利用css实现两列等高的方法

来源:互联网 发布:js throw exception 编辑:程序博客网 时间:2024/05/17 04:20

1:利用负边距

<style type="text/css">

.container{
       width:980px
       background: pink;

       overflow:hidden;

}

/*清楚浮动*/

        .clearfloat{
                zoom:1;
        }
        .clearfloat:after{
                display:block;
                clear:both;
                 content:"";
                 height: 0;
                 line-height: 0;
                 visibility: hidden;
        }

/*清楚浮动*/
        .mainbox{
                width:650px;
                float:left;
                background: red;

                margin-bottom:-9999px;

                padding-bottom:9999px;

        }
        .sidebox{
                  width:280px;
                  float: right;
                  background: green;

                   margin-bottom:-9999px;

                   padding-bottom:9999px;


        }

</style>

2:利用背景图片在Y方向重复

<style type="text/css">

.container{
       width:980px
       background: url(images/a.png) repeat-y 0 0;

}

/*清楚浮动*/

        .clearfloat{
        zoom:1;
        }
        .clearfloat:after{
        display:block;
        clear:both;
        content:"";
        height: 0;
        line-height: 0;
        visibility: hidden;
        }

/*清楚浮动*/
        .mainbox{
        width:650px;
        float:left;

        }
        .sidebox{
          width:280px;
          float: right;

        }

</style>

3:利用边框模拟(定位元素的高度不能大于非定位元素的高度)

<style type="text/css">

.container{
       width:980px;

        positin:relative;

}

/*清楚浮动*/

        .clearfloat{
                zoom:1;
        }
        .clearfloat:after{
                 display:block;
                 clear:both;
                 content:"";
                 height: 0;
                 line-height: 0;
                 visibility: hidden;
          }

/*清楚浮动*/
        .mainbox{
                width:650px;
                float:left;
                background: red;

                border-right:280px solid green;

        }
        .sidebox{
                 width:280px;

                 position:absolute;

                 top:0;

                 right:0;

        }

</style>


div class="container clearfloat">
    <div class="mainbox">主要</div>
    <div class="sidebox">侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏侧边栏</div>
    </div>

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 全民投资:开局我选悟空 求你们了,让朕当个昏君吧 凌队的千面保镖超A的 我不只是动作巨星 穿越三国:这个阿斗不用扶 绑定百亿物资系统后暴富古代了 遮天之凡体至尊 穿越诸天神话 重生79之我在美国开银行 首次穿越撞上氢弹是否搞错了什么 港综世界的警察 满朝奸臣,你让朕怎么当千古一帝 我的火种战舰 我在魔王城伪装怪物 女配在年代文里做万人迷 九品仙路 护林日常:开局拯救大熊猫 穿越兽世:种田驭夫乐悠悠 不灭战神 我在宝可梦世界开餐厅 爸爸,我是来当你同学的 这个主角明明很强却异常谨慎 四合院:我的穿越为啥这么陋 甩了线上男友后我被亲哭了 人在南天坐看万古 为了成为英灵我只好在历史里搞事 我成了游戏里的反派之王 离婚后,前夫每天都想上位 霍格沃茨的风与鹰翼 攻略暴君后,我抱错大腿了 我的精灵模拟器 金鸾喜嫁 人在美漫,开局枪斗术 大国科技从手机开始 人住超神,渣在诸天 斗罗之王者吕布降临 从白蛇开始诸天改命 诸天之天外降临者 屠龙之前就读过龙族的路明非 足球盛宴,从收购欧洲俱乐部开始 在漫威驱魔的魔鬼神父