zoukankan      html  css  js  c++  java
  • 弹性盒布局(自适应)

    <!doctype html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>弹性盒布局-宽度自动分配-图片自适应</title>
        <style>
            *{ margin:0; padding:0}
            #parent {
                width:100%;
                background:#999;
                display:-webkit-box;
                height:auto;
            }
            #parent div {
                margin:5px;
            }
            /*将盒子进行平均分配的主要代码*/
            /*.son1{ -webkit-box-flex:1; }*/
            /*.son2{ -webkit-box-flex:1; }*/
            /*.son3{ -webkit-box-flex:1; }*/
            /*.son3{ -webkit-box-flex:3; } */  /*假如此处为3,则此盒子是整个大盒子一块的1/3*/
            .son1 img{
                width:100%;
                height: 100%;
            }
            .son1{
                position: relative;
                -webkit-box-flex:1;
            }
            .son1 span{
                position: absolute;
                left: 0;
                right: 0;
                bottom: 0;
                top:0;
                margin: auto;
                text-align: center;
                width: 100%;
                height: 20px;
                white-space:nowrap;/*禁止文字自动换行*/
                color:#666;
            }
            #parent div:hover{
                cursor: pointer;
            }
        </style>
    </head>
    <body>
            <div id="parent">
                <div class="son1">
                    <img src="http://images.cnblogs.com/cnblogs_com/heyiming/947284/o_sky.jpg" alt="" id="img1"/>
                    <span>内容区1的文字介绍</span>
                </div>
            </div>
            <p>3212231</p>
    
    <div id="parent_div" style="100%;background:#999;display:-webkit-box;/*height:500px;*/"><!--内部不含图片需定义高,将盒子撑起来-->
        <div class="son1_div" style="position: relative;-webkit-box-flex:1;background: red">
                <div class="son1_div_fix" style="background:yellow;position: absolute;left: 0;right: 0;/*bottom: 0;*/top:0;margin: auto;text-align: center; 100%;/*margin:-38% 0 0 0;*/">
                    <h3 style="white-space:nowrap;" id="h3_1">我是第一个定位的盒子</h3>
                    <img src="http://images.cnblogs.com/cnblogs_com/heyiming/947284/t_sky.jpg" alt="" style=" 100%;" id="img_fix1"/>
                </div>
        </div>
        <div class="son2_div" style="position: relative;-webkit-box-flex:1;background: green">
            <div class="son2_div_fix" style="background:purple;position: absolute;left: 0;right: 0;/*bottom: 0;*/top:0;margin: auto;text-align: center; 100%;/*margin:-38% 0 0 0;*/">
                <h3 style="white-space:nowrap;" id="h3_2">我是第二个定位的盒子</h3>
                <img src="http://images.cnblogs.com/cnblogs_com/heyiming/947284/t_sky.jpg" alt="" style=" 100%;" id="img_fix2"/>
            </div>
        </div>
        <div class="son3_div" style="position: relative;-webkit-box-flex:1;background: blue">
            <div class="son3_div_fix" style="background:pink;position: absolute;left: 0;right: 0;/*bottom: 0;*/top:0;margin: auto;text-align: center; 100%;/*margin:-38% 0 0 0;*/">
                <h3 style="white-space:nowrap;" id="h3_3">我是第二个定位的盒子</h3>
                <img src="http://images.cnblogs.com/cnblogs_com/heyiming/947284/t_sky.jpg" alt="" style=" 100%;" id="img_fix3"/>
            </div>
        </div>
    </div>
    <div id="show_down" style=" 100%;background: yellowgreen;">231231</div>
    </body>
    </html>
    <script src="http://files.cnblogs.com/files/heyiming/jquery-2.1.4.min.js"></script>
    <script>
    //         img_1=document.getElementById("img1");
    //         img_1.onclick = function(){
    //         window.open('http://baidu.com','_blank');
    //        }
    //         img_2=document.getElementById("img2");
    //         img_2.onclick = function(){
    //             window.open('http://www.sina.com','_blank');
    //         }
    //         img_3=document.getElementById("img3");
    //         img_3.onclick = function(){
    //             window.open('http://www.taobao.com','_blank');
    //         }
    </script>
    
    <script>
    
    </script>
    <script>
    
        //    $(window).load  解决谷歌浏览器的兼容问题
        $(window).load(function(){
    
            var width=$(window).width();
            var one_img=$("#img_fix1").css("height");//获取三图中  第一张图的高
            var h3_1=$("#h3_1").css("height");//获取第一部分文字的高
            var two_img=$("#img_fix2").css("height");//获取三图中  第2张图的高
            var h3_2=$("#h3_2").css("height");//获取第2部分文字的高
            var three_img=$("#img_fix3").css("height");//获取三图中  第3张图的高
            var h3_3=$("#h3_3").css("height");//获取第3部分文字的高
    
            if(980<=width<=1920){
                $(".son1_div_fix").css("height",one_img+h3_1);
                $(".son2_div_fix").css("height",two_img+h3_2);
                $(".son3_div_fix").css("height",three_img+h3_3);
    
                $(".son1_div").css("height",one_img+h3_1);
               $("#parent_div").css("height",one_img+h3_1);
            }
    
        })
    
        $(window).resize(function(){
            var width=$(window).width();
            var one_img=$("#img_fix1").css("height");//获取三图中  第一张图的高
            var h3_1=$("#h3_1").css("height");//获取三图中  第一部分文字的高
    
            var two_img=$("#img_fix2").css("height");//获取三图中  第2张图的高
            var h3_2=$("#h3_2").css("height");//获取第2部分文字的高
    
            var three_img=$("#img_fix3").css("height");//获取三图中  第3张图的高
            var h3_3=$("#h3_3").css("height");//获取第3部分文字的高
            if(980<=width<=1920){
                $(".son1_div_fix").css("height",one_img+h3_1);
                $(".son2_div_fix").css("height",two_img+h3_2);
                $(".son3_div_fix").css("height",three_img+h3_3);
    
                $(".son1_div").css("height",one_img+h3_1);
                $("#parent_div").css("height",one_img+h3_1);
    
            }
        })
    </script>
  • 相关阅读:
    Golang Failpoint 的设计与实现
    没涉及到最值求解;观点:矩阵乘法无法表达出结果。 现实生活中事件、现象的数学表达
    多元微分学 枚举破解15位路由器密码 存储空间限制 拆分减长,求最值 数据去重
    ARP Poisoning Attack and Mitigation Techniques ARP欺骗 中间人攻击 Man-In-The-Middle (MITM) attack 嗅探 防范 Can one MAC address have two different IP addresses within the network?
    The C10K problem
    HTTP Streaming Architecture HLS 直播点播 HTTP流架构
    现代IM系统中消息推送和存储架构的实现
    现代IM系统中的消息系统架构
    长连接锁服务优化实践 C10K问题 nodejs的内部构造 limits.conf文件修改 sysctl.conf文件修改
    doubleclick cookie、动态脚本、用户画像、用户行为分析和海量数据存取 推荐词 京东 电商 信息上传 黑洞 https://blackhole.m.jd.com/getinfo
  • 原文地址:https://www.cnblogs.com/heyiming/p/6439185.html
Copyright © 2011-2022 走看看