javascript - CSS 显示内联 block 并用元素填充所有空间

标签 javascript jquery html css

我有一个带有 display:inline-block 的元素,这些元素比其他元素大,导致元素之间有空间,如图所示。

这是示例的 fiddle 。

http://jsfiddle.net/uu64hyed/

注意:一定要扩大结果窗口的宽度才能看到完整的问题。

CSS

.calenderMonth_header {
    height:35px;
    line-height:35px;
    text-align:center;
    background-color: rgba(221,221,221,1);
    border-bottom: 1px solid rgba(221,221,221,1);
}
.calenderMonth {
    height: 160px;
    width:160px;
    margin:10px;
    border-radius:2px;
    background-color: rgba(238,238,238,1);
    border: 1px solid rgba(221,221,221,1);
    display:inline-block;
    vertical-align:top;
    cursor:pointer;
}
.activeMonth { height:340px; width:340px;}
.calenderMonth:hover { border: rgba(0,153,204,1) 1px solid}

JS

$(document).ready(function(e) {
    var months = [ 
    {month:'January', state:''},
    {month:'Feburary', state:''},
    {month:'March', state:''},
    {month:'April', state:''},
    {month:'December', state:''}];
    $(months).each(function(index, element){
        element.state == 'current' ?
        activeMonth = 'activeMonth':activeMonth = '';
        $('.monthsHolder').append('<article class="calenderMonth '+activeMonth+'">\
        <header class="calenderMonth_header">'+element.month+'</header>\
        </article>');
    });
});

HTML

<section class="app_section app_section_calender hide center">
  <header class="app_section_header">CALENDER
  <section class="monthsHolder"  align="center"></section>
</section>

如何制作较小的盒子来填充剩余空间?

最佳答案

一种解决方案是将您的月份 float ,但随后您必须将居中移动到您的月份持有人并提供宽度。像这样:

.calenderMonth {
    height: 160px;
    width:160px;
    margin:10px;
    border-radius:2px;
    background-color: rgba(238,238,238,1);
    border: 1px solid rgba(221,221,221,1);
    display:inline-block;
    vertical-align:top;
    cursor:pointer;
    float: left;
}

.monthsHolder
{
    margin: 0 auto;
    width: 560px;
}

http://jsfiddle.net/7dyt1tLL/1/

关于javascript - CSS 显示内联 block 并用元素填充所有空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31118493/

相关文章:

javascript - Underscore.js - 从嵌套数组中删除项目?

jquery - 如何使用jQuery调整自定义对话框的位置?

javascript - 将数组值附加到所选元素的 ID 属性

javascript - 如何将图像数组上传到 firebase 存储?

javascript - 在 react 中读取excel文件

jquery - 如何在 Internet Explorer 8 中正确对齐横幅

javascript - 将父类添加到样式标签内的 css

html - 格式化菜单栏的问题

javascript - 将事件监听器添加到插入数组的 DOM 元素

javascript - promise 问题 : ReferenceError: reject is not defined