Javascript CSS显示内联块并用元素填充所有空间
我有一个带有显示的元素:内联块,这些元素比其他元素大,导致元素之间有一个空格,如图所示 下面是一个例子 注意:一定要扩展结果窗口宽度以查看完整问题 CSSJavascript CSS显示内联块并用元素填充所有空间,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我有一个带有显示的元素:内联块,这些元素比其他元素大,导致元素之间有一个空格,如图所示 下面是一个例子 注意:一定要扩展结果窗口宽度以查看完整问题 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,
.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}
$(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>');
});
});
JS
.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}
$(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>');
});
});
$(文档).ready(函数(e){
风险值月份=[
{月份:'一月',州:'},
{月:'2月',州:'},
{月份:'March',状态:'},
{月份:'April',状态:'},
{月份:'December',状态:'}];
美元(月)。每个功能(索引、元素){
element.state==“当前”?
activeMonth='activeMonth':activeMonth='';
$('.MonthHolder')。追加('\
“+元素.月份+”\
');
});
});
HTML
<section class="app_section app_section_calender hide center">
<header class="app_section_header">CALENDER
<section class="monthsHolder" align="center"></section>
</section>
压延机
如何制作较小的方框来填充剩余的空间?一种解决方案是将月份浮动到左边,然后必须将中心移动到月份固定器并给出宽度。像这样:
.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;
}
一种解决方案是让你的月数浮动,但你必须将中心移动到月数固定器上,并给出一个宽度。像这样:
.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;
}
在activeMonth类中添加一个float:left:
.activeMonth {
float: left;
height: 340px;
width: 340px;
}
jsiddle:将float:left添加到activeMonth类中:
.activeMonth {
float: left;
height: 340px;
width: 340px;
}
jsIDLE:内联块将无法填充可用空间。它将向下推任何无法适应可用宽度的元素。浮动元素将解决此问题
使用CSS float,一个元素可以向左或向右推,允许其他元素环绕它。内联块不会填充可用空间。它将向下推任何无法适应可用宽度的元素。浮动元素将解决此问题
使用CSS float,一个元素可以被推到左边或右边,允许其他元素环绕它。你可以使用一个表格,合并较大元素的单元格
bootstrap
可以帮助你很容易地做到这一点。也许可以尝试一下砌体插件。你可以使用一个表格,合并较大元素的单元格bootstrap
可以帮助你很容易地做到这一点。也许可以试试砌体插件。对于“.monthsHolder”,这是否适用于任何其他宽度超过560px的情况?我希望每行有四个区块。对于“.monthsHolder”,其他宽度超过560px的区块可以吗?我希望每排有四个街区,这是可行的。谢谢。好的,这是可行的。谢谢