html - 如何创建像抽搐一样的 block ?

标签 html css

<分区>


关闭 8 年前

如何创建类似 this link 的 block ?

这是我目前尝试过的:

        window.onload = function(){

    var height = 0;
    var width = 0;
    var count_blocks = 0;
    width = window.innerWidth; 

    var h_right_block = document.getElementById('right_block').offsetHeight;
    var h_i_right_block = document.getElementById('i_right_block').offsetHeight;

    h_i_right_block += 20; 

    if(h_i_right_block > h_right_block){
        var w_Scroll = getScrollBarWidth();
        count_blocks = (width - 270 - w_Scroll) / 270;
    }else{
        count_blocks = (width - 270) / 270; 
    }
    count_blocks = Math.floor(count_blocks); 
    var diff_width_block = 250 / count_blocks;
    diff_width_block = Math.round(diff_width_block); 
    diff_width_block = 250 - diff_width_block;
    //diff_width_block = diff_width_block + "px";

    $( '.box' ).css( 'width', diff_width_block );
};

最佳答案

你可以试试这个:jsfiddle url : http://jsfiddle.net/Khumesh/qsbtfhx4/

CSS: 。部分 { 明确:两者; 填充:0px; 边距:0px;

    .col {
        display: block;
        float: left;
        margin-right: 2px;
        margin-bottom: 2px;
        border: 1px solid #000;
    }

        .col:first-child {
            margin-left: 0;
        }

    .group:before,
    .group:after {
        content: "";
        display: table;
    }

    .group:after {
        clear: both;
    }

    .group {
        zoom: 1; /* For IE 6/7 */
    }


    .span_3_of_3 {
        width: 100%;
    }

    .span_2_of_3 {
        width: 66.1%;
    }

    .span_1_of_3 {
        width: 32.2%;
    }

    @media only screen and (max-width: 480px) {
        .col {
            margin: 1% 0 1% 0%;
        }

        .span_3_of_3, .span_2_of_3, .span_1_of_3 {
            width: 100%;
        }
    }

HTML:

<div class="section group">
        <div class="col span_1_of_3">
            This is column 1
        </div>
        <div class="col span_1_of_3">
            This is column 2
        </div>
        <div class="col span_1_of_3">
            This is column 3
        </div>
        <div class="col span_1_of_3">
            This is column 4
        </div>
        <div class="col span_1_of_3">
            This is column 5
        </div>
        <div class="col span_1_of_3">
            This is column 6
        </div>
        <div class="col span_1_of_3">
            This is column 7
        </div>
        <div class="col span_1_of_3">
            This is column 8
        </div>
        <div class="col span_1_of_3">
            This is column 9
        </div>
    </div>

关于html - 如何创建像抽搐一样的 block ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29161363/

上一篇:CSS:如何在标签后设置复选框样式?

下一篇:JavaScript 和 Html 代码来运行所有类型的视频并获得状态

相关文章:

可选 24 或 12 小时的 jQuery 实时时钟

javascript - 从缓冲区播放声音

javascript - 有没有办法用我自己的 CSS 覆盖网站的 CSS?

css - 左/右页相关格式

html - 如何删除跨度并在点击时在跨度下播放 youtube 视频?

html - Rails 应用程序中表单的通用字体样式

javascript - 在浏览器 (F11) 中检测到全屏模式时使标题消失

html - 如何防止绝对定位的元素影响滚动条?

jquery - 纵向和横向倾斜时如何进行自动响应?

css - 为什么 overflow 属性会破坏 CSS3 3D 转换?